diff --git a/support/support.go b/support/support.go index 2ff28783..62cf369d 100644 --- a/support/support.go +++ b/support/support.go @@ -235,6 +235,10 @@ type Check struct { // ////////////////////////////////////////////////////////////////////////////////// // +var buildInfoProvider = debug.ReadBuildInfo + +// ////////////////////////////////////////////////////////////////////////////////// // + // Collect collects basic info about system func Collect(app, ver string) *Info { bin, _ := os.Executable() @@ -435,7 +439,7 @@ func (i *Info) appendBuildInfo() { bin, _ := os.Executable() binSHA := hash.FileHash(bin) - info, ok := debug.ReadBuildInfo() + info, ok := buildInfoProvider() if ok { for _, s := range info.Settings { diff --git a/support/support_test.go b/support/support_test.go index 07956dc7..c80fae02 100644 --- a/support/support_test.go +++ b/support/support_test.go @@ -9,6 +9,7 @@ package support import ( "os" + "runtime/debug" "testing" "github.com/essentialkaos/ek/v13/fmtc" @@ -51,6 +52,8 @@ require ( func (s *SupportSuite) TestCollect(c *C) { i := Collect("test", "1.2.3") + c.Assert(i, NotNil) + os.Setenv("SUPPORT_VAR", "123") chks := []Check{ @@ -85,7 +88,29 @@ func (s *SupportSuite) TestCollect(c *C) { App{}, } - c.Assert(i, NotNil) + resources := &ResourcesInfo{ + CPU: []CPUInfo{ + { + Model: "Virtual", + Threads: 4, + Cores: 2, + }, + }, + MemTotal: 8 * 1024 * 1024, + MemFree: 6 * 1024 * 1024, + MemUsed: 2 * 1024 * 1024, + SwapTotal: 2 * 1024 * 1024, + SwapFree: 1 * 1024 * 1024, + SwapUsed: 1 * 1024 * 1024, + } + + params := []KernelParam{ + {"fs.inotify.max_user_watches", "27024"}, + {"kernel.random.boot_id", "3cfe3c24-c698-42fc-b232-af5345f828f7"}, + } + + i.Build.CGO = true + c.Assert(i.WithDeps(deps), NotNil) c.Assert(i.WithRevision(""), NotNil) c.Assert(i.WithRevision("1234567"), NotNil) @@ -96,6 +121,14 @@ func (s *SupportSuite) TestCollect(c *C) { c.Assert(i.WithEnvVars("", "SUPPORT_VAR", "TERM", "CI"), NotNil) c.Assert(i.WithNetwork(&NetworkInfo{PublicIP: "192.168.1.1", Hostname: "test.loc"}), NotNil) c.Assert(i.WithFS([]FSInfo{FSInfo{}, FSInfo{"/", "/dev/vda1", "ext4", 1000, 10000}}), NotNil) + c.Assert(i.WithResources(resources), NotNil) + c.Assert(i.WithKernel(params), NotNil) + + i.Print() + + i.Resources.SwapTotal = 0 + i.Resources.SwapFree = 0 + i.Resources.SwapUsed = 0 i.Print() @@ -109,6 +142,8 @@ func (s *SupportSuite) TestCollect(c *C) { i.Network = nil i.FS = nil i.Deps = nil + i.Resources = nil + i.Kernel = nil i.Print() @@ -136,6 +171,8 @@ func (s *SupportSuite) TestNil(c *C) { c.Assert(i.WithEnvVars(""), IsNil) c.Assert(i.WithNetwork(nil), IsNil) c.Assert(i.WithFS(nil), IsNil) + c.Assert(i.WithResources(nil), IsNil) + c.Assert(i.WithKernel(nil), IsNil) c.Assert(func() { i.Print() }, NotPanics) } @@ -163,3 +200,20 @@ func (s *SupportSuite) TestSizeCalc(c *C) { FSInfo{Device: "/dev/sda1"}, FSInfo{Device: "/dev/test/test"}, FSInfo{Device: "/dev"}, }), Equals, 14) } + +func (s *SupportSuite) TestBuildInfo(c *C) { + buildInfoProvider = func() (*debug.BuildInfo, bool) { + return &debug.BuildInfo{ + Settings: []debug.BuildSetting{ + {"CGO_ENABLED", "1"}, + {"vcs.revision", "8b6e70d9dce17f98595dd364bd6f699f8608b46e"}, + }, + }, true + } + + i := Collect("test", "1.2.3") + + c.Assert(i, NotNil) + + buildInfoProvider = debug.ReadBuildInfo +}