Skip to content
This repository has been archived by the owner on Mar 4, 2024. It is now read-only.

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
oksana-grishchenko committed Feb 9, 2024
1 parent fa8e366 commit 6ca2184
Show file tree
Hide file tree
Showing 10 changed files with 371 additions and 361 deletions.
505 changes: 253 additions & 252 deletions api-tests/tests/backup-storages.spec.ts

Large diffs are not rendered by default.

17 changes: 9 additions & 8 deletions api-tests/tests/database-cluster-backups.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
// limitations under the License.
import { expect, test } from '@playwright/test'
import * as th from './helpers'
import {testsNs} from "./helpers";

test('create/delete database cluster backups', async ({ request }) => {
const bsName = th.suffixedName('storage')
Expand All @@ -36,13 +37,13 @@ test('create/delete database cluster backups', async ({ request }) => {
},
}

let response = await request.post(`/v1/database-cluster-backups`, {
let response = await request.post(`/v1/namespaces/${testsNs}/database-cluster-backups`, {
data: payload,
})

expect(response.ok()).toBeTruthy()

response = await request.get(`/v1/database-cluster-backups/${backupName}`)
response = await request.get(`/v1/namespaces/${testsNs}/database-cluster-backups/${backupName}`)
const result = await response.json()

expect(result.spec).toMatchObject(payload.spec)
Expand Down Expand Up @@ -70,7 +71,7 @@ test('dbcluster not found', async ({ request }) => {
},
}

const response = await request.post(`/v1/database-cluster-backups`, {
const response = await request.post(`/v1/namespaces/${testsNs}/database-cluster-backups`, {
data: payload,
})

Expand Down Expand Up @@ -142,27 +143,27 @@ test('list backups', async ({ request, page }) => {
]

for (const payload of payloads) {
const response = await request.post(`/v1/database-cluster-backups`, {
const response = await request.post(`/v1/namespaces/${testsNs}/database-cluster-backups`, {
data: payload,
})

expect(response.ok()).toBeTruthy()
}

await page.waitForTimeout(1000)
let response = await request.get(`/v1/database-clusters/${clusterName1}/backups`)
let response = await request.get(`/v1/namespaces/${testsNs}/database-clusters/${clusterName1}/backups`)
let result = await response.json()

expect(result.items).toHaveLength(2)

response = await request.get(`/v1/database-clusters/${clusterName2}/backups`)
response = await request.get(`/v1/namespaces/${testsNs}/database-clusters/${clusterName2}/backups`)
result = await response.json()

expect(result.items).toHaveLength(2)

for (const payload of payloads) {
await request.delete(`/v1/database-cluster-backups/${payload.metadata.name}`)
response = await request.get(`/v1/database-cluster-backups/${payload.metadata.name}`)
await request.delete(`/v1/namespaces/${testsNs}/database-cluster-backups/${payload.metadata.name}`)
response = await request.get(`/v1/namespaces/${testsNs}/database-cluster-backups/${payload.metadata.name}`)
expect(response.status()).toBe(404)
}

Expand Down
25 changes: 13 additions & 12 deletions api-tests/tests/database-cluster-restores.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
// limitations under the License.
import { expect, test } from '@playwright/test'
import * as th from './helpers'
import {testsNs} from "./helpers";


test('create/update/delete database cluster restore', async ({ request }) => {
Expand Down Expand Up @@ -43,7 +44,7 @@ test('create/update/delete database cluster restore', async ({ request }) => {
},
}

let response = await request.post(`/v1/database-cluster-restores`, {
let response = await request.post(`/v1/namespaces/${testsNs}/database-cluster-restores`, {
data: payloadRestore,
})

Expand All @@ -54,7 +55,7 @@ test('create/update/delete database cluster restore', async ({ request }) => {

// update restore
restore.spec.dbClusterName = clName2
response = await request.put(`/v1/database-cluster-restores/${restoreName}`, {
response = await request.put(`/v1/namespaces/${testsNs}/database-cluster-restores/${restoreName}`, {
data: restore,
})
expect(response.ok()).toBeTruthy()
Expand All @@ -64,16 +65,16 @@ test('create/update/delete database cluster restore', async ({ request }) => {

// update restore with not existing dbClusterName
restore.spec.dbClusterName = 'not-existing-cluster'
response = await request.put(`/v1/database-cluster-restores/${restoreName}`, {
response = await request.put(`/v1/namespaces/${testsNs}/database-cluster-restores/${restoreName}`, {
data: restore,
})
expect(response.status()).toBe(400)
expect(await response.text()).toContain('{"message":"Database cluster not-existing-cluster does not exist"}')

// delete restore
await request.delete(`/v1/database-cluster-restores/${restoreName}`)
await request.delete(`/v1/namespaces/${testsNs}/database-cluster-restores/${restoreName}`)
// check it couldn't be found anymore
response = await request.get(`/v1/database-cluster-restores/${restoreName}`)
response = await request.get(`/v1/namespaces/${testsNs}/database-cluster-restores/${restoreName}`)
expect(response.status()).toBe(404)

await th.deleteDBCluster(request, clName)
Expand Down Expand Up @@ -140,7 +141,7 @@ test('list restores', async ({ request, page }) => {
]

for (const payload of payloads) {
const response = await request.post(`/v1/database-cluster-restores`, {
const response = await request.post(`/v1/namespaces/${testsNs}/database-cluster-restores`, {
data: payload,
})

Expand All @@ -150,20 +151,20 @@ test('list restores', async ({ request, page }) => {
await page.waitForTimeout(6000)

// check if the restores are available when being requested via database-clusters/{cluster-name}/restores path
let response = await request.get(`/v1/database-clusters/${clName1}/restores`)
let response = await request.get(`/v1/namespaces/${testsNs}/database-clusters/${clName1}/restores`)
let result = await response.json()

expect(result.items).toHaveLength(2)

response = await request.get(`/v1/database-clusters/${clName2}/restores`)
response = await request.get(`/v1/namespaces/${testsNs}/database-clusters/${clName2}/restores`)
result = await response.json()

expect(result.items).toHaveLength(1)

// delete the created restores
for (const payload of payloads) {
await request.delete(`/v1/database-cluster-restores/${payload.metadata.name}`)
response = await request.get(`/v1/database-cluster-restores/${payload.metadata.name}`)
await request.delete(`/v1/namespaces/${testsNs}/database-cluster-restores/${payload.metadata.name}`)
response = await request.get(`/v1/namespaces/${testsNs}/database-cluster-restores/${payload.metadata.name}`)
expect(response.status()).toBe(404)
}

Expand Down Expand Up @@ -198,7 +199,7 @@ test('create restore: validation errors', async ({ request, page }) => {
},
}

let response = await request.post(`/v1/database-cluster-restores`, {
let response = await request.post(`/v1/namespaces/${testsNs}/database-cluster-restores`, {
data: payloadRestore,
})

Expand All @@ -214,7 +215,7 @@ test('create restore: validation errors', async ({ request, page }) => {
},
}

response = await request.post(`/v1/database-cluster-restores`, {
response = await request.post(`/v1/namespaces/${testsNs}/database-cluster-restores`, {
data: payloadEmptySpec,
})
expect(response.status()).toBe(400)
Expand Down
31 changes: 16 additions & 15 deletions api-tests/tests/database-cluster.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
import { expect, test } from '@fixtures'
import {testsNs} from "@tests/tests/helpers";

// testPrefix is used to differentiate between several workers
// running this test to avoid conflicts in instance names
Expand Down Expand Up @@ -85,13 +86,13 @@ test('create db cluster with monitoring config', async ({ request }) => {
},
}

const postReq = await request.post(`/v1/database-clusters`, { data })
const postReq = await request.post(`/v1/namespaces/${testsNs}/database-clusters`, { data })

expect(postReq.ok()).toBeTruthy()

try {
await expect(async () => {
const pgCluster = await request.get(`/v1/database-clusters/${clusterName}`)
const pgCluster = await request.get(`/v1/namespaces/${testsNs}/database-clusters/${clusterName}`)

expect(pgCluster.ok()).toBeTruthy()
const res = (await pgCluster.json())
Expand All @@ -102,7 +103,7 @@ test('create db cluster with monitoring config', async ({ request }) => {
timeout: 60 * 1000,
})
} finally {
await request.delete(`/v1/database-clusters/${clusterName}`)
await request.delete(`/v1/namespaces/${testsNs}/database-clusters/${clusterName}`)
}
})

Expand Down Expand Up @@ -139,15 +140,15 @@ test('update db cluster with a new monitoring config', async ({ request }) => {
},
}

const postReq = await request.post(`/v1/database-clusters`, { data })
const postReq = await request.post(`/v1/namespaces/${testsNs}/database-clusters`, { data })

expect(postReq.ok()).toBeTruthy()

try {
let res

await expect(async () => {
const req = await request.get(`/v1/database-clusters/${clusterName}`)
const req = await request.get(`/v1/namespaces/${testsNs}/database-clusters/${clusterName}`)

expect(req.ok()).toBeTruthy()
res = (await req.json())
Expand All @@ -164,13 +165,13 @@ test('update db cluster with a new monitoring config', async ({ request }) => {
putData.metadata = res.metadata
putData.spec.monitoring.monitoringConfigName = monitoringConfigName2

const putReq = await request.put(`/v1/database-clusters/${clusterName}`, { data: putData })
const putReq = await request.put(`/v1/namespaces/${testsNs}/database-clusters/${clusterName}`, { data: putData })

expect(putReq.ok()).toBeTruthy()
res = (await putReq.json())
expect(res?.spec?.monitoring?.monitoringConfigName).toBe(monitoringConfigName2)
} finally {
await request.delete(`/v1/database-clusters/${clusterName}`)
await request.delete(`/v1/namespaces/${testsNs}/database-clusters/${clusterName}`)
}
})

Expand Down Expand Up @@ -204,15 +205,15 @@ test('update db cluster without monitoring config with a new monitoring config',
},
}

const postReq = await request.post(`/v1/database-clusters`, { data })
const postReq = await request.post(`/v1/namespaces/${testsNs}/database-clusters`, { data })

expect(postReq.ok()).toBeTruthy()

try {
let res

await expect(async () => {
const req = await request.get(`/v1/database-clusters/${clusterName}`)
const req = await request.get(`/v1/namespaces/${testsNs}/database-clusters/${clusterName}`)

expect(req.ok()).toBeTruthy()
res = (await req.json())
Expand All @@ -229,13 +230,13 @@ test('update db cluster without monitoring config with a new monitoring config',
putData.metadata = res.metadata;
(putData.spec as any).monitoring = { monitoringConfigName: monitoringConfigName2 }

const putReq = await request.put(`/v1/database-clusters/${clusterName}`, { data: putData })
const putReq = await request.put(`/v1/namespaces/${testsNs}/database-clusters/${clusterName}`, { data: putData })

expect(putReq.ok()).toBeTruthy()
res = (await putReq.json())
expect(res?.spec?.monitoring?.monitoringConfigName).toBe(monitoringConfigName2)
} finally {
await request.delete(`/v1/database-clusters/${clusterName}`)
await request.delete(`/v1/namespaces/${testsNs}/database-clusters/${clusterName}`)
}
})

Expand Down Expand Up @@ -272,15 +273,15 @@ test('update db cluster monitoring config with an empty monitoring config', asyn
},
}

const postReq = await request.post(`/v1/database-clusters`, { data })
const postReq = await request.post(`/v1/namespaces/${testsNs}/database-clusters`, { data })

expect(postReq.ok()).toBeTruthy()

try {
let res

await expect(async () => {
const req = await request.get(`/v1/database-clusters/${clusterName}`)
const req = await request.get(`/v1/namespaces/${testsNs}/database-clusters/${clusterName}`)

expect(req.ok()).toBeTruthy()
res = (await req.json())
Expand All @@ -295,12 +296,12 @@ test('update db cluster monitoring config with an empty monitoring config', asyn
putData.metadata = res.metadata;
(putData.spec.monitoring as any) = {}

const putReq = await request.put(`/v1/database-clusters/${clusterName}`, { data: putData })
const putReq = await request.put(`/v1/namespaces/${testsNs}/database-clusters/${clusterName}`, { data: putData })

expect(putReq.ok()).toBeTruthy()
res = (await putReq.json())
expect(res?.spec?.monitoring?.monitoringConfigName).toBeFalsy()
} finally {
await request.delete(`/v1/database-clusters/${clusterName}`)
await request.delete(`/v1/namespaces/${testsNs}/database-clusters/${clusterName}`)
}
})
9 changes: 5 additions & 4 deletions api-tests/tests/database-engines.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@
// See the License for the specific language governing permissions and
// limitations under the License.
import { test, expect } from '@fixtures'
import {testsNs} from "@tests/tests/helpers";

test('check operators are installed', async ({ request }) => {
const enginesList = await request.get(`/v1/database-engines`)
const enginesList = await request.get(`/v1/namespaces/${testsNs}/database-engines`)

expect(enginesList.ok()).toBeTruthy()

Expand All @@ -34,7 +35,7 @@ test('check operators are installed', async ({ request }) => {

test('get/edit database engine versions', async ({ request }) => {

let engineResponse = await request.get(`/v1/database-engines/percona-server-mongodb-operator`)
let engineResponse = await request.get(`/v1/namespaces/${testsNs}/database-engines/percona-server-mongodb-operator`)

expect(engineResponse.ok()).toBeTruthy()

Expand All @@ -49,13 +50,13 @@ test('get/edit database engine versions', async ({ request }) => {
delete engineData.status
engineData.spec.allowedVersions = allowedVersions

const updateResponse = await request.put(`/v1/database-engines/percona-server-mongodb-operator`, {
const updateResponse = await request.put(`/v1/namespaces/${testsNs}/database-engines/percona-server-mongodb-operator`, {
data: engineData,
})

expect(updateResponse.ok()).toBeTruthy()

engineResponse = await request.get(`/v1/database-engines/percona-server-mongodb-operator`)
engineResponse = await request.get(`/v1/namespaces/${testsNs}/database-engines/percona-server-mongodb-operator`)
expect(engineResponse.ok()).toBeTruthy()

expect((await engineResponse.json()).spec.allowedVersions).toEqual(allowedVersions)
Expand Down
Loading

0 comments on commit 6ca2184

Please sign in to comment.