Skip to content

Commit

Permalink
Make ScanNoLogs really silent
Browse files Browse the repository at this point in the history
We were not making it with no logs fully unless we explicitely passed
the option. Now it makes more sense as its full silent

Signed-off-by: Itxaka <[email protected]>
  • Loading branch information
Itxaka committed Nov 6, 2024
1 parent 5aac4eb commit 06d17b4
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 11 deletions.
3 changes: 2 additions & 1 deletion pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -392,10 +392,11 @@ func FilterKeys(d []byte) ([]byte, error) {
}

// ScanNoLogs is a wrapper around Scan that sets the logger to null
// Also sets the NoLogs option to true by default
func ScanNoLogs(opts ...collector.Option) (c *Config, err error) {
log := sdkTypes.NewNullLogger()
result := NewConfig(WithLogger(log))
return scan(result, opts...)
return scan(result, append(opts, collector.NoLogs)...)
}

// Scan is a wrapper around collector.Scan that sets the logger to the default Kairos logger
Expand Down
6 changes: 3 additions & 3 deletions pkg/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ var _ = Describe("Schema", func() {
cleanup()
})
It("Scan can override options", func() {
c, err := ScanNoLogs(collector.Readers(strings.NewReader(`uki-max-entries: 34`)), collector.NoLogs)
c, err := ScanNoLogs(collector.Readers(strings.NewReader(`uki-max-entries: 34`)))
Expect(err).ShouldNot(HaveOccurred())
Expect(c.UkiMaxEntries).To(Equal(34))
})
Expand Down Expand Up @@ -279,7 +279,7 @@ stages:
groups:
- "admin"
`
config, err := pkgConfig.ScanNoLogs(collector.Readers(strings.NewReader(cc)), collector.NoLogs)
config, err := pkgConfig.ScanNoLogs(collector.Readers(strings.NewReader(cc)))
Expect(err).ToNot(HaveOccurred())
Expect(config.CheckForUsers()).ToNot(HaveOccurred())
})
Expand All @@ -297,7 +297,7 @@ stages:
kairos:
passwd: "kairos"
`
config, err := pkgConfig.ScanNoLogs(collector.Readers(strings.NewReader(cc)), collector.NoLogs)
config, err := pkgConfig.ScanNoLogs(collector.Readers(strings.NewReader(cc)))
Expect(err).ToNot(HaveOccurred())
Expect(config.CheckForUsers()).To(HaveOccurred())
})
Expand Down
10 changes: 3 additions & 7 deletions pkg/config/spec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -458,19 +458,15 @@ var _ = Describe("Types", Label("types", "config"), func() {
})

It("sets image size to provided value if set in the config and image is smaller", func() {
cfg, err := config.ScanNoLogs(collector.Readers(strings.NewReader("#cloud-config\nupgrade:\n system:\n size: 666\n")),
collector.NoLogs,
)
cfg, err := config.ScanNoLogs(collector.Readers(strings.NewReader("#cloud-config\nupgrade:\n system:\n size: 666\n")))
// Set manually the config collector in the cfg file before unmarshalling the spec
c.Config = cfg.Config
spec, err := config.NewUpgradeSpec(c)
Expect(err).ShouldNot(HaveOccurred())
Expect(spec.Active.Size).To(Equal(uint(666)))
})
It("sets image size to default value if not set in the config and image is smaller", func() {
cfg, err := config.ScanNoLogs(collector.Readers(strings.NewReader("#cloud-config\nupgrade:\n system:\n uri: dir:/\n")),
collector.NoLogs,
)
cfg, err := config.ScanNoLogs(collector.Readers(strings.NewReader("#cloud-config\nupgrade:\n system:\n uri: dir:/\n")))
// Set manually the config collector in the cfg file before unmarshalling the spec
c.Config = cfg.Config
spec, err := config.NewUpgradeSpec(c)
Expand All @@ -479,7 +475,7 @@ var _ = Describe("Types", Label("types", "config"), func() {
})

It("sets image size to the source if default is smaller", func() {
cfg, err := config.ScanNoLogs(collector.Readers(strings.NewReader("#cloud-config\nupgrade:\n system:\n uri: file:/tmp/waka\n")), collector.NoLogs)
cfg, err := config.ScanNoLogs(collector.Readers(strings.NewReader("#cloud-config\nupgrade:\n system:\n uri: file:/tmp/waka\n")))
// Set manually the config collector in the cfg file before unmarshalling the spec
c.Config = cfg.Config
Expect(c.Fs.Mkdir("/tmp", 0777)).ShouldNot(HaveOccurred())
Expand Down

0 comments on commit 06d17b4

Please sign in to comment.