From c2add82b9358c2a4c94dc3eff862686f80414ef2 Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Tue, 12 Sep 2023 21:18:32 -0500 Subject: [PATCH] server/config: fix MonitorPluginConfiguration test The test was comparing the same configuration to itself, since nothing in the changed CNI configuration is used in the written multus configuration. Instead make sure the updated CNI config contains something that will be reflected in the written multus configuration, and while we're there use a more robust way to wait for the config to be written via gomega.Eventually(). Signed-off-by: Dan Williams --- pkg/server/config/manager_test.go | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/pkg/server/config/manager_test.go b/pkg/server/config/manager_test.go index ab3efadb8..2d4b2e0dd 100644 --- a/pkg/server/config/manager_test.go +++ b/pkg/server/config/manager_test.go @@ -20,7 +20,6 @@ import ( "fmt" "os" "sync" - "time" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" @@ -104,12 +103,9 @@ var _ = Describe("Configuration Manager", func() { }) It("Check MonitorPluginConfiguration", func() { - config, err := configManager.GenerateConfig() - Expect(err).NotTo(HaveOccurred()) - ctx, cancel := context.WithCancel(context.Background()) defer cancel() - err = configManager.Start(ctx, wg) + err := configManager.Start(ctx, wg) Expect(err).NotTo(HaveOccurred()) updatedCNIConfig := ` @@ -117,6 +113,7 @@ var _ = Describe("Configuration Manager", func() { "cniVersion": "0.4.0", "name": "mycni-name", "type": "mycni2", + "capabilities": {"portMappings": true}, "ipam": {}, "dns": {} } @@ -125,10 +122,11 @@ var _ = Describe("Configuration Manager", func() { Expect(os.WriteFile(defaultCniConfig, []byte(updatedCNIConfig), UserRWPermission)).To(Succeed()) // wait for a while to get fsnotify event - time.Sleep(100 * time.Millisecond) - file, err := os.ReadFile(configManager.multusConfigFilePath) - Expect(err).NotTo(HaveOccurred()) - Expect(string(file)).To(Equal(config)) + Eventually(func() string { + file, err := os.ReadFile(configManager.multusConfigFilePath) + Expect(err).NotTo(HaveOccurred()) + return string(file) + }, 2).Should(ContainSubstring("portMappings")) }) When("the user requests the name of the multus configuration to be overridden", func() {