Skip to content

Commit 0c1c671

Browse files
tests: add integration tests to avoid false diffs in plugin protocols (#1585)
* tests: add integration tests to verify empty diff when protocols are reordered in plugins * chore: bump go-database-reconciler to v1.22.2
1 parent 82754ea commit 0c1c671

File tree

6 files changed

+96
-3
lines changed

6 files changed

+96
-3
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ require (
1313
github.com/fatih/color v1.18.0
1414
github.com/google/go-cmp v0.7.0
1515
github.com/kong/go-apiops v0.1.41
16-
github.com/kong/go-database-reconciler v1.22.1
16+
github.com/kong/go-database-reconciler v1.22.2
1717
github.com/kong/go-kong v0.65.0
1818
github.com/mitchellh/go-homedir v1.1.0
1919
github.com/spf13/cobra v1.8.1

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,8 +246,8 @@ github.com/klauspost/cpuid/v2 v2.2.5 h1:0E5MSMDEoAulmXNFquVs//DdoomxaoTY1kUhbc/q
246246
github.com/klauspost/cpuid/v2 v2.2.5/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws=
247247
github.com/kong/go-apiops v0.1.41 h1:1KXbQqyhO2E4nEnXJNqUDmHZU/LQ1U7Zoi+MAlcM2P0=
248248
github.com/kong/go-apiops v0.1.41/go.mod h1:sATq9Tz+ivzHKZU+tDXkRtEZnf64xroU3lgv3yXqP4I=
249-
github.com/kong/go-database-reconciler v1.22.1 h1:m3H8j9pGsR4+CSTTvBuTcSYWGL8i62tOimjzxqjQUqc=
250-
github.com/kong/go-database-reconciler v1.22.1/go.mod h1:Jlo4eEe0/PHd2dIkWTH9tFfShydRwRxY09dZvKZBelU=
249+
github.com/kong/go-database-reconciler v1.22.2 h1:YNSDkwgdLGcjHbdbNP9JW/CjhPn0NDMrnWOvG4QDmLc=
250+
github.com/kong/go-database-reconciler v1.22.2/go.mod h1:Jlo4eEe0/PHd2dIkWTH9tFfShydRwRxY09dZvKZBelU=
251251
github.com/kong/go-kong v0.65.0 h1:dZT+hiMhy7CQsrc9W5nHv3cFJGBGTrwlZhC5MLuf9H8=
252252
github.com/kong/go-kong v0.65.0/go.mod h1:sqdysTKrXIJ6mpxHwTwjgZhLW7jR1/puczTXHLUwJaE=
253253
github.com/kong/go-slugify v1.0.0 h1:vCFAyf2sdoSlBtLcrmDWUFn0ohlpKiKvQfXZkO5vSKY=

tests/integration/diff_test.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -787,6 +787,42 @@ func Test_Diff_NoDiffUnorderedArray(t *testing.T) {
787787
}
788788
}
789789

790+
func Test_Diff_Plugin_Protocol_Order_Change(t *testing.T) {
791+
setup(t)
792+
ctx := context.Background()
793+
794+
tests := []struct {
795+
name string
796+
initialStateFile string
797+
stateFile string
798+
expectedDiff string
799+
}{
800+
{
801+
name: "syncing and then diffing same file should not show false diff",
802+
initialStateFile: "testdata/diff/004-no-diff-plugin/initial-ip-restriction.yaml",
803+
stateFile: "testdata/diff/004-no-diff-plugin/initial-ip-restriction.yaml",
804+
expectedDiff: emptyOutput,
805+
},
806+
{
807+
name: "changing protocol order should not show diff",
808+
initialStateFile: "testdata/diff/004-no-diff-plugin/protocol-initial-order-plugins.yaml",
809+
stateFile: "testdata/diff/004-no-diff-plugin/protocol-reordered-plugins.yaml",
810+
expectedDiff: emptyOutput,
811+
},
812+
}
813+
814+
for _, tc := range tests {
815+
t.Run(tc.name, func(t *testing.T) {
816+
// initialize state
817+
require.NoError(t, sync(ctx, tc.initialStateFile))
818+
819+
out, err := diff(tc.stateFile)
820+
require.NoError(t, err)
821+
assert.Equal(t, tc.expectedDiff, out)
822+
})
823+
}
824+
}
825+
790826
// test scope:
791827
// - 3.5
792828
func Test_Diff_NoDiffCompressedTarget(t *testing.T) {
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
_format_version: "3.0"
2+
services:
3+
- host: a0955.spucs.apip_self-service_api_-_external.v1.stream
4+
name: a0955.spucs.apip_self-service_api_-_external.v1
5+
port: 443
6+
protocol: https
7+
plugins:
8+
- config:
9+
allow:
10+
- 54.93.116.152/32
11+
name: ip-restriction
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
_format_version: "3.0"
2+
services:
3+
- host: a0955.spucs.apip_self-service_api_-_external.v1.stream
4+
name: a0955.spucs.apip_self-service_api_-_external.v1
5+
port: 443
6+
protocol: https
7+
plugins:
8+
- config:
9+
allow:
10+
- 54.93.116.152/32
11+
name: ip-restriction
12+
protocols:
13+
- grpc
14+
- https
15+
- name: prometheus
16+
service: a0955.spucs.apip_self-service_api_-_external.v1
17+
tags:
18+
- o11y
19+
config:
20+
per_consumer: false
21+
protocols:
22+
- grpc
23+
- https
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
_format_version: "3.0"
2+
services:
3+
- host: a0955.spucs.apip_self-service_api_-_external.v1.stream
4+
name: a0955.spucs.apip_self-service_api_-_external.v1
5+
port: 443
6+
protocol: https
7+
plugins:
8+
- config:
9+
allow:
10+
- 54.93.116.152/32
11+
name: ip-restriction
12+
protocols:
13+
- https
14+
- grpc
15+
- name: prometheus
16+
service: a0955.spucs.apip_self-service_api_-_external.v1
17+
tags:
18+
- o11y
19+
config:
20+
per_consumer: false
21+
protocols:
22+
- https
23+
- grpc

0 commit comments

Comments
 (0)