-
Manuel Kieweg authoredManuel Kieweg authored
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
controller_test.go 1.41 KiB
package gosdn
import (
"context"
"net/http"
"reflect"
"testing"
"time"
)
func TestRun(t *testing.T) {
if testing.Short() {
t.Skip("this test is executed separately")
}
type args struct {
request string
}
tests := []struct {
name string
args args
want interface{}
}{
{
name: "liveliness indicator",
args: args{request: apiEndpoint + "/livez"},
want: http.StatusOK,
},
{
name: "readyness indicator",
args: args{request: apiEndpoint + "/readyz"},
want: http.StatusOK,
},
}
ctx, cancel := context.WithCancel(context.Background())
go func() {
if err := Run(ctx); err != nil {
t.Errorf("Run() error = %v", err)
}
}()
time.Sleep(time.Second)
t.Run("Controller Start HTTP API", func(t *testing.T) {
got, err := http.Get(tests[0].args.request)
if err != nil {
t.Error(err)
return
}
if !reflect.DeepEqual(got.StatusCode, tests[0].want) {
t.Errorf("livez got: %v, want %v", got.StatusCode, tests[0].want)
}
got, err = http.Get(tests[1].args.request)
if err != nil {
t.Error(err)
return
}
if !reflect.DeepEqual(got.StatusCode, tests[1].want) {
t.Errorf("readyz got: %v, want %v", got.StatusCode, tests[1].want)
}
got, err = http.Get(tests[2].args.request)
if err != nil {
t.Error(err)
return
}
if !reflect.DeepEqual(got.StatusCode, tests[2].want) {
t.Errorf("api init got: %v, want %v", got.StatusCode, tests[2].want)
}
})
cancel()
}