Skip to content

Commit

Permalink
[fix] skip ssh tests for non-linux environments on Actions
Browse files Browse the repository at this point in the history
  • Loading branch information
deven96 committed Mar 21, 2022
1 parent 36a4917 commit ec8f9c0
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 2 deletions.
16 changes: 16 additions & 0 deletions driver/ssh_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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") {
Expand All @@ -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 {
Expand Down
13 changes: 13 additions & 0 deletions inspector/disk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -39,6 +49,9 @@ func TestDFOnLocal(t *testing.T) {
}

func TestDFOnSSH(t *testing.T) {
if SkipNonLinuxOnCI() {
return
}
driver := NewSSHForTest()
d, _ := NewDF(&driver)
d.Execute()
Expand Down
6 changes: 5 additions & 1 deletion inspector/meminfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

}
Expand Down
28 changes: 28 additions & 0 deletions integration/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"os"
"path/filepath"
"runtime"
"strings"
"testing"

Expand All @@ -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",
Expand All @@ -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()
Expand All @@ -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()
Expand Down Expand Up @@ -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()
Expand All @@ -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)
Expand All @@ -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()
Expand All @@ -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()
Expand Down
3 changes: 3 additions & 0 deletions integration/integration_unix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion integration/integration_windows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}
Expand Down

0 comments on commit ec8f9c0

Please sign in to comment.