From 0482ae09af84234e1b74944b256d990f9c487d84 Mon Sep 17 00:00:00 2001 From: Jimmy Moore Date: Thu, 21 Sep 2023 12:19:59 +0100 Subject: [PATCH] Ext test now tests rust/typescript functions. --- ext.sh | 48 ++++++++++++++++++++++++++++------------------ ext/runner/go.mod | 4 ++++ ext/runner/main.go | 29 ++++++++++++++++++++++++---- 3 files changed, 58 insertions(+), 23 deletions(-) diff --git a/ext.sh b/ext.sh index ed7e9eb..470672f 100755 --- a/ext.sh +++ b/ext.sh @@ -2,51 +2,61 @@ rm -rf ext/sig ext/ext ext/fn local-testfn-latest.scale +# First lets create a signature mkdir ext/sig - echo "Creating signature" ./cmd/cmd signature new -d ext/sig - cp ext/scale.signature ext/sig/scale.signature - echo "Generating signature" ./cmd/cmd signature generate -d ext/sig testsig:latest +# Now create the extension mkdir ext/ext - echo "Creating extension" ./cmd/cmd extension new -d ext/ext - cp ext/scale.extension ext/ext/scale.extension - echo "Generating extension" ./cmd/cmd extension generate testext:latest -d ext/ext -mkdir ext/fn - +# Create a function using the extension in GO +mkdir ext/fn-go echo "Creating function" -./cmd/cmd function new -d ext/fn -s local/testsig:latest -e local/testext:latest testfn:latest - -cat ext/fn_code.go > ext/fn/main.go +./cmd/cmd function new -d ext/fn-go -s local/testsig:latest -e local/testext:latest testfngo:latest +cat ext/fn_code.go > ext/fn-go/main.go +echo "Building function" +./cmd/cmd function build -d ext/fn-go +echo "Exporting function" +./cmd/cmd function export local/testfngo:latest ext/ +# Create a function using the extension in Rust +mkdir ext/fn-rs +echo "Creating function" +./cmd/cmd function new -d ext/fn-rs -s local/testsig:latest -e local/testext:latest -l rust testfnrs:latest +# cat ext/fn_code.rs > ext/fn-rs/main.rs echo "Building function" -./cmd/cmd function build -d ext/fn +./cmd/cmd function build -d ext/fn-rs +echo "Exporting function" +./cmd/cmd function export local/testfnrs:latest ext/ +# Create a function using the extension in Typescript +mkdir ext/fn-ts +echo "Creating function" +./cmd/cmd function new -d ext/fn-ts -s local/testsig:latest -e local/testext:latest -l rust testfnts:latest +# cat ext/fn_code.ts > ext/fn-ts/main.ts +echo "Building function" +./cmd/cmd function build -d ext/fn-ts echo "Exporting function" -./cmd/cmd function export local/testfn:latest ext/ +./cmd/cmd function export local/testfnts:latest ext/ +# Sort out runner echo "Updating runner go.mod..." - -sig=`cat ext/fn/go.mod | grep testsig_latest | sed -e "s/guest/host/"` -ext=`cat ext/fn/go.mod | grep testext_latest | sed -e "s/guest/host/"` - +sig=`cat ext/fn-go/go.mod | grep testsig_latest | sed -e "s/guest/host/"` +ext=`cat ext/fn-go/go.mod | grep testext_latest | sed -e "s/guest/host/"` echo "Signature is " ${sig} echo "Extension is " ${ext} - # Get rid of any old or previous replacements cat ext/runner/go.mod | grep -v testsig_latest | grep -v testext_latest > ext/runner/go.mod.new mv ext/runner/go.mod.new ext/runner/go.mod - # Now insert the correct locations echo "" >> ext/runner/go.mod echo ${sig} >> ext/runner/go.mod diff --git a/ext/runner/go.mod b/ext/runner/go.mod index 7f6a68b..cba1669 100644 --- a/ext/runner/go.mod +++ b/ext/runner/go.mod @@ -30,5 +30,9 @@ require ( + + + + replace signature => /home/jimmy/.config/scale/signatures/local_testsig_latest_e6ddebc792ee929e2654b4281baca1376e05bf5a96d4bdf63a05a2aab5f9e749_signature/golang/host replace HttpFetch => /home/jimmy/.config/scale/extensions/local_testext_latest_5c7d22390f9101d459292d76c11b5e9f66c327b1766aae34b9cc75f9f40e8206_extension/golang/host diff --git a/ext/runner/main.go b/ext/runner/main.go index 8df7745..363d7a4 100644 --- a/ext/runner/main.go +++ b/ext/runner/main.go @@ -48,11 +48,32 @@ func (hc *HttpConnector) Fetch(u *HttpFetch.ConnectionDetails) (HttpFetch.HttpRe func main() { fmt.Printf("Running scale function with ext...\n") - s, err := scalefunc.Read("../local-testfn-latest.scale") + sgo, err := scalefunc.Read("../local-testfngo-latest.scale") if err != nil { panic(err) } + testfn(sgo) + + srs, err := scalefunc.Read("../local-testfnrs-latest.scale") + if err != nil { + panic(err) + } + + testfn(srs) + + sts, err := scalefunc.Read("../local-testfnts-latest.scale") + if err != nil { + panic(err) + } + + testfn(sts) + +} + +func testfn(fn *scalefunc.Schema) { + fmt.Printf("Running scale function with ext... %s\n", fn.Language) + ext_impl := &FetchExtension{} ctx := context.Background() @@ -60,7 +81,7 @@ func main() { // runtime config := scale.NewConfig(sig.New). WithContext(ctx). - WithFunctions([]*scalefunc.Schema{s}). + WithFunctions([]*scalefunc.Schema{fn}). WithExtension(HttpFetch.New(ext_impl)) r, err := scale.New(config) @@ -81,13 +102,13 @@ func main() { panic(err) } - fmt.Printf("Data(1) from scaleFunction: %s\n", sigctx.Context.MyString) + fmt.Printf("Data(1)[%s] from scaleFunction: %s\n", fn.Language, sigctx.Context.MyString) err = i.Run(context.Background(), sigctx) if err != nil { panic(err) } - fmt.Printf("Data(2) from scaleFunction: %s\n", sigctx.Context.MyString) + fmt.Printf("Data(2)[%s] from scaleFunction: %s\n", fn.Language, sigctx.Context.MyString) }