-
Notifications
You must be signed in to change notification settings - Fork 192
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(integration): add start of integration testing framework (#477)
- Loading branch information
Silas Boyd-Wickizer
committed
May 20, 2019
1 parent
283cc34
commit d9543a1
Showing
4 changed files
with
84 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
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
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,12 @@ | ||
/* eslint-disable max-nested-callbacks */ | ||
/* eslint-env mocha */ | ||
'use strict' | ||
|
||
const env = require('./env') | ||
|
||
describe('test-integration/basic', () => { | ||
it('creates and deletes Namespaces', async () => { | ||
await env.setupNamespace() | ||
await env.tearDownNamespace() | ||
}) | ||
}) |
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,59 @@ | ||
/* eslint-disable max-nested-callbacks */ | ||
/* eslint-env mocha */ | ||
'use strict' | ||
|
||
const k8s = require('@kubernetes/client-node') | ||
|
||
const Client = require('../').Client | ||
const Request = require('../backends/request') | ||
|
||
const ClientNodeBackend = require('../backends/kubernetes-client-node') | ||
|
||
async function getClient () { | ||
if (process.env.KUBERNETES_CLIENT_BACKEND === 'client-node') { | ||
const kubeconfig = new k8s.KubeConfig() | ||
kubeconfig.loadFromDefault() | ||
const backend = new ClientNodeBackend({ client: k8s, kubeconfig }) | ||
const client = new Client({ backend, version: '1.13' }) | ||
return client | ||
} else { | ||
const backend = new Request(Request.config.fromKubeconfig()) | ||
const client = new Client({ backend }) | ||
await client.loadSpec() | ||
return client | ||
} | ||
} | ||
|
||
let lastNamespace = null | ||
|
||
async function setupNamespace (options) { | ||
options = options || {} | ||
const client = options.client || await getClient() | ||
|
||
const namespace = `test-${Math.floor(Math.random() * 900000 + 100000)}` | ||
lastNamespace = namespace | ||
|
||
await client.api.v1.namespaces.post({ | ||
body: { | ||
metadata: { | ||
name: namespace | ||
} | ||
} | ||
}) | ||
|
||
return namespace | ||
} | ||
|
||
async function tearDownNamespace (options) { | ||
options = options || {} | ||
const client = options.clent || await getClient() | ||
const namespace = options.namespace || lastNamespace | ||
|
||
await client.api.v1.namespaces(namespace).delete() | ||
} | ||
|
||
module.exports = { | ||
getClient, | ||
setupNamespace, | ||
tearDownNamespace | ||
} |