-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
cmd_run_grpc_test.go
129 lines (113 loc) · 3.28 KB
/
cmd_run_grpc_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
package tests
import (
"os"
"path/filepath"
"testing"
"go.k6.io/k6/cmd"
"go.k6.io/k6/lib/fsext"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
const projectRootPath = "../../"
// TestGRPCInputOutput runs same k6's scripts that we have in example folder
// it check that output contains/not contains cetane things
func TestGRPCInputOutput(t *testing.T) {
t.Parallel()
tc := map[string]struct {
script string
outputShouldContain []string
outputShouldNotContain []string
}{
"Server streaming": {
script: projectRootPath + "examples/grpc_server_streaming.js",
outputShouldContain: []string{
"output: -",
"default: 1 iterations for each of 1 VUs",
"1 complete and 0 interrupted iterations",
"Found feature called",
"grpc_streams",
"grpc_streams_msgs_received",
"grpc_streams_msgs_sent",
"All done",
},
outputShouldNotContain: []string{
"Stream Error:",
},
},
"Client Streaming": {
script: projectRootPath + "examples/grpc_client_streaming.js",
outputShouldContain: []string{
"output: -",
"default: 1 iterations for each of 1 VUs",
"1 complete and 0 interrupted iterations",
"Visiting point",
"Finished trip with 5 points",
"Passed 5 feature",
"grpc_streams",
"grpc_streams_msgs_received",
"grpc_streams_msgs_sent",
"All done",
},
outputShouldNotContain: []string{
"Stream Error:",
},
},
"Invoke": {
script: projectRootPath + "examples/grpc_invoke.js",
outputShouldContain: []string{
"output: -",
"default: 1 iterations for each of 1 VUs",
"1 complete and 0 interrupted iterations",
"3 Hasta Way, Newton, NJ 07860, USA",
},
outputShouldNotContain: []string{
"grpc_streams",
"grpc_streams_msgs_received",
"grpc_streams_msgs_sent",
},
},
"Reflection": {
script: projectRootPath + "examples/grpc_reflection.js",
outputShouldContain: []string{
"output: -",
"default: 1 iterations for each of 1 VUs",
"1 complete and 0 interrupted iterations",
"3 Hasta Way, Newton, NJ 07860, USA",
},
outputShouldNotContain: []string{
"grpc_streams",
"grpc_streams_msgs_received",
"grpc_streams_msgs_sent",
},
},
}
// Read the proto file from the testutils package
// it's same that we use in the examples
proto, err := os.ReadFile(projectRootPath + "lib/testutils/grpcservice/route_guide.proto") //nolint:forbidigo
require.NoError(t, err)
for name, test := range tc {
name := name
test := test
t.Run(name, func(t *testing.T) {
t.Parallel()
tb := NewGRPC(t)
script, err := os.ReadFile(test.script) //nolint:forbidigo
require.NoError(t, err)
ts := getSingleFileTestState(t, string(script), []string{"-v", "--log-output=stdout", "--no-usage-report"}, 0)
ts.Env = map[string]string{
"GRPC_ADDR": tb.Addr,
"GRPC_PROTO_PATH": "./proto.proto",
}
require.NoError(t, fsext.WriteFile(ts.FS, filepath.Join(ts.Cwd, "proto.proto"), proto, 0o644))
cmd.ExecuteWithGlobalState(ts.GlobalState)
stdout := ts.Stdout.String()
for _, s := range test.outputShouldContain {
assert.Contains(t, stdout, s)
}
for _, s := range test.outputShouldNotContain {
assert.NotContains(t, stdout, s)
}
assert.Empty(t, ts.Stderr.String())
})
}
}