Skip to content

Commit

Permalink
fixed test for header value type
Browse files Browse the repository at this point in the history
  • Loading branch information
Sumeet Rai committed Nov 14, 2024
1 parent f351ff9 commit 50f3c8e
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions plugins/internal/tengoutil/secure_script_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,20 +96,26 @@ func TestNewSecureScript(t *testing.T) {
assert.Contains(t, err.Error(), "unsupported protocol scheme")
})

t.Run("HTTP GET with invalid header value type", func(t *testing.T) {
s, err := NewSecureScript([]byte(`
t.Run("HTTP GET with valid header value type (int)", func(t *testing.T) {
s, err := NewSecureScript(([]byte)(heredoc.Doc(`
http := import("http")
headers := { "User-Agent": 12345 }
http.get("http://example.com", headers)
`), nil)
`)), nil)
assert.NoError(t, err)

_, err = s.Compile()
assert.NoError(t, err)

_, err = s.Run()
assert.Error(t, err)
assert.Contains(t, err.Error(), "header value for key 'User-Agent' must be a string, got int")
result, err := s.Run()
assert.NoError(t, err)

resultMap, ok := result.(*tengo.Map)

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

View workflow job for this annotation

GitHub Actions / plugins-test (internal/tengoutil)

invalid operation: result (variable of type *tengo.Compiled) is not an interface
assert.True(t, ok)

userAgent, ok := resultMap.Value["User-Agent"].(*tengo.String)
assert.True(t, ok)
assert.Equal(t, "12345", userAgent.Value)
})

t.Run("HTTP GET with timeout", func(t *testing.T) {
Expand Down

0 comments on commit 50f3c8e

Please sign in to comment.