Skip to content

Commit

Permalink
Add ts style guide and run e2e on master (kedacore#445)
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmelsayed authored Nov 11, 2019
1 parent 5e6b0c2 commit bb3d6e1
Show file tree
Hide file tree
Showing 6 changed files with 216 additions and 225 deletions.
10 changes: 10 additions & 0 deletions .github/workflows/master-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,13 @@ jobs:
env:
STORAGE_HELM_SAS_TOKEN: ${{ secrets.STORAGE_HELM_SAS_TOKEN }}
run: helm init --client-only && make publish-edge-chart

- name: Run end to end tests
env:
AZURE_SUBSCRIPTION: ${{ secrets.AZURE_SUBSCRIPTION }}
AZURE_RESOURCE_GROUP: ${{ secrets.AZURE_RESOURCE_GROUP }}
AZURE_SP_ID: ${{ secrets.AZURE_SP_ID }}
AZURE_SP_KEY: ${{ secrets.AZURE_SP_KEY }}
AZURE_SP_TENANT: ${{ secrets.AZURE_SP_TENANT }}
TEST_STORAGE_CONNECTION_STRING: ${{ secrets.TEST_STORAGE_CONNECTION_STRING }}
run: make e2e-test
6 changes: 6 additions & 0 deletions tests/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"semi": false,
"singleQuote": true,
"trailingComma": "es5",
"printWidth": 100
}
66 changes: 34 additions & 32 deletions tests/cleanup.test.ts
Original file line number Diff line number Diff line change
@@ -1,41 +1,43 @@
import * as sh from 'shelljs';
import chalk from 'chalk';
import test from 'ava';
import * as sh from 'shelljs'
import chalk from 'chalk'
import test from 'ava'

test.before('setup shelljs', () => {
sh.config.silent = true;
});
sh.config.silent = true
})

test('Remove Keda', t => {
const resources = [
'apiservice.apiregistration.k8s.io/v1beta1.external.metrics.k8s.io',
'deployment.apps/keda-operator',
'clusterrole.rbac.authorization.k8s.io/keda-operator',
'clusterrole.rbac.authorization.k8s.io/keda-external-metrics-reader',
'clusterrolebinding.rbac.authorization.k8s.io/keda-operator',
'clusterrolebinding.rbac.authorization.k8s.io/keda:system:auth-delegator',
'rolebinding.rbac.authorization.k8s.io/keda-auth-reader',
'clusterrolebinding.rbac.authorization.k8s.io/keda-hpa-controller-external-metrics',
'service/keda-operator',
'serviceaccount/keda-operator',
];
const resources = [
'apiservice.apiregistration.k8s.io/v1beta1.external.metrics.k8s.io',
'deployment.apps/keda-operator',
'clusterrole.rbac.authorization.k8s.io/keda-operator',
'clusterrole.rbac.authorization.k8s.io/keda-external-metrics-reader',
'clusterrolebinding.rbac.authorization.k8s.io/keda-operator',
'clusterrolebinding.rbac.authorization.k8s.io/keda:system:auth-delegator',
'rolebinding.rbac.authorization.k8s.io/keda-auth-reader',
'clusterrolebinding.rbac.authorization.k8s.io/keda-hpa-controller-external-metrics',
'service/keda-operator',
'serviceaccount/keda-operator',
]

for (const resource of resources) {
const result = sh.exec(`kubectl delete ${resource} --namespace keda`);
if (result.code !== 0) {
t.log(chalk.red(`error deleting ${resource}. ${result}`));
}
}

let result = sh.exec('kubectl delete rolebinding.rbac.authorization.k8s.io/keda-auth-reader --namespace kube-system');
for (const resource of resources) {
const result = sh.exec(`kubectl delete ${resource} --namespace keda`)
if (result.code !== 0) {
t.log(chalk.red(`error deleting rolebinding. ${result}`));
t.log(chalk.red(`error deleting ${resource}. ${result}`))
}
}

result = sh.exec('kubectl delete namespace keda');
if (result.code !== 0) {
t.log(chalk.red(`error deleting keda namespace. ${result}`));
}
let result = sh.exec(
'kubectl delete rolebinding.rbac.authorization.k8s.io/keda-auth-reader --namespace kube-system'
)
if (result.code !== 0) {
t.log(chalk.red(`error deleting rolebinding. ${result}`))
}

result = sh.exec('kubectl delete namespace keda')
if (result.code !== 0) {
t.log(chalk.red(`error deleting keda namespace. ${result}`))
}

t.pass();
});
t.pass()
})
124 changes: 57 additions & 67 deletions tests/scalers/azure-queue-trigger-auth.test.ts
Original file line number Diff line number Diff line change
@@ -1,110 +1,100 @@
import * as async from "async";
import * as azure from "azure-storage";
import * as fs from "fs";
import * as sh from "shelljs";
import * as tmp from "tmp";
import test from "ava";
import * as async from 'async'
import * as azure from 'azure-storage'
import * as fs from 'fs'
import * as sh from 'shelljs'
import * as tmp from 'tmp'
import test from 'ava'

const defaultNamespace = "azure-queue-auth-test";
const queueName = "auth-queue-name";
const connectionString = process.env["TEST_STORAGE_CONNECTION_STRING"];
const defaultNamespace = 'azure-queue-auth-test'
const queueName = 'auth-queue-name'
const connectionString = process.env['TEST_STORAGE_CONNECTION_STRING']

