From 88e8973004348bd7961cd2cc1cfe937aa8e989d2 Mon Sep 17 00:00:00 2001 From: Piotr Kazmierczak <470696+pkazmierczak@users.noreply.github.com> Date: Wed, 3 Jul 2024 16:09:16 +0200 Subject: [PATCH] consul: additional unit test for consul config merging (#23495) --- command/agent/config_test.go | 37 ++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/command/agent/config_test.go b/command/agent/config_test.go index f8507e1f1..48dec05eb 100644 --- a/command/agent/config_test.go +++ b/command/agent/config_test.go @@ -1742,3 +1742,40 @@ func TestParseMultipleIPTemplates(t *testing.T) { }) } } + +// this test makes sure Consul configs with and without WI merging happens +// correctly; here to assure we don't introduce regressions +func Test_mergeConsulConfigs(t *testing.T) { + ci.Parallel(t) + + c0 := &Config{ + Consuls: []*config.ConsulConfig{ + { + Token: "foo", + AllowUnauthenticated: pointer.Of(true), + }, + }, + } + + c1 := &Config{ + Consuls: []*config.ConsulConfig{ + { + ServiceIdentity: &config.WorkloadIdentityConfig{ + Audience: []string{"consul.io"}, + TTL: pointer.Of(time.Hour), + }, + TaskIdentity: &config.WorkloadIdentityConfig{ + Audience: []string{"consul.io"}, + TTL: pointer.Of(time.Hour), + }, + }, + }, + } + + result := c0.Merge(c1) + + must.Eq(t, c1.Consuls[0].ServiceIdentity, result.Consuls[0].ServiceIdentity) + must.Eq(t, c1.Consuls[0].TaskIdentity, result.Consuls[0].TaskIdentity) + must.Eq(t, c0.Consuls[0].Token, result.Consuls[0].Token) + must.Eq(t, c0.Consuls[0].AllowUnauthenticated, result.Consuls[0].AllowUnauthenticated) +}