-
Notifications
You must be signed in to change notification settings - Fork 0
test maps #18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
test maps #18
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,12 +6,36 @@ import ( | |
| "github.com/extism/go-pdk" | ||
| ) | ||
|
|
||
| //go:export reflectMapHost | ||
| func reflectMapHost(kPtr uint64) uint64 { | ||
| kMem := pdk.FindMemory(kPtr) | ||
| k := string(kMem.ReadBytes()) | ||
|
|
||
| var obj map[string]interface{} | ||
| err := pdk.JSONFrom(kPtr, &obj) | ||
| if err != nil { | ||
| pdk.SetError(err) | ||
| return 0 | ||
| } | ||
|
|
||
| fmt.Println(k) | ||
|
|
||
| kRet := pdk.AllocateString(k) | ||
| return kRet.Offset() | ||
| } | ||
|
|
||
| //go:export reflectJsonObjectHost | ||
| func reflectJsonObjectHost(kPtr uint64) uint64 { | ||
| kMem := pdk.FindMemory(kPtr) | ||
| k := string(kMem.ReadBytes()) | ||
|
|
||
| // TODO should validate that we get json by trying to parse it | ||
| var obj map[string]interface{} | ||
| err := pdk.JSONFrom(kPtr, &obj) | ||
| if err != nil { | ||
| pdk.SetError(err) | ||
| return 0 | ||
| } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comment as above re: adding the tests for type conversion / assertion now that the test module imports are linked. |
||
|
|
||
| fmt.Println(k) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. From an older commit, but does this Println need to be here? |
||
|
|
||
| kRet := pdk.AllocateString(k) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now that we link the test imports (e.g. assert, etc) into XTP Tests, I wonder if it would be worthwhile to run assertions on the kv pairs, doing a type assertion inside the mock here too?
e.g.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should work, assuming all the xtp CLI PRs are merged and the latest version is relased