forked from projectdiscovery/gozero
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgozero_test.go
More file actions
58 lines (52 loc) · 1.27 KB
/
gozero_test.go
File metadata and controls
58 lines (52 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package gozero
import (
"context"
"strings"
"testing"
osutils "github.com/projectdiscovery/utils/os"
"github.com/stretchr/testify/require"
)
func TestEval(t *testing.T) {
opts := &Options{}
if osutils.IsWindows() {
opts.Engines = []string{"python3.exe"}
} else {
opts.Engines = []string{"python3"}
}
pyzero, err := New(opts)
require.Nil(t, err)
src, err := NewSourceWithString(`print(1)`, "", "")
require.Nil(t, err)
// empty input
input, err := NewSource()
require.Nil(t, err)
out, err := pyzero.Eval(context.Background(), src, input)
require.Nil(t, err)
output := out.Stdout.String()
require.Equal(t, "1", strings.TrimSpace(string(output)))
err = src.Cleanup()
require.Nil(t, err)
err = input.Cleanup()
require.Nil(t, err)
}
func TestErr(t *testing.T) {
opts := &Options{}
if osutils.IsWindows() {
opts.Engines = []string{"nonexistent.exe"}
} else {
opts.Engines = []string{"nonexistent"}
}
gozero, err := New(opts)
require.NotNil(t, err)
require.Nil(t, gozero)
require.ErrorIs(t, err, ErrNoValidEngine)
opts.Engines = []string{}
gozero, err = New(opts)
require.NotNil(t, err)
require.Nil(t, gozero)
require.ErrorIs(t, err, ErrNoEngines)
opts.Engines = []string{"python3"}
gozero, err = New(opts)
require.Nil(t, err)
require.NotNil(t, gozero)
}