Skip to content

Commit 3846eea

Browse files
committed
tests(artifact/config): add new tests for the --platform flag
Signed-off-by: Aldo Lacuku <[email protected]>
1 parent fbcb975 commit 3846eea

File tree

1 file changed

+52
-9
lines changed

1 file changed

+52
-9
lines changed

cmd/artifact/config/config_test.go

Lines changed: 52 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,20 +44,23 @@ Usage:
4444
falcoctl artifact config [ref] [flags]
4545
4646
Flags:
47-
-h, --help help for config
48-
--plain-http allows interacting with remote registry via plain http requests
47+
-h, --help help for config
48+
--plain-http allows interacting with remote registry via plain http requests
49+
--platform string os and architecture of the artifact in OS/ARCH format (default "linux/amd64")
4950
5051
Global Flags:
5152
--config string config file to be used for falcoctl (default "/etc/falcoctl/falcoctl.yaml")
5253
--log-format string Set formatting for logs (color, text, json) (default "color")
53-
--log-level string Set level for logs (info, warn, debug, trace) (default "info")`
54+
--log-level string Set level for logs (info, warn, debug, trace) (default "info")
55+
`
5456

5557
var _ = Describe("Config", func() {
5658
const (
57-
artifactCmd = "artifact"
58-
configCmd = "config"
59-
plaingHTTP = "--plain-http"
60-
configFlag = "--config"
59+
artifactCmd = "artifact"
60+
configCmd = "config"
61+
plaingHTTP = "--plain-http"
62+
configFlag = "--config"
63+
platformFlag = "--platform"
6164
)
6265

6366
var (
@@ -93,7 +96,7 @@ var _ = Describe("Config", func() {
9396

9497
It("should match the saved one", func() {
9598
Expect(err).ShouldNot(HaveOccurred())
96-
Expect(string(output.Contents())).ShouldNot(Equal(help))
99+
Expect(string(output.Contents())).Should(Equal(help))
97100
})
98101
})
99102

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

140143
assertFailedBehavior(usage, "ERROR cannot find among the configured indexes, skipping ")
141144
})
145+
146+
When("no manifest for given platform", func() {
147+
BeforeEach(func() {
148+
args = []string{artifactCmd, configCmd, pluginMultiPlatformRef, plaingHTTP, configFlag, configDir, platformFlag, "linux/wrong"}
149+
})
150+
assertFailedBehavior(usage, "ERROR unable to get manifest: unable to find a manifest matching the given platform: linux/wrong")
151+
})
142152
})
143153

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

177+
When("no platform flag", func() {
178+
BeforeEach(func() {
179+
args = []string{artifactCmd, configCmd, pluginMultiPlatformRef, plaingHTTP, configFlag, configDir}
180+
})
181+
182+
It("should success getting the platform where tests are running", func() {
183+
Expect(err).ShouldNot(HaveOccurred())
184+
Expect(output).Should(gbytes.Say(regexp.QuoteMeta(`{"dependencies":[{"name":"my-dep","version":"1.2.3","alternatives":[{"name":"my-alt-dep","version":"`)))
185+
})
186+
})
187+
188+
When("with valid platform", func() {
189+
BeforeEach(func() {
190+
args = []string{artifactCmd, configCmd, pluginMultiPlatformRef, plaingHTTP, configFlag, configDir, platformFlag, testPluginPlatform3}
191+
})
192+
193+
It("should success", func() {
194+
Expect(err).ShouldNot(HaveOccurred())
195+
Expect(output).Should(gbytes.Say(regexp.QuoteMeta(`{"dependencies":[{"name":"my-dep","version":"1.2.3","alternatives":[{"name":"my-alt-dep","version":"`)))
196+
})
197+
})
198+
199+
When("with non existing platform for artifacts without platforms", func() {
200+
BeforeEach(func() {
201+
args = []string{artifactCmd, configCmd, rulesRef, plaingHTTP, configFlag, configDir, platformFlag, testPluginPlatform3}
202+
})
203+
204+
It("should success", func() {
205+
Expect(err).ShouldNot(HaveOccurred())
206+
Expect(output).Should(gbytes.Say(regexp.QuoteMeta(`{"dependencies":[{"name":"dep1","version":"1.2.3"},{"name":"dep2","version":"2.3.1"}]}`)))
207+
})
208+
})
209+
210+
})
168211
})

0 commit comments

Comments
 (0)