Skip to content

Commit

Permalink
server/config: fix MonitorPluginConfiguration test
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
dcbw committed Sep 14, 2023
1 parent 8539a47 commit c2add82
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions pkg/server/config/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"fmt"
"os"
"sync"
"time"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
Expand Down Expand Up @@ -104,19 +103,17 @@ 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 := `
{
"cniVersion": "0.4.0",
"name": "mycni-name",
"type": "mycni2",
"capabilities": {"portMappings": true},
"ipam": {},
"dns": {}
}
Expand All @@ -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() {
Expand Down

0 comments on commit c2add82

Please sign in to comment.