Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions packages/k6-tdk/src/client/resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export class Resource extends EndpointClient {
return response
}

deleteResource(p: { resourcePath: string, root: string }): RefinedResponse<'none'> {
deleteResource(p: { resourcePath: string, root: string }, v?: {allowStatus?: Array<number>}): RefinedResponse<'none'> {
let response: RefinedResponse<'none'>
switch (this.platform) {
case Platform.ownCloudServer:
Expand All @@ -43,7 +43,7 @@ export class Resource extends EndpointClient {

check({val: response}, {
'client -> resource.deleteResource - status': ({status}) => {
return status === 204
return [204, ...(v?.allowStatus || [])].includes(status)
}
})

Expand Down Expand Up @@ -97,7 +97,7 @@ export class Resource extends EndpointClient {
return response
}

uploadResource(p: { resourcePath: string, root: string, resourceBytes: RequestBody }): RefinedResponse<'none'> {
uploadResource(p: { resourcePath: string, root: string, resourceBytes: RequestBody }, v?: {allowStatus?: Array<number>}): RefinedResponse<'none'> {
let response: RefinedResponse<'none'>

switch (this.platform) {
Expand All @@ -112,7 +112,7 @@ export class Resource extends EndpointClient {

check({val: response}, {
'client -> resource.uploadResource - status': ({status}) => {
return status === 201
return [201, 204, ...(v?.allowStatus || [])].includes(status)
}
})

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import {ENV, queryJson, store} from '@opencloud-eu/k6-tdk/lib/utils'
import {Options} from 'k6/options'

import {clientFor} from '@/shortcuts'
import {envValues} from '@/values'
import exec from 'k6/execution'

/**/
export const settings = {
...envValues(),
testFile: ENV('TEST_FILE', 'test-file.txt'),
user: {
login: ENV('USER_LOGIN', 'admin'),
password: ENV('USER_PASSWORD', 'admin')
},
}

/**/
export const options: Options = {
vus: 1,
iterations: 1,
insecureSkipTLSVerify: true
}


async function getShared() {
// the test should upload the same file with the same user all the time,
// even across vu's
const user = {
userLogin: settings.user.login,
userPassword: settings.user.password
}
const userStore = store(user.userLogin)
const client = await userStore.setOrGet('client', async () => {
return clientFor(user)
})
const root = await userStore.setOrGet('root', async () => {
const getMyDrivesResponse = await client.me.getMyDrives({params: {$filter: "driveType eq 'personal'"}})
const [actorRoot = user.userLogin] = queryJson("$.value[?(@.driveType === 'personal')].id", getMyDrivesResponse?.body)

return actorRoot
})

return {client, root}
}

async function cleanup() {
const {root, client} = await getShared()
client.resource.deleteResource(
{root, resourcePath: settings.testFile},
{
allowStatus: [
204,
425, // depending on the load, the resource may still be in post-processing
404, // depending on the state, the resource may not exist
]
},
)
}

export async function setup() {
await cleanup()
}

export default async function actor() {
const {root, client} = await getShared()

client.resource.uploadResource(
{
root,
resourcePath: settings.testFile,
resourceBytes: `${exec.vu.idInTest}-${exec.scenario.iterationInInstance}`
},
{
allowStatus: [
201,
204,
412, // if a file is new, oc does not allow creating revisions before pp is finished
]
},
)
}

export async function teardown() {
await cleanup()
}