From 8233bb0925f738250bbcd11fee9dbe6c99238243 Mon Sep 17 00:00:00 2001 From: shivay Date: Mon, 20 Apr 2026 11:15:07 +0530 Subject: [PATCH 1/4] test: preserve comment lines to hanlde big multi-line yamls --- tests/integration/sync_test.go | 65 ++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/tests/integration/sync_test.go b/tests/integration/sync_test.go index 7add73d48..aed8c2842 100644 --- a/tests/integration/sync_test.go +++ b/tests/integration/sync_test.go @@ -11985,3 +11985,68 @@ func testSyncPluginConditionalKonnectImpl(t *testing.T) { testKongState(t, client, true, false, expectedStatePostSync, nil) } + +// Test_RequestTermination_Dump_Diff ensures that a create-via-API → dump → diff +// round-trip produces zero changes. This is a regression test for a bug where +// YAML-wrapped continuation lines starting with '#' +// were incorrectly stripped by renderTemplate, causing spurious diffs. +// +// test scope: +// - kong >=3.0.0 +func Test_RequestTermination_Dump_Diff(t *testing.T) { + runWhen(t, "kong", ">=3.0.0") + setup(t) + + ctx := context.Background() + + client, err := getTestClient() + require.NoError(t, err) + + body := `{"email":[{"subject":"Lion Rock","htmlemail":"Lion Rock Business Class Lounge Pass cancellation.` + + `","textemail":""}],"sms":"","errors":null}` + + // Step 1: Create the plugin via the Kong Admin API, simulating a plugin + // created through Kong Manager UI (pristine body, no prior YAML round-trip). + createdPlugin, err := client.Plugins.Create(ctx, &kong.Plugin{ + Name: kong.String("request-termination"), + Enabled: kong.Bool(true), + Config: kong.Configuration{ + "status_code": float64(200), + "body": body, + "content_type": "application/json", + "echo": false, + "message": nil, + "trigger": nil, + }, + Protocols: kong.StringSlice("grpc", "grpcs", "http", "https"), + }) + require.NoError(t, err) + t.Cleanup(func() { + if createdPlugin != nil && createdPlugin.ID != nil { + _ = client.Plugins.Delete(ctx, createdPlugin.ID) + } + }) + + tmpFile, err := os.CreateTemp("", "deck-rt-dump-*.yaml") + require.NoError(t, err) + tmpFile.Close() + require.NoError(t, os.Remove(tmpFile.Name())) + t.Cleanup(func() { os.Remove(tmpFile.Name()) }) // no-op if dump already wrote it + + _, err = dump("-o", tmpFile.Name()) + require.NoError(t, err) + + diffOut, err := diff(tmpFile.Name()) + require.NoError(t, err) + assert.Contains(t, diffOut, "Created: 0", + "expected no diff between Kong state and the dumped file, got:\n%s", diffOut) + assert.Contains(t, diffOut, "Updated: 0", + "expected no diff between Kong state and the dumped file, got:\n%s", diffOut) + assert.Contains(t, diffOut, "Deleted: 0", + "expected no diff between Kong state and the dumped file, got:\n%s", diffOut) +} From 7e7c2438ec47ca51cc7891a382e86114bb5d6c8d Mon Sep 17 00:00:00 2001 From: shivay Date: Wed, 22 Apr 2026 12:08:37 +0530 Subject: [PATCH 2/4] chore: updated gdr with commit hash of fix. --- go.mod | 10 +++++----- go.sum | 20 ++++++++++---------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/go.mod b/go.mod index 78819f439..02ff156db 100644 --- a/go.mod +++ b/go.mod @@ -11,10 +11,10 @@ require ( github.com/blang/semver/v4 v4.0.0 github.com/daveshanley/vacuum v0.25.5 github.com/ettle/strcase v0.2.0 - github.com/fatih/color v1.18.0 + github.com/fatih/color v1.19.0 github.com/google/go-cmp v0.7.0 github.com/kong/go-apiops v0.4.0 - github.com/kong/go-database-reconciler v1.35.1 + github.com/kong/go-database-reconciler v1.35.2-0.20260422063407-79ce1626d78b github.com/kong/go-kong v0.74.0 github.com/mitchellh/go-homedir v1.1.0 github.com/spf13/cobra v1.10.2 @@ -24,9 +24,9 @@ require ( golang.org/x/sync v0.20.0 k8s.io/api v0.35.2 k8s.io/apiextensions-apiserver v0.33.1 - k8s.io/apimachinery v0.35.2 + k8s.io/apimachinery v0.35.3 k8s.io/client-go v0.35.2 - k8s.io/code-generator v0.35.1 + k8s.io/code-generator v0.35.3 sigs.k8s.io/gateway-api v1.5.1 sigs.k8s.io/yaml v1.6.0 ) @@ -87,7 +87,7 @@ require ( github.com/peterbourgon/diskv v2.0.1+incompatible // indirect github.com/pkg/errors v0.9.1 // indirect github.com/russross/blackfriday/v2 v2.1.0 // indirect - github.com/samber/lo v1.52.0 // indirect + github.com/samber/lo v1.53.0 // indirect github.com/santhosh-tekuri/jsonschema/v6 v6.0.2 // indirect github.com/sethvargo/go-password v0.3.1 // indirect github.com/shirou/gopsutil/v3 v3.24.5 // indirect diff --git a/go.sum b/go.sum index 9d79076ca..b8487d320 100644 --- a/go.sum +++ b/go.sum @@ -87,8 +87,8 @@ github.com/exponent-io/jsonpath v0.0.0-20151013193312-d6023ce2651d h1:105gxyaGwC github.com/exponent-io/jsonpath v0.0.0-20151013193312-d6023ce2651d/go.mod h1:ZZMPRZwes7CROmyNKgQzC3XPs6L/G2EJLHddWejkmf4= github.com/fatih/camelcase v1.0.0 h1:hxNvNX/xYBp0ovncs8WyWZrOrpBNub/JfaMvbURyft8= github.com/fatih/camelcase v1.0.0/go.mod h1:yN2Sb0lFhZJUdVvtELVWefmrXpuZESvPmqwoZc+/fpc= -github.com/fatih/color v1.18.0 h1:S8gINlzdQ840/4pfAwic/ZE0djQEH3wM94VfqLTZcOM= -github.com/fatih/color v1.18.0/go.mod h1:4FelSpRwEGDpQ12mAdzqdOukCy4u8WUtOY6lkT/6HfU= +github.com/fatih/color v1.19.0 h1:Zp3PiM21/9Ld6FzSKyL5c/BULoe/ONr9KlbYVOfG8+w= +github.com/fatih/color v1.19.0/go.mod h1:zNk67I0ZUT1bEGsSGyCZYZNrHuTkJJB+r6Q9VuMi0LE= github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg= github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U= github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8= @@ -207,8 +207,8 @@ github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= github.com/kong/go-apiops v0.4.0 h1:rXxdcE6VkDTOkhGt/ZytYqp8elw3SfrBQ/+r42lX2J4= github.com/kong/go-apiops v0.4.0/go.mod h1:Xt99d90LallLVwYJAGaufiNbBdsK0KKboe7gR4Ryths= -github.com/kong/go-database-reconciler v1.35.1 h1:u8e7bL/T14UD+tI2ynjLhboOjtvEOk98L2iz79gTP6w= -github.com/kong/go-database-reconciler v1.35.1/go.mod h1:AeQNEbEQ/Wy3OwJiWIo3PwWCWfav25F/FsTESqbelac= +github.com/kong/go-database-reconciler v1.35.2-0.20260422063407-79ce1626d78b h1:uzS6D4L10ExKGdU5DsheuZS/kAbG8YKh7u05MtRWG1w= +github.com/kong/go-database-reconciler v1.35.2-0.20260422063407-79ce1626d78b/go.mod h1:0CDU0gXCBmcwsrWS/rf9oAj2I9Cd19BMEz9/4kYVpTU= 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= @@ -311,8 +311,8 @@ github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/sagikazarmark/locafero v0.11.0 h1:1iurJgmM9G3PA/I+wWYIOw/5SyBtxapeHDcg+AAIFXc= github.com/sagikazarmark/locafero v0.11.0/go.mod h1:nVIGvgyzw595SUSUE6tvCp3YYTeHs15MvlmU87WwIik= -github.com/samber/lo v1.52.0 h1:Rvi+3BFHES3A8meP33VPAxiBZX/Aws5RxrschYGjomw= -github.com/samber/lo v1.52.0/go.mod h1:4+MXEGsJzbKGaUEQFKBq2xtfuznW9oz/WrgyzMzRoM0= +github.com/samber/lo v1.53.0 h1:t975lj2py4kJPQ6haz1QMgtId2gtmfktACxIXArw3HM= +github.com/samber/lo v1.53.0/go.mod h1:4+MXEGsJzbKGaUEQFKBq2xtfuznW9oz/WrgyzMzRoM0= github.com/santhosh-tekuri/jsonschema/v6 v6.0.2 h1:KRzFb2m7YtdldCEkzs6KqmJw4nqEVZGK7IN2kJkjTuQ= github.com/santhosh-tekuri/jsonschema/v6 v6.0.2/go.mod h1:JXeL+ps8p7/KNMjDQk3TCwPpBy0wYklyWTfbkIzdIFU= github.com/sergi/go-diff v1.2.0 h1:XU+rvMAioB0UC3q1MFrIQy4Vo5/4VsRDQQXHsEya6xQ= @@ -585,14 +585,14 @@ k8s.io/api v0.35.2 h1:tW7mWc2RpxW7HS4CoRXhtYHSzme1PN1UjGHJ1bdrtdw= k8s.io/api v0.35.2/go.mod h1:7AJfqGoAZcwSFhOjcGM7WV05QxMMgUaChNfLTXDRE60= k8s.io/apiextensions-apiserver v0.33.1 h1:N7ccbSlRN6I2QBcXevB73PixX2dQNIW0ZRuguEE91zI= k8s.io/apiextensions-apiserver v0.33.1/go.mod h1:uNQ52z1A1Gu75QSa+pFK5bcXc4hq7lpOXbweZgi4dqA= -k8s.io/apimachinery v0.35.2 h1:NqsM/mmZA7sHW02JZ9RTtk3wInRgbVxL8MPfzSANAK8= -k8s.io/apimachinery v0.35.2/go.mod h1:jQCgFZFR1F4Ik7hvr2g84RTJSZegBc8yHgFWKn//hns= +k8s.io/apimachinery v0.35.3 h1:MeaUwQCV3tjKP4bcwWGgZ/cp/vpsRnQzqO6J6tJyoF8= +k8s.io/apimachinery v0.35.3/go.mod h1:jQCgFZFR1F4Ik7hvr2g84RTJSZegBc8yHgFWKn//hns= k8s.io/cli-runtime v0.31.0 h1:V2Q1gj1u3/WfhD475HBQrIYsoryg/LrhhK4RwpN+DhA= k8s.io/cli-runtime v0.31.0/go.mod h1:vg3H94wsubuvWfSmStDbekvbla5vFGC+zLWqcf+bGDw= k8s.io/client-go v0.35.2 h1:YUfPefdGJA4aljDdayAXkc98DnPkIetMl4PrKX97W9o= k8s.io/client-go v0.35.2/go.mod h1:4QqEwh4oQpeK8AaefZ0jwTFJw/9kIjdQi0jpKeYvz7g= -k8s.io/code-generator v0.35.1 h1:yLKR2la7Z9cWT5qmk67ayx8xXLM4RRKQMnC8YPvTWRI= -k8s.io/code-generator v0.35.1/go.mod h1:F2Fhm7aA69tC/VkMXLDokdovltXEF026Tb9yfQXQWKg= +k8s.io/code-generator v0.35.3 h1:NDGCLkEm6Ho65wTdSe2EgErmmtsrezOPwwOchlNc6FQ= +k8s.io/code-generator v0.35.3/go.mod h1:LAVriRGXQusHQ0Ns64SE1ublSswm1KrK7cXn0GuQETg= k8s.io/component-base v0.33.1 h1:EoJ0xA+wr77T+G8p6T3l4efT2oNwbqBVKR71E0tBIaI= k8s.io/component-base v0.33.1/go.mod h1:guT/w/6piyPfTgq7gfvgetyXMIh10zuXA6cRRm3rDuY= k8s.io/gengo/v2 v2.0.0-20250922181213-ec3ebc5fd46b h1:gMplByicHV/TJBizHd9aVEsTYoJBnnUAT5MHlTkbjhQ= From 76801fc9d7ceebe5d0f59670e69de68d8ea947ab Mon Sep 17 00:00:00 2001 From: shivay Date: Mon, 27 Apr 2026 16:09:07 +0530 Subject: [PATCH 3/4] chore: updated related dependency. --- go.mod | 10 +++++----- go.sum | 20 ++++++++++---------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/go.mod b/go.mod index 165154181..ec5ce8c7f 100644 --- a/go.mod +++ b/go.mod @@ -14,18 +14,18 @@ require ( github.com/fatih/color v1.19.0 github.com/google/go-cmp v0.7.0 github.com/kong/go-apiops v0.4.0 - github.com/kong/go-database-reconciler v1.35.2-0.20260422063407-79ce1626d78b - github.com/kong/go-kong v0.74.0 + github.com/kong/go-database-reconciler v1.36.2 + github.com/kong/go-kong v0.75.0 github.com/mitchellh/go-homedir v1.1.0 github.com/spf13/cobra v1.10.2 github.com/spf13/pflag v1.0.10 github.com/spf13/viper v1.21.0 github.com/stretchr/testify v1.11.1 golang.org/x/sync v0.20.0 - k8s.io/api v0.35.2 + k8s.io/api v0.35.4 k8s.io/apiextensions-apiserver v0.33.1 - k8s.io/apimachinery v0.35.3 - k8s.io/client-go v0.35.2 + k8s.io/apimachinery v0.35.4 + k8s.io/client-go v0.35.4 k8s.io/code-generator v0.35.3 sigs.k8s.io/gateway-api v1.5.1 sigs.k8s.io/yaml v1.6.0 diff --git a/go.sum b/go.sum index c32c154ed..be31da768 100644 --- a/go.sum +++ b/go.sum @@ -207,10 +207,10 @@ github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= github.com/kong/go-apiops v0.4.0 h1:rXxdcE6VkDTOkhGt/ZytYqp8elw3SfrBQ/+r42lX2J4= github.com/kong/go-apiops v0.4.0/go.mod h1:Xt99d90LallLVwYJAGaufiNbBdsK0KKboe7gR4Ryths= -github.com/kong/go-database-reconciler v1.35.2-0.20260422063407-79ce1626d78b h1:uzS6D4L10ExKGdU5DsheuZS/kAbG8YKh7u05MtRWG1w= -github.com/kong/go-database-reconciler v1.35.2-0.20260422063407-79ce1626d78b/go.mod h1:0CDU0gXCBmcwsrWS/rf9oAj2I9Cd19BMEz9/4kYVpTU= -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-database-reconciler v1.36.2 h1:fUKSWonpR1UmJdLumJ9CdD4cYQ2wDEF627hJoFr3OBI= +github.com/kong/go-database-reconciler v1.36.2/go.mod h1:0UfhRA9oelppRbirZMp0EM9qTlxb7iu3gJd+WKzoC0w= +github.com/kong/go-kong v0.75.0 h1:QXbujfCJc5TauYS0EhKde2hbOCDe0YZTRYIX+qa+Adc= +github.com/kong/go-kong v0.75.0/go.mod h1:Wx5aTcMjyUnIF94M5NYFWb/EnuEkqB5STrWvybFSYYQ= github.com/kong/go-slugify v1.0.0 h1:vCFAyf2sdoSlBtLcrmDWUFn0ohlpKiKvQfXZkO5vSKY= github.com/kong/go-slugify v1.0.0/go.mod h1:dbR2h3J2QKXQ1k0aww6cN7o4cIcwlWflr6RKRdcoaiw= github.com/kong/kubernetes-configuration v1.5.3 h1:4Hh2ZAT5zjHHqx07VVMF5lIUZ7c2RAOUpIINpOsduZs= @@ -581,16 +581,16 @@ gotest.tools/v3 v3.5.1 h1:EENdUnS3pdur5nybKYIh2Vfgc8IUNBjxDPSjtiJcOzU= gotest.tools/v3 v3.5.1/go.mod h1:isy3WKz7GK6uNw/sbHzfKBLvlvXwUyV06n6brMxxopU= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= -k8s.io/api v0.35.2 h1:tW7mWc2RpxW7HS4CoRXhtYHSzme1PN1UjGHJ1bdrtdw= -k8s.io/api v0.35.2/go.mod h1:7AJfqGoAZcwSFhOjcGM7WV05QxMMgUaChNfLTXDRE60= +k8s.io/api v0.35.4 h1:P7nFYKl5vo9AGUp1Z+Pmd3p2tA7bX2wbFWCvDeRv988= +k8s.io/api v0.35.4/go.mod h1:yl4lqySWOgYJJf9RERXKUwE9g2y+CkuwG+xmcOK8wXU= k8s.io/apiextensions-apiserver v0.33.1 h1:N7ccbSlRN6I2QBcXevB73PixX2dQNIW0ZRuguEE91zI= k8s.io/apiextensions-apiserver v0.33.1/go.mod h1:uNQ52z1A1Gu75QSa+pFK5bcXc4hq7lpOXbweZgi4dqA= -k8s.io/apimachinery v0.35.3 h1:MeaUwQCV3tjKP4bcwWGgZ/cp/vpsRnQzqO6J6tJyoF8= -k8s.io/apimachinery v0.35.3/go.mod h1:jQCgFZFR1F4Ik7hvr2g84RTJSZegBc8yHgFWKn//hns= +k8s.io/apimachinery v0.35.4 h1:xtdom9RG7e+yDp71uoXoJDWEE2eOiHgeO4GdBzwWpds= +k8s.io/apimachinery v0.35.4/go.mod h1:NNi1taPOpep0jOj+oRha3mBJPqvi0hGdaV8TCqGQ+cc= k8s.io/cli-runtime v0.31.0 h1:V2Q1gj1u3/WfhD475HBQrIYsoryg/LrhhK4RwpN+DhA= k8s.io/cli-runtime v0.31.0/go.mod h1:vg3H94wsubuvWfSmStDbekvbla5vFGC+zLWqcf+bGDw= -k8s.io/client-go v0.35.2 h1:YUfPefdGJA4aljDdayAXkc98DnPkIetMl4PrKX97W9o= -k8s.io/client-go v0.35.2/go.mod h1:4QqEwh4oQpeK8AaefZ0jwTFJw/9kIjdQi0jpKeYvz7g= +k8s.io/client-go v0.35.4 h1:DN6fyaGuzK64UvnKO5fOA6ymSjvfGAnCAHAR0C66kD8= +k8s.io/client-go v0.35.4/go.mod h1:2Pg9WpsS4NeOpoYTfHHfMxBG8zFMSAUi4O/qoiJC3nY= k8s.io/code-generator v0.35.3 h1:NDGCLkEm6Ho65wTdSe2EgErmmtsrezOPwwOchlNc6FQ= k8s.io/code-generator v0.35.3/go.mod h1:LAVriRGXQusHQ0Ns64SE1ublSswm1KrK7cXn0GuQETg= k8s.io/component-base v0.33.1 h1:EoJ0xA+wr77T+G8p6T3l4efT2oNwbqBVKR71E0tBIaI= From 6992aede52ebe0316f313321ad4e048ad1f102c0 Mon Sep 17 00:00:00 2001 From: shivay Date: Mon, 27 Apr 2026 18:42:11 +0530 Subject: [PATCH 4/4] chore: resolved review comment. --- tests/integration/diff_test.go | 66 ++++++++++++++++++++++++++++++++++ tests/integration/sync_test.go | 65 --------------------------------- 2 files changed, 66 insertions(+), 65 deletions(-) diff --git a/tests/integration/diff_test.go b/tests/integration/diff_test.go index 7d85fd9db..de05a5a8a 100644 --- a/tests/integration/diff_test.go +++ b/tests/integration/diff_test.go @@ -8,6 +8,7 @@ import ( "testing" "github.com/kong/go-database-reconciler/pkg/utils" + "github.com/kong/go-kong/kong" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -1124,3 +1125,68 @@ func Test_Diff_Konnect_Workspace(t *testing.T) { }) } } + +// Test_RequestTermination_Dump_Diff ensures that a create-via-API → dump → diff +// round-trip produces zero changes. This is a regression test for a bug where +// YAML-wrapped continuation lines starting with '#' +// were incorrectly stripped by renderTemplate, causing spurious diffs. +// +// test scope: +// - kong >=3.0.0 +func Test_RequestTermination_Dump_Diff(t *testing.T) { + runWhen(t, "kong", ">=3.0.0") + setup(t) + + ctx := context.Background() + + client, err := getTestClient() + require.NoError(t, err) + + body := `{"email":[{"subject":"Lion Rock","htmlemail":"Lion Rock Business Class Lounge Pass cancellation.` + + `","textemail":""}],"sms":"","errors":null}` + + // Step 1: Create the plugin via the Kong Admin API, simulating a plugin + // created through Kong Manager UI (pristine body, no prior YAML round-trip). + createdPlugin, err := client.Plugins.Create(ctx, &kong.Plugin{ + Name: kong.String("request-termination"), + Enabled: kong.Bool(true), + Config: kong.Configuration{ + "status_code": float64(200), + "body": body, + "content_type": "application/json", + "echo": false, + "message": nil, + "trigger": nil, + }, + Protocols: kong.StringSlice("grpc", "grpcs", "http", "https"), + }) + require.NoError(t, err) + t.Cleanup(func() { + if createdPlugin != nil && createdPlugin.ID != nil { + _ = client.Plugins.Delete(ctx, createdPlugin.ID) + } + }) + + tmpFile, err := os.CreateTemp("", "deck-rt-dump-*.yaml") + require.NoError(t, err) + tmpFile.Close() + require.NoError(t, os.Remove(tmpFile.Name())) + t.Cleanup(func() { os.Remove(tmpFile.Name()) }) // no-op if dump already wrote it + + _, err = dump("-o", tmpFile.Name()) + require.NoError(t, err) + + diffOut, err := diff(tmpFile.Name()) + require.NoError(t, err) + assert.Contains(t, diffOut, "Created: 0", + "expected no diff between Kong state and the dumped file, got:\n%s", diffOut) + assert.Contains(t, diffOut, "Updated: 0", + "expected no diff between Kong state and the dumped file, got:\n%s", diffOut) + assert.Contains(t, diffOut, "Deleted: 0", + "expected no diff between Kong state and the dumped file, got:\n%s", diffOut) +} diff --git a/tests/integration/sync_test.go b/tests/integration/sync_test.go index 7fd0db5ef..ccadb6c92 100644 --- a/tests/integration/sync_test.go +++ b/tests/integration/sync_test.go @@ -12178,68 +12178,3 @@ func testSyncPluginConditionalKonnectImpl(t *testing.T) { testKongState(t, client, true, false, expectedStatePostSync, nil) } - -// Test_RequestTermination_Dump_Diff ensures that a create-via-API → dump → diff -// round-trip produces zero changes. This is a regression test for a bug where -// YAML-wrapped continuation lines starting with '#' -// were incorrectly stripped by renderTemplate, causing spurious diffs. -// -// test scope: -// - kong >=3.0.0 -func Test_RequestTermination_Dump_Diff(t *testing.T) { - runWhen(t, "kong", ">=3.0.0") - setup(t) - - ctx := context.Background() - - client, err := getTestClient() - require.NoError(t, err) - - body := `{"email":[{"subject":"Lion Rock","htmlemail":"Lion Rock Business Class Lounge Pass cancellation.` + - `","textemail":""}],"sms":"","errors":null}` - - // Step 1: Create the plugin via the Kong Admin API, simulating a plugin - // created through Kong Manager UI (pristine body, no prior YAML round-trip). - createdPlugin, err := client.Plugins.Create(ctx, &kong.Plugin{ - Name: kong.String("request-termination"), - Enabled: kong.Bool(true), - Config: kong.Configuration{ - "status_code": float64(200), - "body": body, - "content_type": "application/json", - "echo": false, - "message": nil, - "trigger": nil, - }, - Protocols: kong.StringSlice("grpc", "grpcs", "http", "https"), - }) - require.NoError(t, err) - t.Cleanup(func() { - if createdPlugin != nil && createdPlugin.ID != nil { - _ = client.Plugins.Delete(ctx, createdPlugin.ID) - } - }) - - tmpFile, err := os.CreateTemp("", "deck-rt-dump-*.yaml") - require.NoError(t, err) - tmpFile.Close() - require.NoError(t, os.Remove(tmpFile.Name())) - t.Cleanup(func() { os.Remove(tmpFile.Name()) }) // no-op if dump already wrote it - - _, err = dump("-o", tmpFile.Name()) - require.NoError(t, err) - - diffOut, err := diff(tmpFile.Name()) - require.NoError(t, err) - assert.Contains(t, diffOut, "Created: 0", - "expected no diff between Kong state and the dumped file, got:\n%s", diffOut) - assert.Contains(t, diffOut, "Updated: 0", - "expected no diff between Kong state and the dumped file, got:\n%s", diffOut) - assert.Contains(t, diffOut, "Deleted: 0", - "expected no diff between Kong state and the dumped file, got:\n%s", diffOut) -}