Skip to content

Commit

Permalink
fix check unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Sumeet Rai committed Nov 14, 2024
1 parent 5878e3f commit f964f6f
Showing 1 changed file with 19 additions and 13 deletions.
32 changes: 19 additions & 13 deletions plugins/internal/tengoutil/secure_script_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package tengoutil

import (
"testing"
"time"

"github.com/MakeNowJust/heredoc"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -68,59 +69,64 @@ func TestNewSecureScript(t *testing.T) {
})

t.Run("HTTP GET with headers", func(t *testing.T) {
s, err := NewSecureScript([]byte(heredoc.Doc(`
s, err := NewSecureScript(([]byte)(heredoc.Doc(`
http := import("http")
headers := { "User-Agent": "test-agent", "Accept": "application/json" }
response := http.get("http://example.com", headers)
response.body
`)), nil)
assert.NoError(t, err)
_, err = s.Compile()

err = s.Compile()

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

View workflow job for this annotation

GitHub Actions / plugins-test (internal/tengoutil)

assignment mismatch: 1 variable but s.Compile returns 2 values
assert.NoError(t, err)
})

t.Run("HTTP GET with invalid URL argument type", func(t *testing.T) {
s, err := NewSecureScript([]byte(heredoc.Doc(`
s, err := NewSecureScript(([]byte)(heredoc.Doc(`
http := import("http")
http.get(12345)
http.get(12345)
`)), nil)
assert.NoError(t, err)
compiledScript, err := s.Compile()

err = s.Compile()

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

View workflow job for this annotation

GitHub Actions / plugins-test (internal/tengoutil)

assignment mismatch: 1 variable but s.Compile returns 2 values
assert.NoError(t, err)

_, err = compiledScript.Run()
err = s.Run()

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

View workflow job for this annotation

GitHub Actions / plugins-test (internal/tengoutil)

assignment mismatch: 1 variable but s.Run returns 2 values
assert.Error(t, err)
assert.Contains(t, err.Error(), "expected argument 1 (URL) to be a string")
})

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

err = s.Compile()

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

View workflow job for this annotation

GitHub Actions / plugins-test (internal/tengoutil)

assignment mismatch: 1 variable but s.Compile returns 2 values
assert.NoError(t, err)

_, err = compiledScript.Run()
err = s.Run()

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

View workflow job for this annotation

GitHub Actions / plugins-test (internal/tengoutil)

assignment mismatch: 1 variable but s.Run returns 2 values
assert.Error(t, err)
assert.Contains(t, err.Error(), "header value for key 'User-Agent' must be a string")
})

t.Run("HTTP GET with timeout", func(t *testing.T) {
s, err := NewSecureScript([]byte(heredoc.Doc(`
s, err := NewSecureScript(([]byte)(heredoc.Doc(`
http := import("http")
response := http.get("http://example.com")
response.body
`)), nil)
assert.NoError(t, err)

defaultTimeout = 1 * time.Millisecond
compiledScript, err := s.Compile()
defaultTimeout := 1 * time.Millisecond

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

View workflow job for this annotation

GitHub Actions / plugins-test (internal/tengoutil)

defaultTimeout declared and not used
defer func() { defaultTimeout = 5 * time.Second }()

err = s.Compile()

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

View workflow job for this annotation

GitHub Actions / plugins-test (internal/tengoutil)

assignment mismatch: 1 variable but s.Compile returns 2 values
assert.NoError(t, err)

_, err = compiledScript.Run()
err = s.Run()

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

View workflow job for this annotation

GitHub Actions / plugins-test (internal/tengoutil)

assignment mismatch: 1 variable but s.Run returns 2 values
assert.Error(t, err)
assert.Contains(t, err.Error(), "context deadline exceeded")
})
Expand Down

0 comments on commit f964f6f

Please sign in to comment.