testing setup

This commit is contained in:
redanthrax 2022-06-15 18:26:10 -07:00
parent 7457bf0b93
commit 7c46970b67
7 changed files with 109 additions and 59 deletions

View file

@ -1,35 +1,20 @@
package agent
import (
"bytes"
"io"
"os"
"testing"
"github.com/sirupsen/logrus"
)
func captureOutput(f func()) string {
old := os.Stdout
r, w, _ := os.Pipe()
os.Stdout = w
f()
w.Close()
os.Stdout = old
var (
version = "2.0.4"
lg = logrus.New()
)
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 TestAgentId(t *testing.T) {
a := New(lg, version)
if a.AgentID == "" {
t.Error("AgentID not set")
} else {
t.Logf("AgentID: %s", a.AgentID)
}
}