Skip to content

Commit

Permalink
unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
Sumeet Rai committed Nov 13, 2024
1 parent f3e78b7 commit d44a27c
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion plugins/internal/tengoutil/secure_script_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ func TestNewSecureScript(t *testing.T) {
base64 := import("base64")
hex := import("hex")
enum := import("enum")
http := import("http)
`)), nil)
assert.NoError(t, err)
_, err = s.Compile()
Expand Down Expand Up @@ -56,4 +55,34 @@ func TestNewSecureScript(t *testing.T) {
_, err = s.Compile()
assert.NoError(t, err)
})

t.Run("HTTP module test", func(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {

Check failure on line 60 in plugins/internal/tengoutil/secure_script_test.go

View workflow job for this annotation

GitHub Actions / plugins-test (internal/tengoutil)

undefined: httptest

Check failure on line 60 in plugins/internal/tengoutil/secure_script_test.go

View workflow job for this annotation

GitHub Actions / plugins-test (internal/tengoutil)

undefined: http
w.WriteHeader(http.StatusOK)

Check failure on line 61 in plugins/internal/tengoutil/secure_script_test.go

View workflow job for this annotation

GitHub Actions / plugins-test (internal/tengoutil)

undefined: http
w.Write([]byte(`{"message": "Hello, world!"}`))
}))
defer ts.Close()

script := heredoc.Docf(`
http := import("http")
json := import("json")
resp := http.get("%s")
data := json.decode(resp.body)
result := data.message
`, ts.URL)

s, err := NewSecureScript([]byte(script), nil)
assert.NoError(t, err)

compiledScript, err := s.Compile()
assert.NoError(t, err)

err = compiledScript.Run()
assert.NoError(t, err)

result, err := compiledScript.Get("result")

Check failure on line 83 in plugins/internal/tengoutil/secure_script_test.go

View workflow job for this annotation

GitHub Actions / plugins-test (internal/tengoutil)

assignment mismatch: 2 variables but compiledScript.Get returns 1 value
assert.NoError(t, err)

assert.Equal(t, "Hello, world!", result.String())
})
}

0 comments on commit d44a27c

Please sign in to comment.