test.before(t => {
if (!connectionString) {
t.fail(
"TEST_STORAGE_CONNECTION_STRING environment variable is required for queue tests"
);
t.fail('TEST_STORAGE_CONNECTION_STRING environment variable is required for queue tests')
}

sh.config.silent = true;
const base64ConStr = Buffer.from(connectionString).toString("base64");
const tmpFile = tmp.fileSync();
fs.writeFileSync(
tmpFile.name,
deployYaml.replace(/{{CONNECTION_STRING_BASE64}}/g, base64ConStr)
);
sh.exec(`kubectl create namespace ${defaultNamespace}`);
sh.config.silent = true
const base64ConStr = Buffer.from(connectionString).toString('base64')
const tmpFile = tmp.fileSync()
fs.writeFileSync(tmpFile.name, deployYaml.replace(/{{CONNECTION_STRING_BASE64}}/g, base64ConStr))
sh.exec(`kubectl create namespace ${defaultNamespace}`)
t.is(
0,
sh.exec(`kubectl apply -f ${tmpFile.name} --namespace ${defaultNamespace}`)
.code,
"creating a deployment should work."
);
});
sh.exec(`kubectl apply -f ${tmpFile.name} --namespace ${defaultNamespace}`).code,
'creating a deployment should work.'
)
})

test.serial("Deployment should have 0 replicas on start", t => {
test.serial('Deployment should have 0 replicas on start', t => {
const replicaCount = sh.exec(
`kubectl get deployment.apps/test-deployment --namespace ${defaultNamespace} -o jsonpath="{.spec.replicas}"`
).stdout;
t.is(replicaCount, "0", "replica count should start out as 0");
});
).stdout
t.is(replicaCount, '0', 'replica count should start out as 0')
})

test.serial.cb(
"Deployment should scale with messages on storage defined through trigger auth",
'Deployment should scale with messages on storage defined through trigger auth',
t => {
const queueSvc = azure.createQueueService(connectionString);
queueSvc.messageEncoder = new azure.QueueMessageEncoder.TextBase64QueueMessageEncoder();
const queueSvc = azure.createQueueService(connectionString)
queueSvc.messageEncoder = new azure.QueueMessageEncoder.TextBase64QueueMessageEncoder()
queueSvc.createQueueIfNotExists(queueName, err => {
t.falsy(err, "unable to create queue");
t.falsy(err, 'unable to create queue')
async.mapLimit(
Array(1000).keys(),
20,
(n, cb) => queueSvc.createMessage(queueName, `test ${n}`, cb),
() => {
let replicaCount = "0";
for (let i = 0; i < 10 && replicaCount !== "1"; i++) {
let replicaCount = '0'
for (let i = 0; i < 10 && replicaCount !== '1'; i++) {
replicaCount = sh.exec(
`kubectl get deployment.apps/test-deployment --namespace ${defaultNamespace} -o jsonpath="{.spec.replicas}"`
).stdout;
if (replicaCount !== "1") {
sh.exec("sleep 1s");
).stdout
if (replicaCount !== '1') {
sh.exec('sleep 1s')
}
}

t.is("1", replicaCount, "Replica count should be 1 after 10 seconds");
t.is('1', replicaCount, 'Replica count should be 1 after 10 seconds')
queueSvc.deleteQueueIfExists(queueName, err => {
t.falsy(err, `unable to delete queue ${queueName}`);
for (let i = 0; i < 50 && replicaCount !== "0"; i++) {
t.falsy(err, `unable to delete queue ${queueName}`)
for (let i = 0; i < 50 && replicaCount !== '0'; i++) {
replicaCount = sh.exec(
`kubectl get deployment.apps/test-deployment --namespace ${defaultNamespace} -o jsonpath="{.spec.replicas}"`
).stdout;
if (replicaCount !== "0") {
sh.exec("sleep 5s");
).stdout
if (replicaCount !== '0') {
sh.exec('sleep 5s')
}
}

t.is(
"0",
replicaCount,
"Replica count should be 0 after 3 minutes"
);
t.end();
});
t.is('0', replicaCount, 'Replica count should be 0 after 3 minutes')
t.end()
})
}
);
});
)
})
}
);
)

test.after.always.cb("clean up azure-queue deployment", t => {
test.after.always.cb('clean up azure-queue deployment', t => {
const resources = [
"secret/test-secrets",
"deployment.apps/test-deployment",
"scaledobject.keda.k8s.io/test-scaledobject"
];
'secret/test-secrets',
'deployment.apps/test-deployment',
'scaledobject.keda.k8s.io/test-scaledobject',
]

for (const resource of resources) {
sh.exec(`kubectl delete ${resource} --namespace ${defaultNamespace}`);
sh.exec(`kubectl delete ${resource} --namespace ${defaultNamespace}`)
}
sh.exec(`kubectl delete namespace ${defaultNamespace}`);
sh.exec(`kubectl delete namespace ${defaultNamespace}`)

// delete test queue
const queueSvc = azure.createQueueService(connectionString);
const queueSvc = azure.createQueueService(connectionString)
queueSvc.deleteQueueIfExists(queueName, err => {
t.falsy(err, "should delete test queue successfully");
t.end();
});
});
t.falsy(err, 'should delete test queue successfully')
t.end()
})
})

const deployYaml = `apiVersion: v1
kind: Secret
Expand Down Expand Up @@ -169,4 +159,4 @@ spec:
- parameter: connection
name: test-auth-secrets
key: connectionString
`;
`
Loading

0 comments on commit bb3d6e1

Please sign in to comment.