Skip to content

Commit

Permalink
tests(artifact/config): add new tests for the --platform flag
Browse files Browse the repository at this point in the history
Signed-off-by: Aldo Lacuku <[email protected]>
  • Loading branch information
alacuku committed Nov 16, 2023
1 parent fbcb975 commit 3846eea
Showing 1 changed file with 52 additions and 9 deletions.
61 changes: 52 additions & 9 deletions cmd/artifact/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,23 @@ Usage:
falcoctl artifact config [ref] [flags]
Flags:
-h, --help help for config
--plain-http allows interacting with remote registry via plain http requests
-h, --help help for config
--plain-http allows interacting with remote registry via plain http requests
--platform string os and architecture of the artifact in OS/ARCH format (default "linux/amd64")
Global Flags:
--config string config file to be used for falcoctl (default "/etc/falcoctl/falcoctl.yaml")
--log-format string Set formatting for logs (color, text, json) (default "color")
--log-level string Set level for logs (info, warn, debug, trace) (default "info")`
--log-level string Set level for logs (info, warn, debug, trace) (default "info")
`

var _ = Describe("Config", func() {
const (
artifactCmd = "artifact"
configCmd = "config"
plaingHTTP = "--plain-http"
configFlag = "--config"
artifactCmd = "artifact"
configCmd = "config"
plaingHTTP = "--plain-http"
configFlag = "--config"
platformFlag = "--platform"
)

var (
Expand Down Expand Up @@ -93,7 +96,7 @@ var _ = Describe("Config", func() {

It("should match the saved one", func() {
Expect(err).ShouldNot(HaveOccurred())
Expect(string(output.Contents())).ShouldNot(Equal(help))
Expect(string(output.Contents())).Should(Equal(help))
})
})

Expand Down Expand Up @@ -139,6 +142,13 @@ var _ = Describe("Config", func() {

assertFailedBehavior(usage, "ERROR cannot find among the configured indexes, skipping ")
})

When("no manifest for given platform", func() {
BeforeEach(func() {
args = []string{artifactCmd, configCmd, pluginMultiPlatformRef, plaingHTTP, configFlag, configDir, platformFlag, "linux/wrong"}
})
assertFailedBehavior(usage, "ERROR unable to get manifest: unable to find a manifest matching the given platform: linux/wrong")
})
})

Context("success", func() {
Expand All @@ -163,6 +173,39 @@ var _ = Describe("Config", func() {
Expect(output).Should(gbytes.Say(regexp.QuoteMeta(`{"dependencies":[{"name":"dep1","version":"1.2.3"},{"name":"dep2","version":"2.3.1"}]}`)))
})
})
})

When("no platform flag", func() {
BeforeEach(func() {
args = []string{artifactCmd, configCmd, pluginMultiPlatformRef, plaingHTTP, configFlag, configDir}
})

It("should success getting the platform where tests are running", func() {
Expect(err).ShouldNot(HaveOccurred())
Expect(output).Should(gbytes.Say(regexp.QuoteMeta(`{"dependencies":[{"name":"my-dep","version":"1.2.3","alternatives":[{"name":"my-alt-dep","version":"`)))

Check failure on line 184 in cmd/artifact/config/config_test.go

View workflow job for this annotation

GitHub Actions / Lint golang files

line is 159 characters (lll)
})
})

When("with valid platform", func() {
BeforeEach(func() {
args = []string{artifactCmd, configCmd, pluginMultiPlatformRef, plaingHTTP, configFlag, configDir, platformFlag, testPluginPlatform3}
})

It("should success", func() {
Expect(err).ShouldNot(HaveOccurred())
Expect(output).Should(gbytes.Say(regexp.QuoteMeta(`{"dependencies":[{"name":"my-dep","version":"1.2.3","alternatives":[{"name":"my-alt-dep","version":"`)))

Check failure on line 195 in cmd/artifact/config/config_test.go

View workflow job for this annotation

GitHub Actions / Lint golang files

line is 159 characters (lll)
})
})

When("with non existing platform for artifacts without platforms", func() {
BeforeEach(func() {
args = []string{artifactCmd, configCmd, rulesRef, plaingHTTP, configFlag, configDir, platformFlag, testPluginPlatform3}
})

It("should success", func() {
Expect(err).ShouldNot(HaveOccurred())
Expect(output).Should(gbytes.Say(regexp.QuoteMeta(`{"dependencies":[{"name":"dep1","version":"1.2.3"},{"name":"dep2","version":"2.3.1"}]}`)))
})
})

})
})

0 comments on commit 3846eea

Please sign in to comment.