From 0ac0697373f6075d36253dcdad6ccd4196e0f2b6 Mon Sep 17 00:00:00 2001 From: Connor Peet Date: Tue, 16 Jun 2020 21:14:46 -0700 Subject: [PATCH] fix: skip test in older version that lacks permission check --- .github/workflows/ci.yml | 2 ++ changelog.md | 1 + src/test/util.ts | 11 +++++++++++ src/test/watch.test.ts | 29 ++++++++++++++++------------- 4 files changed, 30 insertions(+), 13 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1a6eb7b..73fcff3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,3 +21,5 @@ jobs: - run: npm ci - run: npm run build:ts - run: npm test + env: + ETCD_VERSION: ${{ matrix.etcd-version }} diff --git a/changelog.md b/changelog.md index 5655a47..af3c4d0 100644 --- a/changelog.md +++ b/changelog.md @@ -8,6 +8,7 @@ Thank you to [@pauliusuza](https://github.com/pauliusuza) for his help updating everything - **feat**: add `SingleRangeBuilder.exists()` that returns if the given key exists +- **fix**: errors when creating watchers not being handled correctly (see [114](https://github.com/microsoft/etcd3/issues/114)) ## 0.2.13 2019-07-03 diff --git a/src/test/util.ts b/src/test/util.ts index b01c029..81412c9 100644 --- a/src/test/util.ts +++ b/src/test/util.ts @@ -16,6 +16,8 @@ const tlsKey = fs.readFileSync(`${rootPath}/src/test/certs/private/etcd0.localho const etcdSourceAddress = process.env.ETCD_ADDR || '127.0.0.1:2379'; const [etcdSourceHost, etcdSourcePort] = etcdSourceAddress.split(':'); +export const etcdVersion = process.env.ETCD_VERSION || '3.3.9'; + /** * Proxy is a TCP proxy for etcd, used so that we can simulate network failures * and disruptions in a cross-platform manner (i.e no reliance on tcpkill @@ -261,3 +263,12 @@ export async function removeAuth(client: Etcd3) { await wipeAll(client.getUsers()); await wipeAll(client.getRoles()); } + +const compareVersion = (version: string) => { + const aParts = etcdVersion.split('.').map(Number); + const bParts = version.split('.').map(Number); + return aParts.map((a, i) => a - bParts[i]).find(cmp => cmp !== 0) ?? 0; +}; + +export const isAtLeastVersion = (version: string) => compareVersion(version) >= 0; +export const atAtMostVersion = (version: string) => compareVersion(version) <= 0; diff --git a/src/test/watch.test.ts b/src/test/watch.test.ts index adddef6..06c15bd 100644 --- a/src/test/watch.test.ts +++ b/src/test/watch.test.ts @@ -13,6 +13,7 @@ import { tearDownTestClient, setupAuth, removeAuth, + isAtLeastVersion, } from './util'; import { EtcdPermissionDeniedError } from '../errors'; @@ -127,20 +128,22 @@ describe('watch()', () => { beforeEach(() => setupAuth(client)); afterEach(() => removeAuth(client)); - it('is fixed', async () => { - const authedClient = new Etcd3( - getOptions({ - auth: { - username: 'connor', - password: 'password', - }, - }), - ); + if (isAtLeastVersion('3.2.0')) { + it('is fixed', async () => { + const authedClient = new Etcd3( + getOptions({ + auth: { + username: 'connor', + password: 'password', + }, + }), + ); - await expect(authedClient.watch().key('outside of range').create()).to.be.rejectedWith( - EtcdPermissionDeniedError, - ); - }); + await expect(authedClient.watch().key('outside of range').create()).to.be.rejectedWith( + EtcdPermissionDeniedError, + ); + }); + } }); });