forked from openservicemesh/osm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnamespace_test.go
38 lines (28 loc) · 1.13 KB
/
namespace_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package debugger
import (
"net/http/httptest"
"testing"
"github.com/openservicemesh/osm/pkg/k8s"
"github.com/golang/mock/gomock"
tassert "github.com/stretchr/testify/assert"
"github.com/openservicemesh/osm/pkg/tests"
)
// Tests getMonitoredNamespaces through HTTP handler returns a the list of monitored namespaces
func TestMonitoredNamespaceHandler(t *testing.T) {
assert := tassert.New(t)
mockKubeController := k8s.NewMockController(gomock.NewController(t))
ds := DebugConfig{
kubeController: mockKubeController,
}
monitoredNamespacesHandler := ds.getMonitoredNamespacesHandler()
uniqueNs := tests.GetUnique([]string{
tests.BookbuyerService.Namespace, // default
tests.BookstoreV1Service.Namespace, // default
})
mockKubeController.EXPECT().ListMonitoredNamespaces().Return(uniqueNs, nil)
responseRecorder := httptest.NewRecorder()
monitoredNamespacesHandler.ServeHTTP(responseRecorder, nil)
actualResponseBody := responseRecorder.Body.String()
expectedResponseBody := `{"namespaces":["default"]}`
assert.Equal(expectedResponseBody, actualResponseBody, "Actual value did not match expectations:\n%s", actualResponseBody)
}