From 56ab5ed0e8d973e63b356b6bce1b5a0f4df1e003 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20=C5=81askawiec?= Date: Mon, 14 Oct 2024 19:34:55 +0200 Subject: [PATCH] Fixed tests and linter --- test/e2e/util/mongotester/mongotester.go | 26 ++----------------- test/e2e/util/mongotester/mongotester_test.go | 14 ++++++++-- 2 files changed, 14 insertions(+), 26 deletions(-) diff --git a/test/e2e/util/mongotester/mongotester.go b/test/e2e/util/mongotester/mongotester.go index cd21baf7c..9d6d3b139 100644 --- a/test/e2e/util/mongotester/mongotester.go +++ b/test/e2e/util/mongotester/mongotester.go @@ -120,7 +120,7 @@ func (m *Tester) HasKeyfileAuth(tries int, opts ...OptionApplier) func(t *testin } func (m *Tester) HasFCV(fcv string, tries int, opts ...OptionApplier) func(t *testing.T) { - return m.hasAdminParameter("featureCompatibilityVersion", bson.D{{"version", fcv}}, tries, opts...) + return m.hasAdminParameter("featureCompatibilityVersion", bson.D{{Key: "version", Value: fcv}}, tries, opts...) } func (m *Tester) ScramIsConfigured(tries int, opts ...OptionApplier) func(t *testing.T) { @@ -168,7 +168,7 @@ func (m *Tester) VerifyRoles(expectedRoles []automationconfig.CustomRole, tries t.Fatal(err) return false } - assert.ElementsMatch(t, result.Roles, expectedRoles) + assert.Subset(t, result.Roles, expectedRoles) return true }, tries, opts...) } @@ -422,28 +422,6 @@ func (c clientOptionAdder) ApplyOption(opts ...options.Lister[options.ClientOpti return append(opts, c.option) } -// clientOptionRemover is used if a value from the client array of options should be removed. -// assigning a nil value will not take precedence over an existing value, so we need a mechanism -// to remove elements that are present - -// e.g. to disable TLS, you need to remove the options.ClientOption that has a non-nil tls config -// it is not enough to add a tls config that has a nil value. -type clientOptionRemover struct { - // removalPredicate is a function which returns a bool indicating - // if a given options.ClientOption should be removed. - removalPredicate func(opt *options.ClientOptions) bool -} - -func (c clientOptionRemover) ApplyOption(opts ...*options.ClientOptions) []*options.ClientOptions { - newOpts := make([]*options.ClientOptions, 0) - for _, opt := range opts { - if !c.removalPredicate(opt) { - newOpts = append(newOpts, opt) - } - } - return newOpts -} - // WithScram provides a configuration option that will configure the MongoDB resource // with the given username and password func WithScram(username, password string) OptionApplier { diff --git a/test/e2e/util/mongotester/mongotester_test.go b/test/e2e/util/mongotester/mongotester_test.go index 4b67d635a..d99969807 100644 --- a/test/e2e/util/mongotester/mongotester_test.go +++ b/test/e2e/util/mongotester/mongotester_test.go @@ -22,13 +22,18 @@ func TestTlsRemoval_RemovesCorrectConfig(t *testing.T) { // remove the tls value opts = removalOpt.ApplyOption(opts...) + var errs []error raw := options.ClientOptions{} for _, opt := range opts { for _, fn := range opt.List() { - fn(&raw) + err := fn(&raw) + if err != nil { + errs = append(errs, err) + } } } + assert.Len(t, errs, 0) assert.Len(t, opts, 3, "tls removal should remove an element") assert.NotNil(t, raw.Hosts, "tls removal should not effect other configs") assert.Len(t, raw.Hosts, 3, "original configs should not be changed") @@ -39,12 +44,17 @@ func TestWithScram_AddsScramOption(t *testing.T) { opts := WithScram("username", "password").ApplyOption() raw := options.ClientOptions{} + var errs []error for _, opt := range opts { for _, fn := range opt.List() { - fn(&raw) + err := fn(&raw) + if err != nil { + errs = append(errs, err) + } } } + assert.Len(t, errs, 0) assert.Len(t, opts, 1) assert.NotNil(t, opts) assert.Equal(t, raw.Auth.AuthMechanism, "SCRAM-SHA-256")