-
Notifications
You must be signed in to change notification settings - Fork 67
/
apply_test_test.go
130 lines (101 loc) 路 4.72 KB
/
apply_test_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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
package test
import (
"fmt"
"os"
"testing"
"github.com/kubeshop/tracetest/cli-e2etest/environment"
"github.com/kubeshop/tracetest/cli-e2etest/helpers"
"github.com/kubeshop/tracetest/cli-e2etest/testscenarios/types"
"github.com/kubeshop/tracetest/cli-e2etest/tracetestcli"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestApplyTest(t *testing.T) {
t.Run("Basic", func(t *testing.T) {
// instantiate require with testing helper
require := require.New(t)
assert := assert.New(t)
// setup isolated e2e environment
env := environment.CreateAndStart(t)
defer env.Close(t)
cliConfig := env.GetCLIConfigPath(t)
// Given I am a Tracetest CLI user
// And I have my server recently created
// When I try to set up a new test
// Then it should be applied with success
testPath := env.GetTestResourcePath(t, "list")
result := tracetestcli.Exec(t, fmt.Sprintf("apply test --file %s", testPath), tracetestcli.WithCLIConfig(cliConfig))
helpers.RequireExitCodeEqual(t, result, 0)
// When I try to get a test
// Then it should return the test applied on the last step
result = tracetestcli.Exec(t, "get test --id fH_8AulVR", tracetestcli.WithCLIConfig(cliConfig))
helpers.RequireExitCodeEqual(t, result, 0)
listTest := helpers.UnmarshalYAML[types.TestResource](t, result.StdOut)
assert.Equal("Test", listTest.Type)
assert.Equal("fH_8AulVR", listTest.Spec.ID)
assert.Equal("Pokeshop - List", listTest.Spec.Name)
assert.Equal("List Pokemon", listTest.Spec.Description)
assert.Equal("http", listTest.Spec.Trigger.Type)
assert.Equal("http://demo-api:8081/pokemon?take=20&skip=0", listTest.Spec.Trigger.HTTPRequest.URL)
assert.Equal("GET", listTest.Spec.Trigger.HTTPRequest.Method)
assert.Equal("", listTest.Spec.Trigger.HTTPRequest.Body)
require.Len(listTest.Spec.Trigger.HTTPRequest.Headers, 1)
assert.Equal("Content-Type", listTest.Spec.Trigger.HTTPRequest.Headers[0].Key)
assert.Equal("application/json", listTest.Spec.Trigger.HTTPRequest.Headers[0].Value)
})
t.Run("EmbeddingProtobufFile", func(t *testing.T) {
// instantiate require with testing helper
require := require.New(t)
assert := assert.New(t)
proto, err := os.ReadFile("./resources/api.proto")
require.NoError(err)
// setup isolated e2e environment
env := environment.CreateAndStart(t)
defer env.Close(t)
cliConfig := env.GetCLIConfigPath(t)
// Given I am a Tracetest CLI user
// And I have my server recently created
// When I try to set up a new test
// Then it should be applied with success
testPath := env.GetTestResourcePath(t, "grpc-trigger-reference-protobuf")
result := tracetestcli.Exec(t, fmt.Sprintf("apply test --file %s", testPath), tracetestcli.WithCLIConfig(cliConfig))
helpers.RequireExitCodeEqual(t, result, 0)
// When I try to get a test
// Then it should return the test applied on the last step
result = tracetestcli.Exec(t, "get test --id create-pokemon", tracetestcli.WithCLIConfig(cliConfig))
helpers.RequireExitCodeEqual(t, result, 0)
listTest := helpers.UnmarshalYAML[types.TestResource](t, result.StdOut)
assert.Equal("Test", listTest.Type)
assert.Equal("create-pokemon", listTest.Spec.ID)
assert.Equal("grpc", listTest.Spec.Trigger.Type)
assert.Equal(string(proto), listTest.Spec.Trigger.GRPCRequest.ProtobufFile)
})
t.Run("GRPC With Embedded Protobuf starting on comment", func(t *testing.T) {
// comments on first line on a embedded protobuf can be confused with a relative path
// instantiate require with testing helper
require := require.New(t)
assert := assert.New(t)
proto, err := os.ReadFile("./resources/api-with-comment.proto")
require.NoError(err)
// setup isolated e2e environment
env := environment.CreateAndStart(t)
defer env.Close(t)
cliConfig := env.GetCLIConfigPath(t)
// Given I am a Tracetest CLI user
// And I have my server recently created
// When I try to set up a new test
// Then it should be applied with success
testPath := env.GetTestResourcePath(t, "grpc-trigger-embedded-protobuf-with-comment")
result := tracetestcli.Exec(t, fmt.Sprintf("apply test --file %s", testPath), tracetestcli.WithCLIConfig(cliConfig))
helpers.RequireExitCodeEqual(t, result, 0)
// When I try to get a test
// Then it should return the test applied on the last step
result = tracetestcli.Exec(t, "get test --id create-pokemon-embedded", tracetestcli.WithCLIConfig(cliConfig))
helpers.RequireExitCodeEqual(t, result, 0)
listTest := helpers.UnmarshalYAML[types.TestResource](t, result.StdOut)
assert.Equal("Test", listTest.Type)
assert.Equal("create-pokemon-embedded", listTest.Spec.ID)
assert.Equal("grpc", listTest.Spec.Trigger.Type)
assert.Equal(string(proto), listTest.Spec.Trigger.GRPCRequest.ProtobufFile)
})
}