From ec8f9c05c3cc632501e0eba5f3f5fd458465102b Mon Sep 17 00:00:00 2001 From: Diretnan Domnan Date: Mon, 21 Mar 2022 17:22:20 +0100 Subject: [PATCH] [fix] skip ssh tests for non-linux environments on Actions --- driver/ssh_test.go | 16 ++++++++++++++ inspector/disk_test.go | 13 ++++++++++++ inspector/meminfo.go | 6 +++++- integration/integration_test.go | 28 +++++++++++++++++++++++++ integration/integration_unix_test.go | 3 +++ integration/integration_windows_test.go | 2 +- 6 files changed, 66 insertions(+), 2 deletions(-) diff --git a/driver/ssh_test.go b/driver/ssh_test.go index c155d33..ead0326 100644 --- a/driver/ssh_test.go +++ b/driver/ssh_test.go @@ -4,12 +4,22 @@ import ( "fmt" "os" "path/filepath" + "runtime" "strings" "testing" "github.com/bisohns/saido/config" ) +func SkipNonLinuxOnCI() bool { + if os.Getenv("GITHUB_ACTIONS") == "true" { + if runtime.GOOS != "linux" { + return true + } + } + return false +} + func NewSSHForTest() Driver { workingDir, _ := os.Getwd() workingDir = filepath.Dir(workingDir) @@ -27,6 +37,9 @@ func NewSSHForTest() Driver { } func TestSSHRunCommand(t *testing.T) { + if SkipNonLinuxOnCI() { + return + } d := NewSSHForTest() output, err := d.RunCommand(`ps -A`) if err != nil || !strings.Contains(output, "PID") { @@ -35,6 +48,9 @@ func TestSSHRunCommand(t *testing.T) { } func TestSSHSystemDetails(t *testing.T) { + if SkipNonLinuxOnCI() { + return + } d := NewSSHForTest() details := d.GetDetails() if !details.IsLinux { diff --git a/inspector/disk_test.go b/inspector/disk_test.go index ee3c9a4..0373528 100644 --- a/inspector/disk_test.go +++ b/inspector/disk_test.go @@ -6,12 +6,22 @@ import ( "fmt" "os" "path/filepath" + "runtime" "testing" "github.com/bisohns/saido/config" "github.com/bisohns/saido/driver" ) +func SkipNonLinuxOnCI() bool { + if os.Getenv("GITHUB_ACTIONS") == "true" { + if runtime.GOOS != "linux" { + return true + } + } + return false +} + func NewSSHForTest() driver.Driver { workingDir, _ := os.Getwd() workingDir = filepath.Dir(workingDir) @@ -39,6 +49,9 @@ func TestDFOnLocal(t *testing.T) { } func TestDFOnSSH(t *testing.T) { + if SkipNonLinuxOnCI() { + return + } driver := NewSSHForTest() d, _ := NewDF(&driver) d.Execute() diff --git a/inspector/meminfo.go b/inspector/meminfo.go index 29bf3b1..3c4ab32 100644 --- a/inspector/meminfo.go +++ b/inspector/meminfo.go @@ -224,8 +224,12 @@ func (i *MemInfoWin) Parse(output string) { freeVirt, _ = strconv.ParseInt(fields[fieldLen-1], 0, 64) case 5: // Last line is L2 and L3 CacheSize + // sometimes L3 is not shown like on CI + var l3 int64 = 0 l2, _ := strconv.ParseInt(fields[0], 0, 64) - l3, _ := strconv.ParseInt(fields[1], 0, 64) + if fieldLen > 1 { + l3, _ = strconv.ParseInt(fields[1], 0, 64) + } cachesize = l2 + l3 } diff --git a/integration/integration_test.go b/integration/integration_test.go index 3e03163..f290bc7 100644 --- a/integration/integration_test.go +++ b/integration/integration_test.go @@ -4,6 +4,7 @@ import ( "fmt" "os" "path/filepath" + "runtime" "strings" "testing" @@ -12,6 +13,15 @@ import ( "github.com/bisohns/saido/inspector" ) +func SkipNonLinuxOnCI() bool { + if os.Getenv("GITHUB_ACTIONS") == "true" { + if runtime.GOOS != "linux" { + return true + } + } + return false +} + func NewWebForTest() driver.Driver { return &driver.Web{ URL: "https://duckduckgo.com", @@ -36,6 +46,9 @@ func NewSSHForTest() driver.Driver { } func TestDFonSSH(t *testing.T) { + if SkipNonLinuxOnCI() { + return + } d := NewSSHForTest() i, _ := inspector.Init(`disk`, &d) i.Execute() @@ -46,6 +59,9 @@ func TestDFonSSH(t *testing.T) { } func TestMemInfoonSSH(t *testing.T) { + if SkipNonLinuxOnCI() { + return + } d := NewSSHForTest() i, _ := inspector.NewMemInfo(&d) i.Execute() @@ -79,6 +95,9 @@ func TestResponseTimeonWeb(t *testing.T) { } func TestProcessonSSH(t *testing.T) { + if SkipNonLinuxOnCI() { + return + } d := NewSSHForTest() i, _ := inspector.NewProcess(&d) i.Execute() @@ -97,6 +116,9 @@ func TestProcessonSSH(t *testing.T) { } func TestCustomonSSH(t *testing.T) { + if SkipNonLinuxOnCI() { + return + } d := NewSSHForTest() // set vars dfConcrete, _ := d.(*driver.SSH) @@ -113,6 +135,9 @@ func TestCustomonSSH(t *testing.T) { } func TestLoadAvgonSSH(t *testing.T) { + if SkipNonLinuxOnCI() { + return + } d := NewSSHForTest() i, _ := inspector.NewLoadAvg(&d) i.Execute() @@ -139,6 +164,9 @@ func TestCustomonWeb(t *testing.T) { } func TestUptimeonSSH(t *testing.T) { + if SkipNonLinuxOnCI() { + return + } d := NewSSHForTest() i, _ := inspector.NewUptime(&d) i.Execute() diff --git a/integration/integration_unix_test.go b/integration/integration_unix_test.go index 6a8dad5..7d6a5ac 100644 --- a/integration/integration_unix_test.go +++ b/integration/integration_unix_test.go @@ -49,6 +49,9 @@ func TestMemInfoonLocal(t *testing.T) { } func TestDockerStatsonLocal(t *testing.T) { + if SkipNonLinuxOnCI() { + return + } d := NewLocalForTest() i, _ := inspector.NewDockerStats(&d) i.Execute() diff --git a/integration/integration_windows_test.go b/integration/integration_windows_test.go index 2cb7cd9..5d8ca68 100644 --- a/integration/integration_windows_test.go +++ b/integration/integration_windows_test.go @@ -61,7 +61,7 @@ func TestLoadAverageonLocal(t *testing.T) { i.Execute() iConcrete, ok := i.(*inspector.LoadAvgWin) if ok { - if iConcrete.Values.Load1M == 0 { + if iConcrete.Values.Load1M == 0 && !SkipNonLinuxOnCI() { t.Error("Expected load on windows to be > 0") } }