diff --git a/default.nix b/default.nix index 1c1b319..c4cb29b 100644 --- a/default.nix +++ b/default.nix @@ -169,6 +169,7 @@ in rec { appImage pkgs.busybox pkgs.yq-go + pkgs.jq ]} export SHELL=${pkgs.bash}/bin/bash exec ${pkgs.bash}/bin/bash ${./tests}/entrypoint.sh "$@" diff --git a/go/cmd/entrypoint/garage.go b/go/cmd/entrypoint/garage.go index 1b10c08..d90184c 100644 --- a/go/cmd/entrypoint/garage.go +++ b/go/cmd/entrypoint/garage.go @@ -7,6 +7,28 @@ import ( "syscall" ) +// minio-client keeps a configuration directory which contains various pieces of +// information which may or may not be useful. Unfortunately when it initializes +// this directory it likes to print some annoying logs, so we pre-initialize in +// order to prevent it from doing so. +func initMCConfigDir() (string, error) { + var ( + path = filepath.Join(envDataDirPath, "mc") + sharePath = filepath.Join(path, "share") + configJSONPath = filepath.Join(path, "config.json") + ) + + if err := os.MkdirAll(sharePath, 0700); err != nil { + return "", fmt.Errorf("creating %q: %w", sharePath, err) + } + + if err := os.WriteFile(configJSONPath, []byte(`{}`), 0600); err != nil { + return "", fmt.Errorf("writing %q: %w", configJSONPath, err) + } + + return path, nil +} + var subCmdGarageMC = subCmd{ name: "mc", descr: "Runs the mc (minio-client) binary. The isle garage can be accessed under the `garage` alias", @@ -50,7 +72,15 @@ var subCmdGarageMC = subCmd{ args = args[i:] } - args = append([]string{binPath("mc")}, args...) + configDir, err := initMCConfigDir() + if err != nil { + return fmt.Errorf("initializing minio-client config directory: %w", err) + } + + args = append([]string{ + binPath("mc"), + "--config-dir", configDir, + }, args...) var ( mcHostVar = fmt.Sprintf( diff --git a/tests/cases/garage/00-cli.sh b/tests/cases/garage/00-cli.sh new file mode 100644 index 0000000..cb7fcc2 --- /dev/null +++ b/tests/cases/garage/00-cli.sh @@ -0,0 +1,13 @@ +# shellcheck source=../../utils/with-single-node-cluster.sh +source "$UTILS"/with-single-node-cluster.sh + +status="$(isle garage cli status | tail -n+3)" + +[ "$(echo "$status" | wc -l)" = "3" ] +echo "$status" | grep -q '10.6.9.1:3900' +echo "$status" | grep -q '10.6.9.1:3910' +echo "$status" | grep -q '10.6.9.1:3920' + +buckets="$(isle garage cli bucket list | tail -n+2)" +[ "$(echo "$buckets" | wc -l)" = 1 ] +echo "$buckets" | grep -q 'global-shared' diff --git a/tests/cases/garage/01-mc.sh b/tests/cases/garage/01-mc.sh new file mode 100644 index 0000000..d885bc0 --- /dev/null +++ b/tests/cases/garage/01-mc.sh @@ -0,0 +1,8 @@ +# shellcheck source=../../utils/with-single-node-cluster.sh +source "$UTILS"/with-single-node-cluster.sh + +files="$(isle garage mc -- tree --json garage)" +[ "$(echo "$files" | jq -s '.|length')" -ge "1" ] + +file="$(echo "$files" | jq -sr '.[0].key')" +[ "$(isle garage mc -- cat "garage/$file" | wc -c)" -gt "0" ] diff --git a/tests/entrypoint.sh b/tests/entrypoint.sh index 3acf252..28fb181 100644 --- a/tests/entrypoint.sh +++ b/tests/entrypoint.sh @@ -50,7 +50,7 @@ test_files=$( find ./cases -type f -name '*.sh' \ | sed "s|^\./cases/||" \ | grep -v entrypoint.sh \ - | sort -n + | sort ) for r in "${REGEXS[@]}"; do @@ -61,7 +61,12 @@ echo -e "number of tests: $(echo "$test_files" | wc -l)\n" for file in $test_files; do echo "Running test case: $file" - [ -z "$VERBOSE" ] && output="$TMPDIR/$file.log" || output=/dev/stdout + if [ -z "$VERBOSE" ]; then + output="$TMPDIR/$file.log" + mkdir -p "$(dirname "$output")" + else + output=/dev/stdout + fi ( export TEST_CASE_FILE="$file"