-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from gm-data/master
- Loading branch information
Showing
2 changed files
with
122 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package cloudability | ||
|
||
import ( | ||
"encoding/json" | ||
"strconv" | ||
) | ||
|
||
const containersEndpoint = "/containers/" | ||
|
||
// ContainersEndpoint - Cloudability Containers Provisioning Endpoint | ||
type ContainersEndpoint struct { | ||
*v3Endpoint | ||
} | ||
|
||
// Containers - Cloudability ContainersProvisioning Endpoint | ||
func (c *Client) Containers() *ContainersEndpoint { | ||
return &ContainersEndpoint{newV3Endpoint(c, containersEndpoint)} | ||
} | ||
|
||
type Cluster struct { | ||
ID int `json:"id,omitempty"` | ||
ClusterName string `json:"clusterName"` | ||
KubernetesVersion string `json:"kubernetesVersion,omitempty"` | ||
ClusterVersion string `json:"clusterVersion,omitempty"` | ||
} | ||
|
||
type clusterPayload struct { | ||
ClusterName string `json:"clusterName"` | ||
KubernetesVersion string `json:"kubernetesVersion,omitempty"` | ||
ClusterVersion string `json:"clusterVersion,omitempty"` | ||
} | ||
|
||
// GetContainer - Get an existing cluster by ID. | ||
func (e ContainersEndpoint) GetContainer(id int) (*Cluster, error) { | ||
var result v3Result[*Cluster] | ||
err := e.get(e, "provisioning/"+strconv.Itoa(id), &result) | ||
return result.Result, err | ||
} | ||
|
||
// NewContainers - Create a new Container Provisioning. | ||
func (e *ContainersEndpoint) NewContainers(clusterProvisioning *Cluster) (*Cluster, error) { | ||
clusterProvisioningPayload := new(clusterPayload) | ||
jsonClusterProvisioning, _ := json.Marshal(clusterProvisioning) | ||
json.Unmarshal(jsonClusterProvisioning, clusterProvisioningPayload) | ||
var result v3Result[*Cluster] | ||
err := e.post(e, "provisioning/", clusterProvisioningPayload, nil) | ||
return result.Result, err | ||
} | ||
|
||
// UpdateContainers - Update an existing container by ID. | ||
func (e *ContainersEndpoint) UpdateContainers(clusterProvisioning *Cluster) error { | ||
payload := new(clusterPayload) | ||
jsonContainersProvisioning, _ := json.Marshal(clusterProvisioning) | ||
json.Unmarshal(jsonContainersProvisioning, payload) | ||
return e.put(e, "provisioning/"+strconv.Itoa(clusterProvisioning.ID), payload) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package cloudability | ||
|
||
import ( | ||
"net/url" | ||
"testing" | ||
) | ||
|
||
func TestContainersProvisioningEndpoint(t *testing.T) { | ||
testClient := NewClient("testapikey") | ||
e := testClient.Containers() | ||
if e.BaseURL.String() != apiV3URL { | ||
t.Errorf("ContaintersProvisioningEndpoint BaseURL mismatch. Got %s. Expected %s", e.BaseURL.String(), apiV3URL) | ||
} | ||
if e.EndpointPath != containersEndpoint { | ||
t.Errorf("ContaintersProvisioningEndpoint EndpointPath mismatch. Got %s. Expected %s", e.EndpointPath, containersEndpoint) | ||
} | ||
} | ||
|
||
func TestGetCluster(t *testing.T) { | ||
testServer := testAPI(t, "GET", "/containers/provisioning/1", nil) | ||
defer testServer.Close() | ||
|
||
testClient := NewClient("testapikey") | ||
e := testClient.Containers() | ||
e.BaseURL, _ = url.Parse(testServer.URL) | ||
_, err := e.GetContainer(1) | ||
if err != nil { | ||
t.Fail() | ||
} | ||
} | ||
|
||
func TestNewContainers(t *testing.T) { | ||
cluster := &Cluster{ | ||
ClusterName: "test-cluster-name", | ||
ClusterVersion: "test-cluster-version", | ||
KubernetesVersion: "test-kubernetes-version", | ||
} | ||
testServer := testAPI(t, "POST", "/containers/provisioning", cluster) | ||
defer testServer.Close() | ||
|
||
testClient := NewClient("testapikey") | ||
e := testClient.Containers() | ||
e.BaseURL, _ = url.Parse(testServer.URL) | ||
_, err := e.NewContainers(cluster) | ||
if err != nil { | ||
t.Fail() | ||
} | ||
} | ||
|
||
func TestUpdateContainers(t *testing.T) { | ||
cluster := &Cluster{ | ||
ClusterName: "test-cluster-name", | ||
ClusterVersion: "test-cluster-version", | ||
KubernetesVersion: "test-kubernetes-version", | ||
} | ||
testServer := testAPI(t, "PUT", "/containers/provisioning/0", cluster) | ||
defer testServer.Close() | ||
|
||
testClient := NewClient("testapikey") | ||
e := testClient.Containers() | ||
e.BaseURL, _ = url.Parse(testServer.URL) | ||
err := e.UpdateContainers(cluster) | ||
if err != nil { | ||
t.Fail() | ||
} | ||
} |