Skip to content
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

GoLang Test Cases #69

Merged
merged 30 commits into from
Sep 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
acb02e1
chore: init (thank you ChatGPT)
dOrgJelli Jul 6, 2023
a4ff235
wip: go harness
Niraj-Kamdar Jul 10, 2023
e8edc82
Update module.go
dOrgJelli Jul 11, 2023
0ad61c1
Merge remote-tracking branch 'origin/golang-cases' into golang-cases
Niraj-Kamdar Jul 11, 2023
3fe32fa
fix: issues
Niraj-Kamdar Jul 11, 2023
514697c
wip: test harness wraps
Niraj-Kamdar Jul 12, 2023
06af361
fix: asyncify issues
Niraj-Kamdar Jul 12, 2023
8560023
feat: add subinvoke go wraps
Niraj-Kamdar Jul 12, 2023
654f4f5
chore: go asyncify passing
dOrgJelli Jul 12, 2023
87a04f7
fix: json-type go implmentation
dOrgJelli Jul 13, 2023
4ddd97e
chore: fix object-type go impl
dOrgJelli Jul 13, 2023
05c7d8d
chore: subinvoke functional
dOrgJelli Jul 13, 2023
7d3e02c
chore: update to latest bindings
dOrgJelli Jul 13, 2023
d30a50b
chore: minor updates
dOrgJelli Jul 13, 2023
2a596b2
chore(cases): update with latest rust wrap bindings
cbrzn Jul 17, 2023
96859a2
fix: todo wraps are building
Niraj-Kamdar Jul 17, 2023
d12d793
chore(ci): set rust to stable version
cbrzn Jul 18, 2023
a503f16
chore: fix bigint rs
cbrzn Jul 18, 2023
71d060b
chore(ci): add clippy without nightly
cbrzn Jul 18, 2023
3f65084
Merge branch 'master' into golang-cases
dOrgJelli Jul 26, 2023
53b5b7a
chore: update versions
dOrgJelli Jul 30, 2023
c8c363b
Merge branch 'golang-cases' into chore/latest-rust-wrap-bindings
dOrgJelli Jul 30, 2023
4d79bb3
Merge pull request #70 from polywrap/chore/latest-rust-wrap-bindings
dOrgJelli Jul 30, 2023
9e14f46
merge master
dOrgJelli Aug 17, 2023
119f94f
chore: update asyncify
dOrgJelli Aug 17, 2023
1110ac7
chore: fix subinvoke feature
dOrgJelli Aug 17, 2023
176bd0e
chore: fix env-type
dOrgJelli Aug 17, 2023
16e4b31
chore: fix subinvoke test cases
dOrgJelli Aug 17, 2023
49c11fd
Merge branch 'master' into golang-cases
dOrgJelli Sep 6, 2023
44afd28
chore: fix subinvoke case
dOrgJelli Sep 7, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,7 @@ wrap
/target
results.json
/wrappers
yarn.lock
yarn.lock
.env
venv/
pyexpr/
2 changes: 1 addition & 1 deletion cases/asyncify/client-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export function configure(builder: ClientConfigBuilder): ClientConfigBuilder {
}

