Skip to content

Commit 8d912ff

Browse files
committed
test(apply): Add integration tests
1 parent 6f5a769 commit 8d912ff

File tree

11 files changed

+202
-1
lines changed

11 files changed

+202
-1
lines changed

tests/integration/apply_test.go

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
//go:build integration
2+
3+
package integration
4+
5+
import (
6+
"testing"
7+
8+
"github.com/stretchr/testify/assert"
9+
)
10+
11+
func Test_Apply_3x(t *testing.T) {
12+
// setup stage
13+
14+
tests := []struct {
15+
name string
16+
firstFile string
17+
secondFile string
18+
expectedState string
19+
}{
20+
{
21+
name: "applies multiple of the same entity",
22+
firstFile: "testdata/apply/001-same-type/service-01.yaml",
23+
secondFile: "testdata/apply/001-same-type/service-02.yaml",
24+
expectedState: "testdata/apply/001-same-type/expected-state.yaml",
25+
},
26+
{
27+
name: "applies different entity types",
28+
firstFile: "testdata/apply/002-different-types/service-01.yaml",
29+
secondFile: "testdata/apply/002-different-types/plugin-01.yaml",
30+
expectedState: "testdata/apply/002-different-types/expected-state.yaml",
31+
},
32+
{
33+
name: "accepts foreign keys",
34+
firstFile: "testdata/apply/003-foreign-keys-consumers/consumer-01.yaml",
35+
secondFile: "testdata/apply/003-foreign-keys-consumers/plugin-01.yaml",
36+
expectedState: "testdata/apply/003-foreign-keys-consumers/expected-state.yaml",
37+
},
38+
}
39+
for _, tc := range tests {
40+
t.Run(tc.name, func(t *testing.T) {
41+
runWhen(t, "kong", ">=3.0.0")
42+
setup(t)
43+
apply(tc.firstFile)
44+
apply(tc.secondFile)
45+
46+
out, _ := dump()
47+
48+
expected, err := readFile(tc.expectedState)
49+
if err != nil {
50+
t.Fatalf("failed to read expected state: %v", err)
51+
}
52+
53+
assert.Equal(t, expected, out)
54+
})
55+
}
56+
}

tests/integration/test_utils.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,16 @@ func setup(t *testing.T) {
266266
})
267267
}
268268

269+
func apply(kongFile string, opts ...string) error {
270+
deckCmd := cmd.NewRootCmd()
271+
args := []string{"gateway", "apply", kongFile}
272+
if len(opts) > 0 {
273+
args = append(args, opts...)
274+
}
275+
deckCmd.SetArgs(args)
276+
return deckCmd.ExecuteContext(context.Background())
277+
}
278+
269279
func sync(kongFile string, opts ...string) error {
270280
deckCmd := cmd.NewRootCmd()
271281
args := []string{"sync", "-s", kongFile}
@@ -300,7 +310,7 @@ func diff(kongFile string, opts ...string) (string, error) {
300310

301311
func dump(opts ...string) (string, error) {
302312
deckCmd := cmd.NewRootCmd()
303-
args := []string{"dump"}
313+
args := []string{"gateway", "dump"}
304314
if len(opts) > 0 {
305315
args = append(args, opts...)
306316
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
_format_version: "3.0"
2+
services:
3+
- connect_timeout: 60000
4+
enabled: true
5+
host: httpbin.org
6+
name: mock1
7+
path: /anything
8+
port: 80
9+
protocol: http
10+
read_timeout: 60000
11+
retries: 5
12+
write_timeout: 60000
13+
- connect_timeout: 60000
14+
enabled: true
15+
host: httpbin.org
16+
name: mock2
17+
path: /anything
18+
port: 80
19+
protocol: http
20+
read_timeout: 60000
21+
retries: 5
22+
write_timeout: 60000
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
_format_version: "3.0"
2+
services:
3+
- connect_timeout: 60000
4+
enabled: true
5+
host: httpbin.org
6+
name: mock1
7+
path: /anything
8+
port: 80
9+
protocol: http
10+
read_timeout: 60000
11+
retries: 5
12+
write_timeout: 60000
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
_format_version: "3.0"
2+
services:
3+
- connect_timeout: 60000
4+
enabled: true
5+
host: httpbin.org
6+
name: mock2
7+
path: /anything
8+
port: 80
9+
protocol: http
10+
read_timeout: 60000
11+
retries: 5
12+
write_timeout: 60000
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
_format_version: "3.0"
2+
plugins:
3+
- config:
4+
body: null
5+
content_type: null
6+
echo: false
7+
message: null
8+
status_code: 200
9+
trigger: null
10+
enabled: true
11+
name: request-termination
12+
protocols:
13+
- grpc
14+
- grpcs
15+
- http
16+
- https
17+
services:
18+
- connect_timeout: 60000
19+
enabled: true
20+
host: httpbin.org
21+
name: mock1
22+
path: /anything
23+
port: 80
24+
protocol: http
25+
read_timeout: 60000
26+
retries: 5
27+
write_timeout: 60000
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
_format_version: "3.0"
2+
plugins:
3+
- name: request-termination
4+
config:
5+
body: null
6+
content_type: null
7+
echo: false
8+
message: null
9+
status_code: 200
10+
trigger: null
11+
enabled: true
12+
protocols:
13+
- grpc
14+
- grpcs
15+
- http
16+
- https
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
_format_version: "3.0"
2+
services:
3+
- connect_timeout: 60000
4+
enabled: true
5+
host: httpbin.org
6+
name: mock1
7+
path: /anything
8+
port: 80
9+
protocol: http
10+
read_timeout: 60000
11+
retries: 5
12+
write_timeout: 60000
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
_format_version: "3.0"
2+
consumers:
3+
- username: alice
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
_format_version: "3.0"
2+
consumers:
3+
- plugins:
4+
- config:
5+
body: null
6+
content_type: null
7+
echo: false
8+
message: null
9+
status_code: 404
10+
trigger: null
11+
enabled: true
12+
name: request-termination
13+
protocols:
14+
- http
15+
- https
16+
username: alice

0 commit comments

Comments
 (0)