From 4d3fffa2df68a2fb2fce05a8becd30e03e819aa0 Mon Sep 17 00:00:00 2001 From: Ksawery Zietara Date: Thu, 3 Oct 2024 15:32:06 +0200 Subject: [PATCH] Use chai-as-promised to check if functions threw an error --- testing/e2e/skr/package-lock.json | 63 +++++++++++++++-------- testing/e2e/skr/package.json | 1 + testing/e2e/skr/skr-binding-test/index.js | 27 ++-------- 3 files changed, 48 insertions(+), 43 deletions(-) diff --git a/testing/e2e/skr/package-lock.json b/testing/e2e/skr/package-lock.json index 9b20c4f632..f3793972e4 100644 --- a/testing/e2e/skr/package-lock.json +++ b/testing/e2e/skr/package-lock.json @@ -11,6 +11,7 @@ "dependencies": { "@kubernetes/client-node": "0.15.1", "axios": "^1.7.4", + "chai-as-promised": "^8.0.0", "js-yaml": "^4.1.0", "mocha-junit-reporter": "^2.0.0", "node-forge": "^1.3.1", @@ -436,7 +437,6 @@ "version": "1.1.0", "resolved": "https://registry.npmjs.org/assertion-error/-/assertion-error-1.1.0.tgz", "integrity": "sha512-jgsaNduz+ndvGyFt3uSuWqvy4lCnIJiovtouQN5JZHOKCS2QuhEdbcQHFhVksz2N2U9hXJo8odG7ETyWlEeuDw==", - "dev": true, "engines": { "node": "*" } @@ -618,7 +618,6 @@ "version": "4.3.7", "resolved": "https://registry.npmjs.org/chai/-/chai-4.3.7.tgz", "integrity": "sha512-HLnAzZ2iupm25PlN0xFreAlBA5zaBSv3og0DdeGA4Ar6h6rJ3A0rolRUKJhSF2V10GZKDgWF/VmAEsNWjCRB+A==", - "dev": true, "dependencies": { "assertion-error": "^1.1.0", "check-error": "^1.0.2", @@ -632,6 +631,27 @@ "node": ">=4" } }, + "node_modules/chai-as-promised": { + "version": "8.0.0", + "resolved": "https://registry.npmjs.org/chai-as-promised/-/chai-as-promised-8.0.0.tgz", + "integrity": "sha512-sMsGXTrS3FunP/wbqh/KxM8Kj/aLPXQGkNtvE5wPfSToq8wkkvBpTZo1LIiEVmC4BwkKpag+l5h/20lBMk6nUg==", + "license": "WTFPL", + "dependencies": { + "check-error": "^2.0.0" + }, + "peerDependencies": { + "chai": ">= 2.1.2 < 6" + } + }, + "node_modules/chai-as-promised/node_modules/check-error": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/check-error/-/check-error-2.1.1.tgz", + "integrity": "sha512-OAlb+T7V4Op9OwdkjmguYRqncdlx5JiofwOAUkmTF+jNdHwzTaTs4sRAGpzLF3oOz5xAyDGrPgeIDFQmDOTiJw==", + "license": "MIT", + "engines": { + "node": ">= 16" + } + }, "node_modules/chalk": { "version": "4.1.2", "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", @@ -659,7 +679,6 @@ "version": "1.0.2", "resolved": "https://registry.npmjs.org/check-error/-/check-error-1.0.2.tgz", "integrity": "sha512-BrgHpW9NURQgzoNyjfq0Wu6VFO6D7IZEmJNdtgNqpzGG8RuNFHt2jQxWlAs4HMe119chBnv+34syEZtc6IhLtA==", - "dev": true, "engines": { "node": "*" } @@ -884,7 +903,6 @@ "version": "4.1.3", "resolved": "https://registry.npmjs.org/deep-eql/-/deep-eql-4.1.3.tgz", "integrity": "sha512-WaEtAOpRA1MQ0eohqZjpGD8zdI0Ovsm8mmFhaDN8dvDZzyoUMcYDnf5Y6iu7HTXxf8JDS23qWa4a+hKCDyOPzw==", - "dev": true, "dependencies": { "type-detect": "^4.0.0" }, @@ -1352,7 +1370,6 @@ "version": "2.0.0", "resolved": "https://registry.npmjs.org/get-func-name/-/get-func-name-2.0.0.tgz", "integrity": "sha512-Hm0ixYtaSZ/V7C8FJrtZIuBBI+iSgL+1Aq82zSu8VQNB4S3Gk8e7Qs3VwBDJAhmRZcFqkl3tQu36g/Foh5I5ig==", - "dev": true, "engines": { "node": "*" } @@ -1864,7 +1881,6 @@ "version": "2.3.6", "resolved": "https://registry.npmjs.org/loupe/-/loupe-2.3.6.tgz", "integrity": "sha512-RaPMZKiMy8/JruncMU5Bt6na1eftNoo++R4Y+N2FrxkDVTrGvcyzFTsaGif4QTeKESheMGegbhw6iUAq+5A8zA==", - "dev": true, "dependencies": { "get-func-name": "^2.0.0" } @@ -2341,7 +2357,6 @@ "version": "1.1.1", "resolved": "https://registry.npmjs.org/pathval/-/pathval-1.1.1.tgz", "integrity": "sha512-Dp6zGqpTdETdR63lehJYPeIOqpiNBNtc7BpWSLrOje7UaIsE5aY92r/AunQA7rsXvet3lrJ3JnZX29UPTKXyKQ==", - "dev": true, "engines": { "node": "*" } @@ -2886,7 +2901,6 @@ "version": "4.0.8", "resolved": "https://registry.npmjs.org/type-detect/-/type-detect-4.0.8.tgz", "integrity": "sha512-0fr/mIH1dlO+x7TlcMy+bIDqKPsw/70tVyeHW787goQjhmqaZe10uwLujubK9q9Lg6Fiho1KUKDYz0Z7k7g5/g==", - "dev": true, "engines": { "node": ">=4" } @@ -3445,8 +3459,7 @@ "assertion-error": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/assertion-error/-/assertion-error-1.1.0.tgz", - "integrity": "sha512-jgsaNduz+ndvGyFt3uSuWqvy4lCnIJiovtouQN5JZHOKCS2QuhEdbcQHFhVksz2N2U9hXJo8odG7ETyWlEeuDw==", - "dev": true + "integrity": "sha512-jgsaNduz+ndvGyFt3uSuWqvy4lCnIJiovtouQN5JZHOKCS2QuhEdbcQHFhVksz2N2U9hXJo8odG7ETyWlEeuDw==" }, "asynckit": { "version": "0.4.0", @@ -3589,7 +3602,6 @@ "version": "4.3.7", "resolved": "https://registry.npmjs.org/chai/-/chai-4.3.7.tgz", "integrity": "sha512-HLnAzZ2iupm25PlN0xFreAlBA5zaBSv3og0DdeGA4Ar6h6rJ3A0rolRUKJhSF2V10GZKDgWF/VmAEsNWjCRB+A==", - "dev": true, "requires": { "assertion-error": "^1.1.0", "check-error": "^1.0.2", @@ -3600,6 +3612,21 @@ "type-detect": "^4.0.5" } }, + "chai-as-promised": { + "version": "8.0.0", + "resolved": "https://registry.npmjs.org/chai-as-promised/-/chai-as-promised-8.0.0.tgz", + "integrity": "sha512-sMsGXTrS3FunP/wbqh/KxM8Kj/aLPXQGkNtvE5wPfSToq8wkkvBpTZo1LIiEVmC4BwkKpag+l5h/20lBMk6nUg==", + "requires": { + "check-error": "^2.0.0" + }, + "dependencies": { + "check-error": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/check-error/-/check-error-2.1.1.tgz", + "integrity": "sha512-OAlb+T7V4Op9OwdkjmguYRqncdlx5JiofwOAUkmTF+jNdHwzTaTs4sRAGpzLF3oOz5xAyDGrPgeIDFQmDOTiJw==" + } + } + }, "chalk": { "version": "4.1.2", "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", @@ -3617,8 +3644,7 @@ "check-error": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/check-error/-/check-error-1.0.2.tgz", - "integrity": "sha512-BrgHpW9NURQgzoNyjfq0Wu6VFO6D7IZEmJNdtgNqpzGG8RuNFHt2jQxWlAs4HMe119chBnv+34syEZtc6IhLtA==", - "dev": true + "integrity": "sha512-BrgHpW9NURQgzoNyjfq0Wu6VFO6D7IZEmJNdtgNqpzGG8RuNFHt2jQxWlAs4HMe119chBnv+34syEZtc6IhLtA==" }, "chokidar": { "version": "3.5.3", @@ -3776,7 +3802,6 @@ "version": "4.1.3", "resolved": "https://registry.npmjs.org/deep-eql/-/deep-eql-4.1.3.tgz", "integrity": "sha512-WaEtAOpRA1MQ0eohqZjpGD8zdI0Ovsm8mmFhaDN8dvDZzyoUMcYDnf5Y6iu7HTXxf8JDS23qWa4a+hKCDyOPzw==", - "dev": true, "requires": { "type-detect": "^4.0.0" } @@ -4114,8 +4139,7 @@ "get-func-name": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/get-func-name/-/get-func-name-2.0.0.tgz", - "integrity": "sha512-Hm0ixYtaSZ/V7C8FJrtZIuBBI+iSgL+1Aq82zSu8VQNB4S3Gk8e7Qs3VwBDJAhmRZcFqkl3tQu36g/Foh5I5ig==", - "dev": true + "integrity": "sha512-Hm0ixYtaSZ/V7C8FJrtZIuBBI+iSgL+1Aq82zSu8VQNB4S3Gk8e7Qs3VwBDJAhmRZcFqkl3tQu36g/Foh5I5ig==" }, "get-stream": { "version": "6.0.1", @@ -4487,7 +4511,6 @@ "version": "2.3.6", "resolved": "https://registry.npmjs.org/loupe/-/loupe-2.3.6.tgz", "integrity": "sha512-RaPMZKiMy8/JruncMU5Bt6na1eftNoo++R4Y+N2FrxkDVTrGvcyzFTsaGif4QTeKESheMGegbhw6iUAq+5A8zA==", - "dev": true, "requires": { "get-func-name": "^2.0.0" } @@ -4824,8 +4847,7 @@ "pathval": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/pathval/-/pathval-1.1.1.tgz", - "integrity": "sha512-Dp6zGqpTdETdR63lehJYPeIOqpiNBNtc7BpWSLrOje7UaIsE5aY92r/AunQA7rsXvet3lrJ3JnZX29UPTKXyKQ==", - "dev": true + "integrity": "sha512-Dp6zGqpTdETdR63lehJYPeIOqpiNBNtc7BpWSLrOje7UaIsE5aY92r/AunQA7rsXvet3lrJ3JnZX29UPTKXyKQ==" }, "performance-now": { "version": "2.1.0", @@ -5200,8 +5222,7 @@ "type-detect": { "version": "4.0.8", "resolved": "https://registry.npmjs.org/type-detect/-/type-detect-4.0.8.tgz", - "integrity": "sha512-0fr/mIH1dlO+x7TlcMy+bIDqKPsw/70tVyeHW787goQjhmqaZe10uwLujubK9q9Lg6Fiho1KUKDYz0Z7k7g5/g==", - "dev": true + "integrity": "sha512-0fr/mIH1dlO+x7TlcMy+bIDqKPsw/70tVyeHW787goQjhmqaZe10uwLujubK9q9Lg6Fiho1KUKDYz0Z7k7g5/g==" }, "type-fest": { "version": "0.20.2", diff --git a/testing/e2e/skr/package.json b/testing/e2e/skr/package.json index 38fae43ddf..eb876deda8 100644 --- a/testing/e2e/skr/package.json +++ b/testing/e2e/skr/package.json @@ -28,6 +28,7 @@ "dependencies": { "@kubernetes/client-node": "0.15.1", "axios": "^1.7.4", + "chai-as-promised": "^8.0.0", "js-yaml": "^4.1.0", "mocha-junit-reporter": "^2.0.0", "node-forge": "^1.3.1", diff --git a/testing/e2e/skr/skr-binding-test/index.js b/testing/e2e/skr/skr-binding-test/index.js index bc60e4cde3..7419cc0e97 100644 --- a/testing/e2e/skr/skr-binding-test/index.js +++ b/testing/e2e/skr/skr-binding-test/index.js @@ -1,4 +1,6 @@ const {expect} = require('chai'); +const chaiAsPromised = require('chai-as-promised'); +chai.use(chaiAsPromised); const {gatherOptions} = require('../skr-test'); const {initializeK8sClient} = require('../utils/index.js'); const {getSecret, getKubeconfigValidityInSeconds} = require('../utils'); @@ -56,23 +58,11 @@ describe('SKR Binding test', function() { }); it('Try to fetch SKR binding created using Kubernetes TokenRequest', async function() { - try { - await keb.getBinding(options.instanceID, bindingID); - fail('KEB must return an error'); - } catch (err) { - expect(err.response.status).equal(404); - console.log('Got response:'); - console.log(err.response.data); - } + await expect(keb.getBinding(options.instanceID, bindingID)).to.be.rejectedWith(Error); }); it('Try to fetch sap-btp-manager secret using binding from Kubernetes TokenRequest', async function() { - try { - await getSecret(secretName, ns); - fail('KCP must return an error'); - } catch (err) { - console.log(err); - } + await expect(getSecret(secretName, ns)).to.be.rejectedWith(Error); }); it('Create SKR binding using Gardener', async function() { @@ -104,14 +94,7 @@ describe('SKR Binding test', function() { }); it('Try to fetch SKR binding created using Gardener', async function() { - try { - await keb.getBinding(options.instanceID, bindingID); - fail('KEB must return an error'); - } catch (err) { - expect(err.response.status).equal(404); - console.log('Got response:'); - console.log(err.response.data); - } + await expect(keb.getBinding(options.instanceID, bindingID)).to.be.rejectedWith(Error); }); it('Try to fetch sap-btp-manager secret using binding from Gardener', async function() {