class MemoryStoragePlugin extends PluginModule<Record<string, unknown>> {
private _value: number;
private _value: number = 0;

async getData(_: {}): Promise<number> {
await this.sleep(50);
Expand Down
80 changes: 80 additions & 0 deletions cases/asyncify/implementations/go/module.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package module

import (
"github.com/polywrap/wrap-test-harness/go/module/wrap/types"
storage "github.com/polywrap/wrap-test-harness/go/module/wrap/imported/storage"
"strconv"
)

func GetData() uint32 {
v, err := storage.Storage_GetData(&storage.Storage_ArgsGetData{})
if err != nil {
panic(err.Error())
}
return uint32(v)
}

func SetDataWithLargeArgs(args *types.ArgsSetDataWithLargeArgs) string {
largeString := args.Value
_, err := storage.Storage_SetData(&storage.Storage_ArgsSetData{Value: 66})
if err != nil {
panic(err.Error())
}
return largeString
}

func SetDataWithManyArgs(args *types.ArgsSetDataWithManyArgs) string {
_, err := storage.Storage_SetData(&storage.Storage_ArgsSetData{Value: 55})
if err != nil {
panic(err.Error())
}
return args.ValueA + args.ValueB + args.ValueC + args.ValueD + args.ValueE + args.ValueF + args.ValueG + args.ValueH + args.ValueI + args.ValueJ + args.ValueK + args.ValueL
}

func SetDataWithManyStructuredArgs(args *types.ArgsSetDataWithManyStructuredArgs) bool {
_, err := storage.Storage_SetData(&storage.Storage_ArgsSetData{Value: 44})
if err != nil {
panic(err.Error())
}
return true
}

func LocalVarMethod() bool {
_, err := storage.Storage_SetData(&storage.Storage_ArgsSetData{Value: 88})
if err != nil {
panic(err.Error())
}
return true
}

func GlobalVarMethod() bool {
_, err := storage.Storage_SetData(&storage.Storage_ArgsSetData{Value: 77})
if err != nil {
panic(err.Error())
}
return true
}

func SubsequentInvokes(args *types.ArgsSubsequentInvokes) []string {
var result []string
var err error

for i := 0; i < int(args.NumberOfTimes); i++ {
_, errSet := storage.Storage_SetData(&storage.Storage_ArgsSetData{Value: int32(i)})
if errSet != nil {
err = errSet
break
}
data, errGet := storage.Storage_GetData(&storage.Storage_ArgsGetData{})
if errGet != nil {
err = errGet
break
}
str := strconv.Itoa(int(data))
result = append(result, str)
}
if err != nil {
panic(err.Error())
}
return result
}
19 changes: 19 additions & 0 deletions cases/bigint-type/implementations/go/module.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package module

import (
"github.com/polywrap/wrap-test-harness/go/module/wrap/types"
big "github.com/polywrap/go-wrap/msgpack/big"
)

func Method(args *types.ArgsMethod) (*big.Int) {
result := new(big.Int).Mul(args.Arg1, args.Obj.Prop1)

if args.Arg2 != nil {
result.Mul(result, args.Arg2)
}
if args.Obj.Prop2 != nil {
result.Mul(result, args.Obj.Prop2)
}

return result
}
19 changes: 19 additions & 0 deletions cases/bignumber-type/implementations/go/module.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package module

import (
"github.com/polywrap/wrap-test-harness/go/module/wrap/types"
big "github.com/polywrap/go-wrap/msgpack/big"
)

func Method(args *types.ArgsMethod) (*big.Int) {
result := big.NewInt(0).Mul(args.Arg1, args.Obj.Prop1)

if args.Arg2 != nil {
result.Mul(result, args.Arg2)
}
if args.Obj.Prop2 != nil {
result.Mul(result, args.Obj.Prop2)
}

return result
}
11 changes: 11 additions & 0 deletions cases/bytes-type/implementations/go/module.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package module

import (
"github.com/polywrap/wrap-test-harness/go/module/wrap/types"
)

func BytesMethod(args *types.ArgsBytesMethod) ([]byte) {
s := string(args.Arg.Prop)
result := []byte(s + " Sanity!")
return result
}
11 changes: 11 additions & 0 deletions cases/enum-type/implementations/go/module.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package module

import "github.com/polywrap/wrap-test-harness/go/module/wrap/types"

func Method1(args *types.ArgsMethod1) types.SanityEnum {
return args.En
}

func Method2(args *types.ArgsMethod2) []types.SanityEnum {
return args.EnumArray
}
17 changes: 17 additions & 0 deletions cases/env-type/00-main/implementations/go/module.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package module

import (
"github.com/polywrap/wrap-test-harness/go/module/wrap/types"
)

func MethodNoEnv(args *types.ArgsMethodNoEnv) string {
return args.Arg
}

func MethodRequireEnv(env *types.Env) types.Env {
return *env
}

func MethodOptionalEnv(env *types.Env) *types.Env {
return env
}
30 changes: 30 additions & 0 deletions cases/env-type/01-subinvoker/implementations/go/module.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package module

import (
. "github.com/polywrap/wrap-test-harness/go/module/wrap/imported/subinvoked"
"github.com/polywrap/wrap-test-harness/go/module/wrap/types"
)

func SubinvokeMethodNoEnv(args *types.ArgsSubinvokeMethodNoEnv) string {
value, err := Subinvoked_MethodNoEnv(&Subinvoked_ArgsMethodNoEnv{Arg: args.Arg})
if err != nil {
panic(err.Error())
}
return value
}

func SubinvokeMethodRequireEnv() Subinvoked_Env {
value, err := Subinvoked_MethodRequireEnv(&Subinvoked_ArgsMethodRequireEnv{})
if err != nil {
panic(err.Error())
}
return value
}

func SubinvokeMethodOptionalEnv() *Subinvoked_Env {
value, err := Subinvoked_MethodOptionalEnv(&Subinvoked_ArgsMethodOptionalEnv{})
if err != nil {
panic(err.Error())
}
return value
}
11 changes: 11 additions & 0 deletions cases/env-type/02-subinvoker-with-env/implementations/go/module.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package module

import (
. "github.com/polywrap/wrap-test-harness/go/module/wrap/imported/subinvoked"
"github.com/polywrap/wrap-test-harness/go/module/wrap/types"
)

func SubinvokeMethodRequireEnv(_ *types.Env) Subinvoked_Env {
res, _ := Subinvoked_MethodRequireEnv(&Subinvoked_ArgsMethodRequireEnv{})
return res
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package module

import (
"github.com/polywrap/wrap-test-harness/go/module/wrap/types"
)

func ModuleMethod(args *types.ArgsModuleMethod) types.ImplementationType {
return args.Arg
}

func AbstractModuleMethod(args *types.ArgsAbstractModuleMethod) string {
return args.Arg.Str
}
24 changes: 24 additions & 0 deletions cases/interface-invoke/02-wrapper/implementations/go/module.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package module

import (
. "github.com/polywrap/wrap-test-harness/go/module/wrap/interfaces"
. "github.com/polywrap/wrap-test-harness/go/module/wrap/imported/pkginterface"
"github.com/polywrap/wrap-test-harness/go/module/wrap/types"
)

func ModuleMethod(args *types.ArgsModuleMethod) types.ImplementationType {
return args.Arg
}

func AbstractModuleMethod(args *types.ArgsAbstractModuleMethod) string {
impls := Interface_GetImplementations()
uri := impls[1]
methodArgs := &Interface_ArgsAbstractModuleMethod{
Arg: args.Arg,
}
result, err := Interface_AbstractModuleMethod(uri, methodArgs)
if err != nil {
panic(err.Error())
}
return result
}
23 changes: 23 additions & 0 deletions cases/invalid-type/implementations/go/module.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package module

import "github.com/polywrap/wrap-test-harness/go/module/wrap/types"

func BoolMethod(args *types.ArgsBoolMethod) (bool) {
return args.Arg
}

func IntMethod(args *types.ArgsIntMethod) (int32) {
return args.Arg
}

func UIntMethod(args *types.ArgsUIntMethod) (uint32) {
return args.Arg
}

func BytesMethod(args *types.ArgsBytesMethod) ([]uint8) {
return args.Arg
}

func ArrayMethod(args *types.ArgsArrayMethod) ([]string) {
return args.Arg
}
60 changes: 60 additions & 0 deletions cases/json-type/implementations/go/module.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package module

import (
"encoding/json"
"github.com/valyala/fastjson"
"github.com/polywrap/wrap-test-harness/go/module/wrap/types"
)

func Stringify(args *types.ArgsStringify) (string) {
var newString string
for _, object := range args.Values {
newString += object.String()
}
return newString
}

func Parse(args *types.ArgsParse) *fastjson.Value {
p := fastjson.Parser{}
value, err := p.Parse(args.Value)
if err != nil {
panic(err)
}
return value
}

func StringifyObject(args *types.ArgsStringifyObject) (string) {
var newString string
newString += args.Object.JsonA.String()
newString += args.Object.JsonB.String()
return newString
}

func MethodJSON(args *types.ArgsMethodJSON) *fastjson.Value {
jsonValue, jsonErr := json.Marshal(args)
if jsonErr != nil {
panic(jsonErr)
}
value, err := fastjson.ParseBytes(jsonValue)
if err != nil {
panic(err)
}
return value
}

func ParseReserved(args *types.ArgsParseReserved) types.Reserved {
var reserved types.Reserved
err := json.Unmarshal([]byte(args.Json), &reserved)
if err != nil {
panic(err)
}
return reserved
}

func StringifyReserved(args *types.ArgsStringifyReserved) (string) {
jsonString, err := json.Marshal(args.Reserved)
if err != nil {
panic(err)
}
return string(jsonString)
}
26 changes: 26 additions & 0 deletions cases/map-type/implementations/go/module.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package module

import (
"github.com/polywrap/wrap-test-harness/go/module/wrap/types"
)

func GetKey(args *types.ArgsGetKey) int32 {
value, exists := args.Foo.M_map[args.Key]
if !exists {
// Return a default value or handle the case when the key is not found
return 0
}
return value
}

func ReturnMap(args *types.ArgsReturnMap) map[string]int32 {
return args.M_map
}

func ReturnCustomMap(args *types.ArgsReturnCustomMap) types.CustomMap {
return args.Foo
}

func ReturnNestedMap(args *types.ArgsReturnNestedMap) map[string]map[string]int32 {
return args.Foo
}
5 changes: 5 additions & 0 deletions cases/no-args/implementations/go/module.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package module

func NoArgsMethod() bool {
return true
}
Loading
Loading