gstat/args/args_test.go

97 lines
1.8 KiB
Go
Raw Permalink Normal View History

2020-05-09 14:30:54 +02:00
package args_test
2020-05-03 16:24:05 +02:00
2020-05-09 14:30:54 +02:00
import (
"testing"
2020-05-03 16:24:05 +02:00
2020-05-09 14:30:54 +02:00
"github.com/hamburghammer/gstat/args"
)
func TestValidate(t *testing.T) {
2020-05-28 22:17:38 +02:00
2020-05-09 14:30:54 +02:00
t.Run("should error if args are empty", func(t *testing.T) {
arguments := args.Arguments{}
got := arguments.Validate()
want := "Arguments are empty"
2020-05-28 22:17:38 +02:00
if len(got) != 1 {
t.Errorf("An error was expected but got '%d' errors", len(got))
2020-05-28 22:17:38 +02:00
}
2020-05-30 15:02:46 +02:00
gotValidationError := got[0]
2020-05-28 22:17:38 +02:00
2020-05-30 15:02:46 +02:00
if gotValidationError.Message != want {
t.Errorf("got error message: '%s' \n want message: '%s'", gotValidationError.Message, want)
}
})
t.Run("should have url validation error", func(t *testing.T) {
arguments := args.Arguments{}
arguments.Health = "example.com"
got := arguments.Validate()
want := "The URI does not looks like schema://provider"
if len(got) != 1 {
t.Errorf("An error was expected but got '%d' errors", len(got))
}
2020-05-30 15:02:46 +02:00
gotValidationError := got[0]
2020-05-30 15:02:46 +02:00
if gotValidationError.Message != want {
t.Errorf("got error message: '%s' \n want message: '%s'", gotValidationError.Message, want)
}
})
}
func TestEquals(t *testing.T) {
defaultArgs := args.Arguments{}
t.Run("should check CPU", func(t *testing.T) {
args := args.Arguments{CPU: true}
if args.Equals(defaultArgs) {
t.Fail()
}
})
t.Run("should check Mem", func(t *testing.T) {
args := args.Arguments{Mem: true}
if args.Equals(defaultArgs) {
t.Fail()
}
})
t.Run("should check Disk", func(t *testing.T) {
args := args.Arguments{Disk: true}
if args.Equals(defaultArgs) {
t.Fail()
}
})
t.Run("should check Processes", func(t *testing.T) {
args := args.Arguments{Processes: true}
if args.Equals(defaultArgs) {
t.Fail()
}
})
t.Run("should check Health", func(t *testing.T) {
args := args.Arguments{Health: "http://example.com"}
if args.Equals(defaultArgs) {
t.Fail()
2020-05-28 22:17:38 +02:00
}
2020-05-09 14:30:54 +02:00
})
2020-05-03 16:24:05 +02:00
}