1
0
Fork 0
mirror of https://github.com/eosswedenorg/antelope-api-healthcheck synced 2026-06-17 04:50:02 +02:00

Adding src/api/debug_test.go

This commit is contained in:
Henrik Hautakoski 2022-10-03 16:32:17 +02:00
parent 0349999540
commit bc6f857c1e
No known key found for this signature in database
GPG key ID: 608414D93E862CCD

56
src/api/debug_test.go Normal file
View file

@ -0,0 +1,56 @@
package api
import (
"reflect"
"testing"
"github.com/stretchr/testify/assert"
"github.com/eosswedenorg-go/haproxy/agentcheck"
)
func TestNewDebugApi(t *testing.T) {
type args struct {
response string
}
tests := []struct {
name string
args args
want DebugApi
}{
{"Up", args{"up"}, DebugApi{response: agentcheck.NewStatusResponse(agentcheck.Up)}},
{"Down", args{"down"}, DebugApi{response: agentcheck.NewStatusResponse("down")}},
{"DownMessage", args{"down#some message"}, DebugApi{response: agentcheck.NewStatusMessageResponse(agentcheck.Down, "some message")}},
{"Ready", args{"ready"}, DebugApi{response: agentcheck.NewStatusResponse(agentcheck.Ready)}},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := NewDebugApi(tt.args.response); !reflect.DeepEqual(got, tt.want) {
t.Errorf("NewDebugApi() = %v, want %v", got, tt.want)
}
})
}
}
func TestDebugApi_LogInfo(t *testing.T) {
expected := LogParams{"type", "Debug", "response", "up"}
api := DebugApi{
response: agentcheck.NewStatusResponse(agentcheck.Up),
}
assert.Equal(t, api.LogInfo(), expected)
}
func TestDebugApi_Call(t *testing.T) {
expected := agentcheck.NewStatusMessageResponse(agentcheck.Stopped, "message")
api := DebugApi{
response: expected,
}
response, msg := api.Call()
assert.Equal(t, response, expected)
assert.Equal(t, msg, "")
}