|
| 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