Skip to content

Commit

Permalink
Adding tags support in library
Browse files Browse the repository at this point in the history
  • Loading branch information
jdewinne committed Dec 18, 2023
1 parent 5ea4b6b commit d1afbf7
Show file tree
Hide file tree
Showing 6 changed files with 120 additions and 3 deletions.
7 changes: 6 additions & 1 deletion dist/clusters.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,14 @@ export declare class ClusterVersion {
name: string;
version: string;
}
export declare function createCluster(vendorPortalApi: VendorPortalApi, clusterName: string, k8sDistribution: string, k8sVersion: string, clusterTTL: string, diskGib?: number, nodeCount?: number, instanceType?: string): Promise<Cluster>;
interface tag {
key: string;
value: string;
}
export declare function createCluster(vendorPortalApi: VendorPortalApi, clusterName: string, k8sDistribution: string, k8sVersion: string, clusterTTL: string, diskGib?: number, nodeCount?: number, instanceType?: string, tags?: tag[]): Promise<Cluster>;
export declare function pollForStatus(vendorPortalApi: VendorPortalApi, clusterId: string, expectedStatus: string, timeout?: number): Promise<Cluster>;
export declare function getKubeconfig(vendorPortalApi: VendorPortalApi, clusterId: string): Promise<string>;
export declare function removeCluster(vendorPortalApi: VendorPortalApi, clusterId: string): Promise<void>;
export declare function upgradeCluster(vendorPortalApi: VendorPortalApi, clusterId: string, k8sVersion: string): Promise<Cluster>;
export declare function getClusterVersions(vendorPortalApi: VendorPortalApi): Promise<ClusterVersion[]>;
export {};
5 changes: 4 additions & 1 deletion dist/clusters.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ exports.Cluster = Cluster;
class ClusterVersion {
}
exports.ClusterVersion = ClusterVersion;
async function createCluster(vendorPortalApi, clusterName, k8sDistribution, k8sVersion, clusterTTL, diskGib, nodeCount, instanceType) {
async function createCluster(vendorPortalApi, clusterName, k8sDistribution, k8sVersion, clusterTTL, diskGib, nodeCount, instanceType, tags) {
const http = await vendorPortalApi.client();
const reqBody = {
"name": clusterName,
Expand All @@ -18,6 +18,9 @@ async function createCluster(vendorPortalApi, clusterName, k8sDistribution, k8sV
"node_count": nodeCount,
"instance_type": instanceType
};
if (tags) {
reqBody['tags'] = tags;
}
const uri = `${vendorPortalApi.endpoint}/cluster`;
const res = await http.post(uri, JSON.stringify(reqBody));
if (res.message.statusCode != 201) {
Expand Down
43 changes: 43 additions & 0 deletions dist/clusters.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,49 @@ describe('ClusterService', () => {
});
});
});
describe('ClusterService with tags', () => {
beforeAll(() => globalThis.provider.setup());
afterEach(() => globalThis.provider.verify());
afterAll(() => globalThis.provider.finalize());
test('should return cluster with tags', () => {
const expectedCluster = { cluster: { name: "cluster1", id: "1234abcd", status: "provisioning" } };
const reqBody = {
name: "cluster1",
kubernetes_distribution: "kind",
kubernetes_version: "v1.25.1",
ttl: "10m",
tags: [
{
key: "foo",
value: "bar"
}
]
};
globalThis.provider.addInteraction({
state: 'cluster created',
uponReceiving: 'a request for creating a cluster',
withRequest: {
method: 'POST',
path: '/cluster',
body: reqBody,
},
willRespondWith: {
status: 201,
headers: { 'Content-Type': 'application/json' },
body: expectedCluster
}
});
const apiClient = new configuration_1.VendorPortalApi();
apiClient.apiToken = "abcd1234";
apiClient.endpoint = globalThis.provider.mockService.baseUrl;
const tags = [{ key: "foo", value: "bar" }];
return (0, clusters_1.createCluster)(apiClient, "cluster1", "kind", "v1.25.1", "10m", undefined, undefined, undefined, tags).then(cluster => {
expect(cluster.name).toEqual(expectedCluster.cluster.name);
expect(cluster.id).toEqual(expectedCluster.cluster.id);
expect(cluster.status).toEqual(expectedCluster.cluster.status);
});
});
});
describe('upgradeCluster', () => {
const mockServer = mockttp.getLocal();
const apiClient = new configuration_1.VendorPortalApi();
Expand Down
6 changes: 6 additions & 0 deletions pacts/npm_consumer-vp_service.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@
"kubernetes_distribution": "kind",
"kubernetes_version": "v1.25.1",
"name": "cluster1",
"tags": [
{
"key": "foo",
"value": "bar"
}
],
"ttl": "10m"
},
"headers": {
Expand Down
49 changes: 49 additions & 0 deletions src/clusters.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,55 @@ describe('ClusterService', () => {
});
});

describe('ClusterService with tags', () => {

beforeAll(() => globalThis.provider.setup());
afterEach(() => globalThis.provider.verify());
afterAll(() => globalThis.provider.finalize());


test('should return cluster with tags', () => {
const expectedCluster = { cluster: { name: "cluster1", id: "1234abcd", status: "provisioning" } }
const reqBody = {
name: "cluster1",
kubernetes_distribution: "kind",
kubernetes_version: "v1.25.1",
ttl: "10m",
tags: [
{
key: "foo",
value: "bar"
}
]
}
globalThis.provider.addInteraction({
state: 'cluster created',
uponReceiving: 'a request for creating a cluster',
withRequest: {
method: 'POST',
path: '/cluster',
body: reqBody,
},
willRespondWith: {
status: 201,
headers: { 'Content-Type': 'application/json' },
body: expectedCluster
}
});

const apiClient = new VendorPortalApi();
apiClient.apiToken = "abcd1234";
apiClient.endpoint = globalThis.provider.mockService.baseUrl;
const tags = [{ key: "foo", value: "bar" }];

return createCluster(apiClient, "cluster1", "kind", "v1.25.1", "10m", undefined, undefined, undefined, tags).then(cluster => {
expect(cluster.name).toEqual(expectedCluster.cluster.name);
expect(cluster.id).toEqual(expectedCluster.cluster.id);
expect(cluster.status).toEqual(expectedCluster.cluster.status);
});
});
});

describe('upgradeCluster', () => {
const mockServer = mockttp.getLocal()
const apiClient = new VendorPortalApi();
Expand Down
13 changes: 12 additions & 1 deletion src/clusters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,14 @@ export class ClusterVersion {
version: string;
}

export async function createCluster(vendorPortalApi: VendorPortalApi, clusterName: string, k8sDistribution: string, k8sVersion: string, clusterTTL: string, diskGib?: number, nodeCount?: number, instanceType?: string): Promise<Cluster> {
interface tag {
key: string;
value: string;
}


export async function createCluster(vendorPortalApi: VendorPortalApi, clusterName: string, k8sDistribution: string, k8sVersion: string,
clusterTTL: string, diskGib?: number, nodeCount?: number, instanceType?: string, tags?: tag[]): Promise<Cluster> {
const http = await vendorPortalApi.client();

const reqBody = {
Expand All @@ -24,6 +31,10 @@ export async function createCluster(vendorPortalApi: VendorPortalApi, clusterNam
"instance_type": instanceType
}

if (tags) {
reqBody['tags'] = tags;
}

const uri = `${vendorPortalApi.endpoint}/cluster`;
const res = await http.post(uri, JSON.stringify(reqBody));
if (res.message.statusCode != 201) {
Expand Down

0 comments on commit d1afbf7

Please sign in to comment.