|
|
@@ -7,6 +7,7 @@ import (
|
|
|
"strings"
|
|
|
"testing"
|
|
|
|
|
|
+ "github.com/go-test/deep"
|
|
|
"github.com/porter-dev/porter/internal/forms"
|
|
|
"github.com/porter-dev/porter/internal/models"
|
|
|
)
|
|
|
@@ -81,7 +82,7 @@ var createProjectTests = []*projTest{
|
|
|
"name": "project-test"
|
|
|
}`,
|
|
|
expStatus: http.StatusCreated,
|
|
|
- expBody: `{"id":1,"name":"project-test","roles":[{"id":0,"kind":"admin","user_id":1,"project_id":1}],"repo_clients":[]}`,
|
|
|
+ expBody: `{"id":1,"name":"project-test","roles":[{"id":0,"kind":"admin","user_id":1,"project_id":1}]}`,
|
|
|
useCookie: true,
|
|
|
validators: []func(c *projTest, tester *tester, t *testing.T){
|
|
|
projectModelBodyValidator,
|
|
|
@@ -104,7 +105,7 @@ var readProjectTests = []*projTest{
|
|
|
endpoint: "/api/projects/1",
|
|
|
body: ``,
|
|
|
expStatus: http.StatusOK,
|
|
|
- expBody: `{"id":1,"name":"project-test","roles":[{"id":0,"kind":"admin","user_id":1,"project_id":1}],"repo_clients":[]}`,
|
|
|
+ expBody: `{"id":1,"name":"project-test","roles":[{"id":0,"kind":"admin","user_id":1,"project_id":1}]}`,
|
|
|
useCookie: true,
|
|
|
validators: []func(c *projTest, tester *tester, t *testing.T){
|
|
|
projectModelBodyValidator,
|
|
|
@@ -116,6 +117,30 @@ func TestHandleReadProject(t *testing.T) {
|
|
|
testProjRequests(t, readProjectTests, true)
|
|
|
}
|
|
|
|
|
|
+var listProjectClustersTest = []*projTest{
|
|
|
+ &projTest{
|
|
|
+ initializers: []func(t *tester){
|
|
|
+ initUserDefault,
|
|
|
+ initProject,
|
|
|
+ initProjectSADefault,
|
|
|
+ },
|
|
|
+ msg: "List project clusters",
|
|
|
+ method: "GET",
|
|
|
+ endpoint: "/api/projects/1/clusters",
|
|
|
+ body: ``,
|
|
|
+ expStatus: http.StatusOK,
|
|
|
+ expBody: `[{"id":1,"service_account_id":1,"name":"cluster-test","server":"https://localhost"}]`,
|
|
|
+ useCookie: true,
|
|
|
+ validators: []func(c *projTest, tester *tester, t *testing.T){
|
|
|
+ projectClustersValidator,
|
|
|
+ },
|
|
|
+ },
|
|
|
+}
|
|
|
+
|
|
|
+func TestHandleListProjectClusters(t *testing.T) {
|
|
|
+ testProjRequests(t, listProjectClustersTest, true)
|
|
|
+}
|
|
|
+
|
|
|
var createProjectSACandidatesTests = []*projTest{
|
|
|
&projTest{
|
|
|
initializers: []func(t *tester){
|
|
|
@@ -345,6 +370,19 @@ func projectSABodyValidator(c *projTest, tester *tester, t *testing.T) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+func projectClustersValidator(c *projTest, tester *tester, t *testing.T) {
|
|
|
+ gotBody := make([]*models.ClusterExternal, 0)
|
|
|
+ expBody := make([]*models.ClusterExternal, 0)
|
|
|
+
|
|
|
+ json.Unmarshal(tester.rr.Body.Bytes(), &gotBody)
|
|
|
+ json.Unmarshal([]byte(c.expBody), &expBody)
|
|
|
+
|
|
|
+ if diff := deep.Equal(gotBody, expBody); diff != nil {
|
|
|
+ t.Errorf("handler returned wrong body:\n")
|
|
|
+ t.Error(diff)
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
const OIDCAuthWithDataForJSON string = `apiVersion: v1\nclusters:\n- cluster:\n server: https://localhost\n certificate-authority-data: LS0tLS1CRUdJTiBDRVJ=\n name: cluster-test\ncontexts:\n- context:\n cluster: cluster-test\n user: test-admin\n name: context-test\ncurrent-context: context-test\nkind: Config\npreferences: {}\nusers:\n- name: test-admin\n user:\n auth-provider:\n config:\n client-id: porter-api\n id-token: token\n idp-issuer-url: https://localhost\n idp-certificate-authority-data: LS0tLS1CRUdJTiBDRVJ=\n name: oidc`
|
|
|
|
|
|
const OIDCAuthWithoutDataForJSON string = `apiVersion: v1\nclusters:\n- cluster:\n server: https://localhost\n certificate-authority-data: LS0tLS1CRUdJTiBDRVJ=\n name: cluster-test\ncontexts:\n- context:\n cluster: cluster-test\n user: test-admin\n name: context-test\ncurrent-context: context-test\nkind: Config\npreferences: {}\nusers:\n- name: test-admin\n user:\n auth-provider:\n config:\n client-id: porter-api\n id-token: token\n idp-issuer-url: https://localhost\n idp-certificate-authority: /fake/path/to/ca.pem\n name: oidc`
|