-
Notifications
You must be signed in to change notification settings - Fork 128
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
220 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
//go:build integration | ||
|
||
package integration | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/kong/go-kong/kong" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
var ( | ||
svc1_a = []*kong.Service{ | ||
{ | ||
ID: kong.String("58076db2-28b6-423b-ba39-a797193017f7"), | ||
Name: kong.String("svc1"), | ||
ConnectTimeout: kong.Int(60000), | ||
Host: kong.String("mockbin.org"), | ||
Port: kong.Int(80), | ||
Protocol: kong.String("http"), | ||
ReadTimeout: kong.Int(60000), | ||
Retries: kong.Int(5), | ||
WriteTimeout: kong.Int(60000), | ||
Tags: nil, | ||
}, | ||
} | ||
) | ||
|
||
func Test_Apply_3x(t *testing.T) { | ||
// setup stage | ||
|
||
tests := []struct { | ||
name string | ||
firstFile string | ||
secondFile string | ||
expectedState string | ||
}{ | ||
{ | ||
name: "applies multiple of the same entity", | ||
firstFile: "testdata/apply/001-same-type/service-01.yaml", | ||
secondFile: "testdata/apply/001-same-type/service-02.yaml", | ||
expectedState: "testdata/apply/001-same-type/expected-state.yaml", | ||
}, | ||
{ | ||
name: "applies different entity types", | ||
firstFile: "testdata/apply/002-different-types/service-01.yaml", | ||
secondFile: "testdata/apply/002-different-types/plugin-01.yaml", | ||
expectedState: "testdata/apply/002-different-types/expected-state.yaml", | ||
}, | ||
{ | ||
name: "accepts foreign keys", | ||
firstFile: "testdata/apply/003-foreign-keys-consumers/consumer-01.yaml", | ||
secondFile: "testdata/apply/003-foreign-keys-consumers/plugin-01.yaml", | ||
expectedState: "testdata/apply/003-foreign-keys-consumers/expected-state.yaml", | ||
}, | ||
} | ||
for _, tc := range tests { | ||
t.Run(tc.name, func(t *testing.T) { | ||
runWhen(t, "kong", ">=3.0.0") | ||
setup(t) | ||
apply(tc.firstFile) | ||
apply(tc.secondFile) | ||
|
||
out, _ := dump() | ||
|
||
expected, err := readFile(tc.expectedState) | ||
if err != nil { | ||
t.Fatalf("failed to read expected state: %v", err) | ||
} | ||
|
||
assert.Equal(t, expected, out) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
tests/integration/testdata/apply/001-same-type/expected-state.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
_format_version: "3.0" | ||
services: | ||
- connect_timeout: 60000 | ||
enabled: true | ||
host: httpbin.org | ||
name: mock1 | ||
path: /anything | ||
port: 80 | ||
protocol: http | ||
read_timeout: 60000 | ||
retries: 5 | ||
write_timeout: 60000 | ||
- connect_timeout: 60000 | ||
enabled: true | ||
host: httpbin.org | ||
name: mock2 | ||
path: /anything | ||
port: 80 | ||
protocol: http | ||
read_timeout: 60000 | ||
retries: 5 | ||
write_timeout: 60000 |
12 changes: 12 additions & 0 deletions
12
tests/integration/testdata/apply/001-same-type/service-01.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
_format_version: "3.0" | ||
services: | ||
- connect_timeout: 60000 | ||
enabled: true | ||
host: httpbin.org | ||
name: mock1 | ||
path: /anything | ||
port: 80 | ||
protocol: http | ||
read_timeout: 60000 | ||
retries: 5 | ||
write_timeout: 60000 |
12 changes: 12 additions & 0 deletions
12
tests/integration/testdata/apply/001-same-type/service-02.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
_format_version: "3.0" | ||
services: | ||
- connect_timeout: 60000 | ||
enabled: true | ||
host: httpbin.org | ||
name: mock2 | ||
path: /anything | ||
port: 80 | ||
protocol: http | ||
read_timeout: 60000 | ||
retries: 5 | ||
write_timeout: 60000 |
27 changes: 27 additions & 0 deletions
27
tests/integration/testdata/apply/002-different-types/expected-state.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
_format_version: "3.0" | ||
plugins: | ||
- config: | ||
body: null | ||
content_type: null | ||
echo: false | ||
message: null | ||
status_code: 200 | ||
trigger: null | ||
enabled: true | ||
name: request-termination | ||
protocols: | ||
- grpc | ||
- grpcs | ||
- http | ||
- https | ||
services: | ||
- connect_timeout: 60000 | ||
enabled: true | ||
host: httpbin.org | ||
name: mock1 | ||
path: /anything | ||
port: 80 | ||
protocol: http | ||
read_timeout: 60000 | ||
retries: 5 | ||
write_timeout: 60000 |
16 changes: 16 additions & 0 deletions
16
tests/integration/testdata/apply/002-different-types/plugin-01.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
_format_version: "3.0" | ||
plugins: | ||
- name: request-termination | ||
config: | ||
body: null | ||
content_type: null | ||
echo: false | ||
message: null | ||
status_code: 200 | ||
trigger: null | ||
enabled: true | ||
protocols: | ||
- grpc | ||
- grpcs | ||
- http | ||
- https |
12 changes: 12 additions & 0 deletions
12
tests/integration/testdata/apply/002-different-types/service-01.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
_format_version: "3.0" | ||
services: | ||
- connect_timeout: 60000 | ||
enabled: true | ||
host: httpbin.org | ||
name: mock1 | ||
path: /anything | ||
port: 80 | ||
protocol: http | ||
read_timeout: 60000 | ||
retries: 5 | ||
write_timeout: 60000 |
3 changes: 3 additions & 0 deletions
3
tests/integration/testdata/apply/003-foreign-keys-consumers/consumer-01.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
_format_version: "3.0" | ||
consumers: | ||
- username: alice |
16 changes: 16 additions & 0 deletions
16
tests/integration/testdata/apply/003-foreign-keys-consumers/expected-state.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
_format_version: "3.0" | ||
consumers: | ||
- plugins: | ||
- config: | ||
body: null | ||
content_type: null | ||
echo: false | ||
message: null | ||
status_code: 404 | ||
trigger: null | ||
enabled: true | ||
name: request-termination | ||
protocols: | ||
- http | ||
- https | ||
username: alice |
15 changes: 15 additions & 0 deletions
15
tests/integration/testdata/apply/003-foreign-keys-consumers/plugin-01.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
_format_version: "3.0" | ||
plugins: | ||
- name: request-termination | ||
enabled: true | ||
consumer: alice | ||
config: | ||
status_code: 404 | ||
body: null | ||
content_type: null | ||
echo: false | ||
message: null | ||
trigger: null | ||
protocols: | ||
- http | ||
- https |