-
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 #627 from nextcloud-libraries/artonge/feat/save_re…
…store_state feat: Add save/restore state commands
- Loading branch information
Showing
5 changed files
with
62 additions
and
45 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 was deleted.
Oops, something went wrong.
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,42 @@ | ||
/** | ||
* SPDX-FileCopyrightText: 2022 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 function saveState(): Cypress.Chainable<string> { | ||
const snapshot = Math.random().toString(36).substring(7) | ||
|
||
getContainerName().then(name => { | ||
// DB | ||
cy.exec(`docker exec --user www-data ${name} cp /var/www/html/data/owncloud.db /var/www/html/data/owncloud.db-${snapshot}`) | ||
|
||
// Data | ||
cy.exec(`docker exec --user www-data rm /var/www/html/data/data-${snapshot}.tar`, { failOnNonZeroExit: false }) | ||
cy.exec(`docker exec --user www-data --workdir /var/www/html/data ${name} tar cf /var/www/html/data/data-${snapshot}.tar .`) | ||
}) | ||
|
||
cy.log(`Created snapshot ${snapshot}`) | ||
|
||
return cy.wrap(snapshot) | ||
} | ||
|
||
export function restoreState(snapshot: string = 'init') { | ||
getContainerName().then(name => { | ||
// DB | ||
cy.exec(`docker exec --user www-data ${name} cp /var/www/html/data/owncloud.db-${snapshot} /var/www/html/data/owncloud.db`) | ||
|
||
// Data | ||
cy.exec(`docker exec --user www-data --workdir /var/www/html/data ${name} rm -vfr $(tar --exclude='*/*' -tf '/var/www/html/data/data-${snapshot}.tar')`) | ||
cy.exec(`docker exec --user www-data --workdir /var/www/html/data ${name} tar -xf '/var/www/html/data/data-${snapshot}.tar'`) | ||
}) | ||
|
||
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