Skip to content
Merged
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,6 @@ github.com/kong/go-database-reconciler v1.33.0 h1:EAwap2hSCwHUJfVxbF+uw6UruqC47h
github.com/kong/go-database-reconciler v1.33.0/go.mod h1:CTFu9hfOh2L4qPniCUCqLYhKiuVA0UsQe0Iv4jZc58o=
github.com/kong/go-database-reconciler v1.35.0 h1:36Lmik7eoNMl+B/g6beWqBVgGl8b2vLXwNYNUVOtdRM=
github.com/kong/go-database-reconciler v1.35.0/go.mod h1:AeQNEbEQ/Wy3OwJiWIo3PwWCWfav25F/FsTESqbelac=
github.com/kong/go-kong v0.73.0 h1:Ct4EHJsJqoaYod39+gGy/JnU1664jzDbxTS2dk6Y628=

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed unused sum entries post running go mod tidy

github.com/kong/go-kong v0.73.0/go.mod h1:Wx5aTcMjyUnIF94M5NYFWb/EnuEkqB5STrWvybFSYYQ=
github.com/kong/go-kong v0.74.0 h1:iNs3tHeCRWL2lbJ4io0Rpm23u4GZchFY2wJ/BUxNs4w=
github.com/kong/go-kong v0.74.0/go.mod h1:Wx5aTcMjyUnIF94M5NYFWb/EnuEkqB5STrWvybFSYYQ=
github.com/kong/go-slugify v1.0.0 h1:vCFAyf2sdoSlBtLcrmDWUFn0ohlpKiKvQfXZkO5vSKY=
Expand Down
114 changes: 114 additions & 0 deletions tests/integration/sync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -834,6 +834,28 @@ var (
},
}

targetUpdatedWeight = []*kong.Target{
{
Target: kong.String("198.51.100.11:80"),
Upstream: &kong.Upstream{
ID: kong.String("a6f89ffc-1e53-4b01-9d3d-7a142bcd"),
},
Weight: kong.Int(100),
Failover: kong.Bool(false),
},
}

targetUpdatedWeightPost34 = []*kong.Target{
{
Target: kong.String("198.51.100.11:80"),
Upstream: &kong.Upstream{
ID: kong.String("a6f89ffc-1e53-4b01-9d3d-7a142bcd"),
},
Weight: kong.Int(100),
Failover: kong.Bool(false),
},
}

rateLimitingPlugin = []*kong.Plugin{
{
Name: kong.String("rate-limiting"),
Expand Down Expand Up @@ -3452,6 +3474,59 @@ func Test_Sync_Upstreams_Target_ZeroWeight_3x(t *testing.T) {
}
}

// test scope:
// - 3.x
func Test_Sync_Upstreams_Target_UpdateWeight(t *testing.T) {
client, err := getTestClient()
require.NoError(t, err)

tests := []struct {
name string
kongFile string
expectedState utils.KongRawState
runWhen string
}{
{
name: "updates weight of a target for an existing upstream >=3.4.0 <3.11.0",
kongFile: "testdata/sync/050-update-upstream-target-weight/after.yaml",
expectedState: utils.KongRawState{
Upstreams: upstreamPre311,
Targets: target,
},
runWhen: ">=3.4.0 <3.11.0",
},
{
name: "updates weight of a target for an existing upstream >=3.11.0 <3.12.0",
kongFile: "testdata/sync/050-update-upstream-target-weight/after.yaml",
expectedState: utils.KongRawState{
Upstreams: upstream,
Targets: target,
},
runWhen: ">=3.11.0 <3.12.0",
},
{
name: "updates weight of a target for an existing upstream >=3.12.0",
kongFile: "testdata/sync/050-update-upstream-target-weight/after.yaml",
expectedState: utils.KongRawState{
Upstreams: upstream,
Targets: targetUpdatedWeightPost34,
},
runWhen: ">=3.12.0",
},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
runWhen(t, "kong", tc.runWhen)
setup(t)
require.NoError(t, sync(context.Background(),
"testdata/sync/050-update-upstream-target-weight/before.yaml"))
require.NoError(t, sync(context.Background(), tc.kongFile))
testKongState(t, client, false, false,
tc.expectedState, nil)
})
}
}

// test scope:
// - konnect
func Test_Sync_Upstreams_Target_ZeroWeight_Konnect(t *testing.T) {
Expand Down Expand Up @@ -3490,6 +3565,45 @@ func testSyncUpstreamsTargetZeroWeightKonnectImpl(t *testing.T) {
}
}

// test scope:
// - konnect
func Test_Sync_Upstreams_Target_UpdateWeight_Konnect(t *testing.T) {
runDualTestWithSkipDefaults(t, "Test_Sync_Upstreams_Target_UpdateWeight_Konnect",
testSyncUpstreamsTargetUpdateWeightKonnectImpl)
}

func testSyncUpstreamsTargetUpdateWeightKonnectImpl(t *testing.T) {
client, err := getTestClient()
require.NoError(t, err)

tests := []struct {
name string
kongFile string
expectedState utils.KongRawState
}{
{
name: "updates weight in upstream target",
kongFile: "testdata/sync/050-update-upstream-target-weight/after.yaml",
expectedState: utils.KongRawState{
Upstreams: upstream,
Targets: targetUpdatedWeight,
},
},
}

for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
runWhen(t, "konnect", "")
setup(t)
require.NoError(t, sync(context.Background(),
"testdata/sync/050-update-upstream-target-weight/before.yaml"))
require.NoError(t, sync(context.Background(), tc.kongFile))
testKongState(t, client, true, false,
tc.expectedState, nil)
})
}
}

func Test_Sync_RateLimitingPlugin(t *testing.T) {
// setup stage
client, err := getTestClient()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
_format_version: "3.0"
upstreams:
- name: upstream1
algorithm: round-robin
targets:
- target: 198.51.100.11:80
weight: 100
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
_format_version: "3.0"
upstreams:
- name: upstream1
algorithm: round-robin
targets:
- target: 198.51.100.11:80
weight: 0
Loading