Skip to content

Commit

Permalink
Additional apply command tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mheap committed Jan 27, 2025
1 parent 9aded15 commit 24f4ed9
Show file tree
Hide file tree
Showing 11 changed files with 177 additions and 0 deletions.
38 changes: 38 additions & 0 deletions tests/integration/apply_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,20 @@ func Test_Apply_3x(t *testing.T) {
expectedState: "testdata/apply/004-foreign-keys-consumer-groups/expected-state.yaml",
runWhen: "enterprise",
},
{
name: "accepts service foreign keys",
firstFile: "testdata/apply/005-foreign-keys-services/service-01.yaml",
secondFile: "testdata/apply/005-foreign-keys-services/plugin-01.yaml",
expectedState: "testdata/apply/005-foreign-keys-services/expected-state.yaml",
runWhen: "kong",
},
{
name: "accepts route foreign keys",
firstFile: "testdata/apply/006-foreign-keys-routes/route-01.yaml",
secondFile: "testdata/apply/006-foreign-keys-routes/plugin-01.yaml",
expectedState: "testdata/apply/006-foreign-keys-routes/expected-state.yaml",
runWhen: "kong",
},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
Expand All @@ -64,4 +78,28 @@ func Test_Apply_3x(t *testing.T) {
assert.Equal(t, expected, out)
})
}

t.Run("updates existing entities", func(t *testing.T) {
runWhen(t, "kong", ">=3.0.0")
setup(t)

apply("testdata/apply/007-update-existing-entity/service-01.yaml")

out, _ := dump()
expectedOriginal, err := readFile("testdata/apply/007-update-existing-entity/expected-state-01.yaml")
if err != nil {
t.Fatalf("failed to read expected state: %v", err)
}

assert.Equal(t, expectedOriginal, out)

apply("testdata/apply/007-update-existing-entity/service-02.yaml")
expectedChanged, err := readFile("testdata/apply/007-update-existing-entity/expected-state-02.yaml")
if err != nil {
t.Fatalf("failed to read expected state: %v", err)
}

outChanged, _ := dump()
assert.Equal(t, expectedChanged, outChanged)
})
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
_format_version: "3.0"
services:
- connect_timeout: 60000
enabled: true
host: httpbin.konghq.com
name: example-service
plugins:
- config:
body: null
content_type: null
echo: false
message: null
status_code: 404
trigger: null
enabled: true
name: request-termination
protocols:
- http
- https
port: 80
protocol: http
read_timeout: 60000
retries: 5
write_timeout: 60000
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
_format_version: "3.0"
plugins:
- name: request-termination
enabled: true
service: example-service
config:
status_code: 404
body: null
content_type: null
echo: false
message: null
trigger: null
protocols:
- http
- https
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
_format_version: "3.0"
services:
- name: example-service
url: http://httpbin.konghq.com
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
_format_version: "3.0"
routes:
- https_redirect_status_code: 426
name: example-route
path_handling: v0
paths:
- /mock
plugins:
- config:
body: null
content_type: null
echo: false
message: null
status_code: 404
trigger: null
enabled: true
name: request-termination
protocols:
- http
- https
preserve_host: false
protocols:
- http
- https
regex_priority: 0
request_buffering: true
response_buffering: true
strip_path: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
_format_version: "3.0"
plugins:
- name: request-termination
enabled: true
route: example-route
config:
status_code: 404
body: null
content_type: null
echo: false
message: null
trigger: null
protocols:
- http
- https
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
_format_version: "3.0"
routes:
- name: example-route
paths:
- "/mock"
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
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: /changed
port: 80
protocol: http
read_timeout: 60000
retries: 5
write_timeout: 60000
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
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: /changed
port: 80
protocol: http
read_timeout: 60000
retries: 5
write_timeout: 60000

0 comments on commit 24f4ed9

Please sign in to comment.