-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #599 from nextcloud-libraries/perf/db-snapshot
feat(docker): implement DB snapshot and create default set of users
- Loading branch information
Showing
8 changed files
with
154 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/** | ||
* SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
import { User } from '../../dist' | ||
import { randHash } from '../utils' | ||
|
||
describe('Create a snapshot and a user', function() { | ||
let snapshot: string | ||
|
||
it('Create a snapshot', function() { | ||
cy.createDBSnapshot().then(_snapshot => { | ||
snapshot = _snapshot | ||
}) | ||
}) | ||
|
||
const hash = 'user' + randHash() | ||
const user = new User(hash, 'password') | ||
it('Create a user and login', function() { | ||
cy.createUser(user).then(() => { | ||
cy.login(user) | ||
}) | ||
|
||
cy.visit('/apps/files') | ||
cy.url().should('include', '/apps/files') | ||
|
||
cy.listUsers().then(users => { | ||
expect(users).to.contain(user.userId) | ||
}) | ||
}) | ||
|
||
it('Restore the snapshot', function() { | ||
cy.restoreDBSnapshot(snapshot) | ||
}) | ||
|
||
it('Fail login with the user', function() { | ||
cy.visit('/apps/files') | ||
cy.url().should('include', '/login') | ||
|
||
cy.listUsers().then(users => { | ||
expect(users).to.not.contain(user.userId) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,4 @@ | |
export * from './getNc' | ||
export * from './sessions' | ||
export * from './users' | ||
export * from './snapshots' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/** | ||
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
import { basename } from 'path' | ||
|
||
const getContainerName = function(): Cypress.Chainable<string> { | ||
return cy.exec('pwd').then(({ stdout }) => { | ||
const app = basename(stdout).replace(' ', '') | ||
return cy.wrap(`nextcloud-cypress-tests_${app}`) | ||
}) | ||
} | ||
|
||
export const createDBSnapshot = function(snapshot?: string): Cypress.Chainable<string> { | ||
const hash = new Date().toISOString().replace(/[^0-9]/g, '') | ||
getContainerName().then(name => { | ||
cy.exec(`docker exec --user www-data ${name} cp /var/www/html/data/owncloud.db /var/www/html/data/owncloud.db-${snapshot ?? hash}`) | ||
}) | ||
cy.log(`Created snapshot ${snapshot ?? hash}`) | ||
return cy.wrap(snapshot ?? hash) | ||
} | ||
|
||
export const restoreDBSnapshot = function(snapshot: string = 'init') { | ||
getContainerName().then(name => { | ||
cy.exec(`docker exec --user www-data ${name} cp /var/www/html/data/owncloud.db-${snapshot} /var/www/html/data/owncloud.db`) | ||
}) | ||
cy.log(`Restored snapshot ${snapshot}`) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters