Skip to content

Commit

Permalink
test: get complaince report via cli
Browse files Browse the repository at this point in the history
Signed-off-by: chenk <hen.keinan@gmail.com>
  • Loading branch information
chen-keinan committed Mar 20, 2022
1 parent b4ce0c2 commit c85a7f2
Showing 1 changed file with 65 additions and 0 deletions.
65 changes: 65 additions & 0 deletions itest/starboard/starboard_cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1262,6 +1262,71 @@ var _ = Describe("Starboard CLI", func() {
})
})

Describe("Command get nsa compliance report", func() {

It("should create nsa compliance report", func() {
// create ciskubebenchreports
err := cmd.Run(versionInfo, []string{
"starboard",
"scan", "ciskubebenchreports",
"-v", starboardCLILogLevel,
}, GinkgoWriter, GinkgoWriter)
Expect(err).ToNot(HaveOccurred())

// create configauditreports
ctx := context.TODO()
object := helper.NewPod().
WithRandomName("nginx-polaris").
WithNamespace(testNamespace.Name).
WithContainer("nginx-container", "nginx:1.16").
Build()
err = kubeClient.Create(ctx, object)
Expect(err).ToNot(HaveOccurred())

err = cmd.Run(versionInfo, []string{
"starboard",
"scan", "configauditreports", "pod" + "/" + object.GetName(),
"--namespace", object.GetNamespace(),
"-v", starboardCLILogLevel,
}, GinkgoWriter, GinkgoWriter)
Expect(err).ToNot(HaveOccurred())

// get cluster compliance report
stdout := NewBuffer()
stderr := NewBuffer()
err = cmd.Run(versionInfo, []string{
"starboard", "get", "clustercompliancereports",
"nsa", "--output", "yaml",
"-v", starboardCLILogLevel,
}, stdout, stderr)
Expect(err).ToNot(HaveOccurred())

var ccr v1alpha1.ClusterComplianceReport
err = yaml.Unmarshal(stdout.Contents(), &ccr)
Expect(err).ToNot(HaveOccurred())
Expect(ccr.Status.Summary.PassCount == 12).To(BeTrue())
Expect(ccr.Status.Summary.FailCount == 6).To(BeTrue())
Expect(len(ccr.Status.ControlChecks) == 27).To(BeTrue())

// get cluster compliance detail report
stdout = NewBuffer()
stderr = NewBuffer()
err = cmd.Run(versionInfo, []string{
"starboard", "get", "clustercompliancereports",
"nsa", "--output", "yaml", "--detail",
"-v", starboardCLILogLevel,
}, stdout, stderr)
Expect(err).ToNot(HaveOccurred())

var ccdr v1alpha1.ClusterComplianceDetailReport
err = yaml.Unmarshal(stdout.Contents(), &ccdr)
Expect(err).ToNot(HaveOccurred())
Expect(ccdr.Report.Summary.PassCount == 12).To(BeTrue())
Expect(ccdr.Report.Summary.FailCount == 6).To(BeTrue())
Expect(len(ccdr.Report.ControlChecks) == 6).To(BeTrue())
})
})

Describe("Command scan kubehunterreports", func() {

BeforeEach(func() {
Expand Down

0 comments on commit c85a7f2

Please sign in to comment.