Skip to content

Commit 3954332

Browse files
Merge pull request #887 from marioferh/ut_must_gather
must-gather gather-sysinfo unit tests
2 parents 6599055 + f79e246 commit 3954332

File tree

3 files changed

+107
-1
lines changed

3 files changed

+107
-1
lines changed

hack/unittests.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ FUNC_FILE="${OUTDIR}/coverage.txt"
1010
HTML_FILE="${OUTDIR}/coverage.html"
1111

1212
echo "running unittests with coverage"
13-
GOFLAGS=-mod=vendor go test -race -covermode=atomic -coverprofile="${COVER_FILE}" -v ./pkg/... ./controllers/... ./api/...
13+
GOFLAGS=-mod=vendor go test -race -covermode=atomic -coverprofile="${COVER_FILE}" -v ./pkg/... ./controllers/... ./api/... ./tools/...
1414

1515
if [[ -n "${DRONE}" ]]; then
1616

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package main
2+
3+
import (
4+
"testing"
5+
6+
. "github.com/onsi/ginkgo"
7+
. "github.com/onsi/gomega"
8+
)
9+
10+
func TestComponetsUtils(t *testing.T) {
11+
RegisterFailHandler(Fail)
12+
RunSpecs(t, "Tuned Suite")
13+
}
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
package main
2+
3+
import (
4+
"io/ioutil"
5+
6+
. "github.com/onsi/ginkgo"
7+
. "github.com/onsi/gomega"
8+
"github.com/openshift-kni/debug-tools/pkg/knit/cmd"
9+
"github.com/spf13/cobra"
10+
)
11+
12+
var kniEntries = []string{
13+
"/host/proc/cmdline",
14+
"/host/proc/interrupts",
15+
"/host/proc/irq/default_smp_affinity",
16+
"/host/proc/irq/*/*affinity_list",
17+
"/host/proc/irq/*/node",
18+
"/host/proc/softirqs",
19+
"/host/sys/devices/system/cpu/smt/active",
20+
"/host/proc/sys/kernel/sched_domain/cpu*/domain*/flags",
21+
"/host/sys/devices/system/cpu/offline",
22+
"/host/sys/class/dmi/id/bios*",
23+
"/host/sys/class/dmi/id/product_family",
24+
"/host/sys/class/dmi/id/product_name",
25+
"/host/sys/class/dmi/id/product_sku",
26+
"/host/sys/class/dmi/id/product_version",
27+
}
28+
29+
var snapshotEntries = []string{"/host/proc/cmdline", "/host/sys/devices/system/node/online"}
30+
31+
var expectedEntries = []string{
32+
"/host/proc/cmdline",
33+
"/host/proc/interrupts",
34+
"/host/proc/irq/default_smp_affinity",
35+
"/host/proc/irq/*/*affinity_list",
36+
"/host/proc/irq/*/node",
37+
"/host/proc/softirqs",
38+
"/host/sys/devices/system/cpu/smt/active",
39+
"/host/proc/sys/kernel/sched_domain/cpu*/domain*/flags",
40+
"/host/sys/devices/system/cpu/offline",
41+
"/host/sys/class/dmi/id/bios*",
42+
"/host/sys/class/dmi/id/product_family",
43+
"/host/sys/class/dmi/id/product_name",
44+
"/host/sys/class/dmi/id/product_sku",
45+
"/host/sys/class/dmi/id/product_version",
46+
"/host/sys/devices/system/node/online",
47+
}
48+
49+
var _ = Describe("Components utils", func() {
50+
Context("gather sysinfo", func() {
51+
It("collect machine info test", func() {
52+
//Check if collect machine info file is created correctly
53+
knitOpts := &cmd.KnitOptions{}
54+
knitOpts.SysFSRoot = "/host/sys"
55+
56+
err := collectMachineinfo(knitOpts, "./output")
57+
Expect(err).ToNot(HaveOccurred())
58+
59+
content, err := ioutil.ReadFile("./output")
60+
Expect(err).ToNot(HaveOccurred())
61+
62+
output := string(content)
63+
Expect(output).To(ContainSubstring("timestamp"))
64+
})
65+
66+
It("chroot file spec test", func() {
67+
entries := chrootFileSpecs(kniExpectedCloneContent(), "/host")
68+
Expect(entries).To(Equal(kniEntries))
69+
})
70+
71+
It("no duplicates entries test", func() {
72+
resultEntries := dedupExpectedContent(kniEntries, snapshotEntries)
73+
Expect(len(expectedEntries)).To(Equal(len(resultEntries)))
74+
})
75+
76+
It("makeSnapshot test", func() {
77+
knitOpts := &cmd.KnitOptions{}
78+
79+
opts := &snapshotOptions{}
80+
cmd := &cobra.Command{}
81+
args := []string{}
82+
83+
err := makeSnapshot(cmd, knitOpts, opts, args)
84+
Expect(err).To(HaveOccurred(), "--output is requidred")
85+
86+
opts.output = "testSnapshot.tgz"
87+
err = makeSnapshot(cmd, knitOpts, opts, args)
88+
Expect(err).ToNot(HaveOccurred())
89+
90+
Expect(opts.output).To(BeAnExistingFile())
91+
})
92+
})
93+
})

0 commit comments

Comments
 (0)