Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crictl config --set if the YAML defines entries multiple times #1661

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/common/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,9 @@ func setConfigOption(configName, configValue string, yamlData *yaml.Node) {
for indx := 0; indx < contentLen-1; {
name := yamlData.Content[0].Content[indx].Value
if name == configName {
// Set the value, even if we have the option defined multiple times.
yamlData.Content[0].Content[indx+1].Value = configValue
foundOption = true
break
}
indx += 2
}
Expand Down
38 changes: 38 additions & 0 deletions test/e2e/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,42 @@ pull-image-on-create: false
disable-pull-on-run: false
`))
})

It("should succeed to get the right value if duplicate entries are defined", func() {
_, err := configFile.WriteString(`
timeout: 20
timeout: 5
timeout: 10
`)
Expect(err).NotTo(HaveOccurred())

t.CrictlExpectSuccess("--config "+configFile.Name()+" config --get timeout", "10")
})

It("should succeed to set duplicate entries", func() {
_, err := configFile.WriteString(`
timeout: 20
timeout: 5
timeout: 10
`)
Expect(err).NotTo(HaveOccurred())

t.CrictlExpectSuccess("--config "+configFile.Name()+" config --set timeout=30", "")

cfgContent, err := os.ReadFile(configFile.Name())
Expect(err).NotTo(HaveOccurred())

Expect(string(cfgContent)).To(Equal(
`timeout: 30
timeout: 30
timeout: 30
runtime-endpoint: ""
image-endpoint: ""
debug: false
pull-image-on-create: false
disable-pull-on-run: false
`))

t.CrictlExpectSuccess("--config "+configFile.Name()+" config --get timeout", "30")
})
})
Loading