Skip to content

Commit

Permalink
Extend groups to have an array of clusters as a field
Browse files Browse the repository at this point in the history
  • Loading branch information
Florian Froese committed Mar 24, 2021
1 parent 0caf65b commit 95a8bcb
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 13 deletions.
8 changes: 4 additions & 4 deletions client/actions/clusters/cluster_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ import (
//go:generate go run github.com/maxbrunsfeld/counterfeiter/v6 . ClusterService
type ClusterService interface {
// RegisterCluster registers a new cluster under the specified organization ID.
RegisterCluster(string, types.Registration) (*RegisterClusterResponseDataDetails, error)
RegisterCluster(orgID string, registration types.Registration) (*RegisterClusterResponseDataDetails, error)
// ClustersByOrgID lists the clusters registered under the specified organization.
ClustersByOrgID(string) (types.ClusterList, error)
ClustersByOrgID(orgID string) (types.ClusterList, error)
// ClusterByName returns the cluster registered under the specified organization and name.
ClusterByName(string, string) (*types.Cluster, error)
ClusterByName(orgID string, clusterName string) (*types.Cluster, error)
// DeleteClusterByClusterID deletes the specified cluster from the specified org,
// including all resources under that cluster.
DeleteClusterByClusterID(string, string) (*DeleteClustersResponseDataDetails, error)
DeleteClusterByClusterID(orgID string, clusterID string) (*DeleteClustersResponseDataDetails, error)
}

// Client is an implementation of a satcon client.
Expand Down
1 change: 1 addition & 0 deletions client/actions/groups/group_by_name.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ func NewGroupByNameVariables(orgID string, name string) GroupByNameVariables {
"orgId",
"name",
"created",
"clusters{id,orgId,clusterId,name,metadata}",
}

return vars
Expand Down
9 changes: 9 additions & 0 deletions client/actions/groups/group_by_name_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ var _ = Describe("GroupByName", func() {
"orgId",
"name",
"created",
"clusters{id,orgId,clusterId,name,metadata}",
))
})
})
Expand All @@ -64,6 +65,14 @@ var _ = Describe("GroupByName", func() {
UUID: "asdf",
OrgID: orgID,
Name: "group1",
Clusters: []types.Cluster{
{
ID: "cid",
OrgID: "oid",
ClusterID: "cid",
Name: "cluster1",
},
},
},
},
}
Expand Down
1 change: 1 addition & 0 deletions client/actions/groups/groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ func NewGroupsVariables(orgID string) GroupsVariables {
"orgId",
"name",
"created",
"clusters{id,orgId,clusterId,name,metadata}",
}

return vars
Expand Down
9 changes: 9 additions & 0 deletions client/actions/groups/groups_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ var _ = Describe("Groups", func() {
"orgId",
"name",
"created",
"clusters{id,orgId,clusterId,name,metadata}",
))
})
})
Expand All @@ -61,6 +62,14 @@ var _ = Describe("Groups", func() {
UUID: "asdf",
OrgID: orgID,
Name: "cluster1",
Clusters: []types.Cluster{
{
ID: "cid",
OrgID: "oid",
ClusterID: "cid",
Name: "cluster1",
},
},
},
{
UUID: "qwer",
Expand Down
11 changes: 6 additions & 5 deletions client/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,12 @@ type RequestErrorDetails struct {
type GroupList []Group

type Group struct {
UUID string `json:"uuid,omitempty"`
OrgID string `json:"orgId,omitempty"`
Name string `json:"name,omitempty"`
Owner BasicUser `json:"owner,omitempty"`
Created string `json:"created,omitempty"`
UUID string `json:"uuid,omitempty"`
OrgID string `json:"orgId,omitempty"`
Name string `json:"name,omitempty"`
Owner BasicUser `json:"owner,omitempty"`
Created string `json:"created,omitempty"`
Clusters []Cluster `json:"clusters,omitempty"`
}

// Registration is the encapsulation of the JSON registration body, which at this
Expand Down
28 changes: 24 additions & 4 deletions test/integration/groups_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package integration_test

import (
"fmt"
"github.com/IBM/satcon-client-go/client/types"
"strings"

. "github.com/onsi/ginkgo"
Expand Down Expand Up @@ -30,14 +31,16 @@ var _ = Describe("Groups", func() {
Describe("Group Lifecycle", func() {

var (
groupName1 string
groupName2 string
groupName1 string
groupName2 string
clusterName string
)

BeforeEach(func() {
groupName1 = RandStringBytes(8)
groupName2 = RandStringBytes(8)
fmt.Printf("groupName1 = %s\ngroupName2 = %s\n", groupName1, groupName2)
clusterName = RandStringBytes(8)
fmt.Printf("groupName1 = %s\ngroupName2 = %s\nclusterName = %s\n", groupName1, groupName2, clusterName)
})

It("Lists the groups, creates our new group, lists again and finds it, deletes it, and finally lists to see that it's gone", func() {
Expand Down Expand Up @@ -68,11 +71,28 @@ var _ = Describe("Groups", func() {
}
Expect(found).To(BeTrue())

// get group by name
// create new cluster
newClusterDetails, err := c.Clusters.RegisterCluster(testConfig.OrgID, types.Registration{Name: clusterName})
Expect(err).NotTo(HaveOccurred())
Expect(newClusterDetails).NotTo(BeNil())

// add new cluster to the group
_, err = c.Groups.GroupClusters(testConfig.OrgID, newGroupDetails.UUID, []string{newClusterDetails.ClusterID})
Expect(err).NotTo(HaveOccurred())

// get group by name and verify that the new cluster is part of it
group1, err := c.Groups.GroupByName(testConfig.OrgID, groupName1)
Expect(err).NotTo(HaveOccurred())
Expect(group1).NotTo(BeNil())
Expect(group1.Name).To(Equal(groupName1))
Expect(group1.Clusters).To(HaveLen(1))
Expect(group1.Clusters[0].ClusterID).To(Equal(newClusterDetails.ClusterID))
Expect(group1.Clusters[0].Name).To(Equal(clusterName))

// delete cluster
delClusterDetails, err := c.Clusters.DeleteClusterByClusterID(testConfig.OrgID, newClusterDetails.ClusterID)
Expect(err).NotTo(HaveOccurred())
Expect(delClusterDetails.DeletedClusterCount).To(Equal(1))

// delete the group using RemoveGroupByName
removeGroup1, err := c.Groups.RemoveGroupByName(testConfig.OrgID, groupName1)
Expand Down

0 comments on commit 95a8bcb

Please sign in to comment.