Skip to content
Snippets Groups Projects
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
controller_test.go 1.06 KiB
package nucleus

import (
	"context"
	"net/http"
	"testing"
	"time"
)

func TestRun(t *testing.T) {
	type args struct {
		request string
	}
	tests := []struct {
		name    string
		args    args
		want    interface{}
		wantErr bool
	}{
		{
			name:    "liveliness indicator",
			args:    args{request: apiEndpoint + "/livez"},
			want:    &http.Response{StatusCode: http.StatusOK},
			wantErr: false,
		},
		{
			name:    "readyness indicator",
			args:    args{request: apiEndpoint + "/readyz"},
			want:    &http.Response{StatusCode: http.StatusOK},
			wantErr: false,
		},
		{
			name:    "init",
			args:    args{request: apiEndpoint + "/api?q=init"},
			want:    &http.Response{StatusCode: http.StatusOK},
			wantErr: false,
		},
	}
	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			ctx, cancel := context.WithCancel(context.Background())
			go func() {
				if err := Run(ctx); (err != nil) != tt.wantErr {
					t.Errorf("Run() error = %v, wantErr %v", err, tt.wantErr)
				}
			}()
			time.Sleep(time.Second)
			cancel()
			time.Sleep(time.Second)
		})
	}
}