-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcommand_test.go
65 lines (48 loc) · 1.43 KB
/
command_test.go
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
59
60
61
62
63
64
65
package k6exec_test
import (
"context"
"strings"
"testing"
"github.com/grafana/k6build/pkg/testutils"
"github.com/grafana/k6deps"
"github.com/grafana/k6exec"
"github.com/grafana/k6provider"
"github.com/stretchr/testify/require"
)
func TestCommand(t *testing.T) {
t.Parallel()
env, err := testutils.NewTestEnv(testutils.TestEnvConfig{
WorkDir: t.TempDir(),
CatalogURL: "testdata/minimal-catalog.json",
})
require.NoError(t, err)
t.Cleanup(env.Cleanup)
opts := &k6exec.Options{
Env: k6deps.Source{Ignore: true},
Manifest: k6deps.Source{Ignore: true},
BuildServiceURL: env.BuildServiceURL(),
}
cmd, cleanup, err := k6exec.Command(context.TODO(), []string{"version"}, opts)
defer func() { require.NoError(t, cleanup()) }()
require.NoError(t, err)
out, err := cmd.Output()
require.NoError(t, err)
require.True(t, strings.HasPrefix(string(out), "k6"))
}
func TestCommand_errors(t *testing.T) {
t.Parallel()
env, err := testutils.NewTestEnv(testutils.TestEnvConfig{
WorkDir: t.TempDir(),
CatalogURL: "testdata/empty-catalog.json",
})
require.NoError(t, err)
t.Cleanup(env.Cleanup)
opts := &k6exec.Options{
Env: k6deps.Source{Ignore: true},
Manifest: k6deps.Source{Ignore: true},
BuildServiceURL: env.BuildServiceURL(),
}
_, _, err = k6exec.Command(context.TODO(), nil, opts)
require.Error(t, err)
require.ErrorIs(t, err, k6provider.ErrInvalidParameters)
}