-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathcluster_test.go
46 lines (36 loc) · 1.14 KB
/
cluster_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
39
40
41
42
43
44
45
46
package api
import (
"net/http"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"go.uber.org/zap"
"github.com/spinup-host/spinup/config"
"github.com/spinup-host/spinup/internal/metastore"
"github.com/spinup-host/spinup/testutils"
)
// cluster tests contain unit tests for cluster-related API endpoints.
func TestListCluster(t *testing.T) {
svc := &mockClusterService{}
testClusters := []metastore.ClusterInfo{
{
ID: 1,
Name: "test_cluster_1",
ClusterID: "test_cluster_1",
},
}
svc.On("ListClusters", mock.Anything).Return(testClusters, nil)
loggerConfig := zap.NewProductionConfig()
loggerConfig.OutputPaths = []string{"stdout"}
logger, err := loggerConfig.Build()
assert.NoError(t, err)
appConfig := testutils.GetConfig()
ch, err := NewClusterHandler(svc, appConfig, logger)
server := createServer(ch)
t.Run("fails for unauthenticated users", func(t *testing.T) {
listRequest, err := http.NewRequest(http.MethodGet, "/listcluster", nil)
assert.NoError(t, err)
response := executeRequest(server, listRequest)
assert.Equal(t, http.StatusUnauthorized, response.Code)
})
}