rmmagent/agent/agent_linux_test.go

45 lines
675 B
Go
Raw Normal View History

2022-06-16 01:26:10 +00:00
package agent
import (
"bytes"
"io"
"os"
"testing"
)
func captureOutput(f func()) string {
old := os.Stdout
r, w, _ := os.Pipe()
os.Stdout = w
f()
w.Close()
os.Stdout = old
var buf bytes.Buffer
io.Copy(&buf, r)
return buf.String()
}
func TestShowStatus(t *testing.T) {
var (
version = "2.0.4"
)
output := captureOutput(func() {
ShowStatus(version)
})
if output != (version + "\n") {
t.Errorf("ShowStatus output not equal to version defined.")
}
}
func TestOsString(t *testing.T) {
a := New(lg, version)
osString := a.osString()
if osString == "" {
t.Errorf("Could not get OS String")
} else {
t.Logf("Got OS String: %s", osString)
}
}