Skip to content

Commit

Permalink
nextcloud: migration: add nextcloud config maintenance_window_start
Browse files Browse the repository at this point in the history
  • Loading branch information
Pilzinsel64 committed May 17, 2024
1 parent 9be79e5 commit b1c1efe
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/nextcloud/config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,5 @@
'log_type' => 'file',
'logfile' => $snap_data_current.'/logs/nextcloud.log',
'logfilemode' => 0640,
'maintenance_window_start' => 1,
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/sh -e

# Check if config 'maintenance_window_start' doesn't exist or has no value set
if ! occ -n config:system:get maintenance_window_start; then
# Set default 'maintenance_window_start' to 1 a.m. (UTC)
occ -n config:system:set maintenance_window_start --value=1 --type=integer
fi
50 changes: 50 additions & 0 deletions tests/unit/migrations/add_maintenance_window_start_spec.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
Describe 'add-maintenance-window-start migration'
BeforeEach 'setup'
AfterEach 'teardown'
setup()
{
SPEC_TMPDIR="$(mktemp --directory --tmpdir nextcloud-snap-tests.XXXXXXXXXX)"
MIGRATION="src/migrations/migrations/28.0.0snap1/1_add-maintenance-window-start.sh"

# Create nextcloud config for the migration to tweak
mkdir -p "$SPEC_TMPDIR/nextcloud/config"
CONFIG_FILE="$SPEC_TMPDIR/nextcloud/config/config.php"
touch "$CONFIG_FILE"

# Make the migration look in the right place
export SNAP_DATA="$SPEC_TMPDIR"
}

teardown()
{
rm -rf "$SPEC_TMPDIR"
}

It 'handles empty config file'
When call "$MIGRATION"
The status should be failure
End

It 'handles basic config file'
cat <<- "EOF" > "$CONFIG_FILE"
?php
$CONFIG = array(
);
EOF

expected_content=$(cat <<- "EOF"
?php
$CONFIG = array(
'maintenance_window_start' => 1,
);
EOF
)

When call "$MIGRATION"
The status should be success
The output should include "The config ''maintenance_window_start' => 1,' has been added"
The contents of file "$CONFIG_FILE" should equal "$expected_content"
End
End
2 changes: 1 addition & 1 deletion tests/unit/spec_helper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ spec_helper_precheck()
# Available variables: VERSION, SHELL_TYPE, SHELL_VERSION
: minimum_version "0.28.1"
setenv SNAP="$SHELLSPEC_PROJECT_ROOT/src/common"
setenv NEXTCLOUD_SCRIPT_INCLUDE_PATH="src/common/utilities:src/apache/utilities:src/https/utilities:src/php/utilities:src/hooks/utilities"
setenv NEXTCLOUD_SCRIPT_INCLUDE_PATH="src/common/utilities:src/apache/utilities:src/https/utilities:src/php/utilities:src/hooks/utilities:src/nextcloud/utilities"
}

# This callback function will be invoked after a specfile has been loaded.
Expand Down

0 comments on commit b1c1efe

Please sign in to comment.