Skip to content

Commit

Permalink
Ext test now tests rust/typescript functions.
Browse files Browse the repository at this point in the history
  • Loading branch information
jimmyaxod committed Sep 21, 2023
1 parent 95503e7 commit 0482ae0
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 23 deletions.
48 changes: 29 additions & 19 deletions ext.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions ext/runner/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
29 changes: 25 additions & 4 deletions ext/runner/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,40 @@ 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()

// 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)
Expand All @@ -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)

}

0 comments on commit 0482ae0

Please sign in to comment.