Skip to content

Commit

Permalink
test(apply): Add integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mheap committed Jan 7, 2025
1 parent 6f5a769 commit 8d912ff
Show file tree
Hide file tree
Showing 11 changed files with 202 additions and 1 deletion.
56 changes: 56 additions & 0 deletions tests/integration/apply_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
//go:build integration

package integration

import (
"testing"

"github.com/stretchr/testify/assert"
)

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)
})
}
}
12 changes: 11 additions & 1 deletion tests/integration/test_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,16 @@ func setup(t *testing.T) {
})
}

func apply(kongFile string, opts ...string) error {
deckCmd := cmd.NewRootCmd()
args := []string{"gateway", "apply", kongFile}
if len(opts) > 0 {
args = append(args, opts...)
}
deckCmd.SetArgs(args)
return deckCmd.ExecuteContext(context.Background())
}

func sync(kongFile string, opts ...string) error {
deckCmd := cmd.NewRootCmd()
args := []string{"sync", "-s", kongFile}
Expand Down Expand Up @@ -300,7 +310,7 @@ func diff(kongFile string, opts ...string) (string, error) {

func dump(opts ...string) (string, error) {
deckCmd := cmd.NewRootCmd()
args := []string{"dump"}
args := []string{"gateway", "dump"}
if len(opts) > 0 {
args = append(args, opts...)
}
Expand Down
22 changes: 22 additions & 0 deletions tests/integration/testdata/apply/001-same-type/expected-state.yaml
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 tests/integration/testdata/apply/001-same-type/service-01.yaml
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 tests/integration/testdata/apply/001-same-type/service-02.yaml
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
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
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
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,3 @@
_format_version: "3.0"
consumers:
- username: alice
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
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

0 comments on commit 8d912ff

Please sign in to comment.