From a6204a7c584630ecb80ab7a7eeb02d10f2af76d5 Mon Sep 17 00:00:00 2001 From: shm12 Date: Wed, 28 Dec 2022 17:22:40 +0200 Subject: [PATCH] Fix `opa inspect` data namespaces on windows Signed-off-by: shm12 --- build/binary-smoke-test.sh | 12 ++++++++++++ internal/bundle/inspect/inspect.go | 5 +++-- test/cli/smoke/namesapce/data.json | 3 +++ 3 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 test/cli/smoke/namesapce/data.json diff --git a/build/binary-smoke-test.sh b/build/binary-smoke-test.sh index 5d8f9b03f3..af2ad7b588 100755 --- a/build/binary-smoke-test.sh +++ b/build/binary-smoke-test.sh @@ -3,6 +3,13 @@ set -eo pipefail OPA_EXEC="$1" TARGET="$2" +PATH_SEPARATOR="/" +if [[ $OPA_EXEC == *".exe" ]]; then + PATH_SEPARATOR="\\" +fi + + + github_actions_group() { local args="$*" echo "::group::$args" @@ -42,3 +49,8 @@ echo '{"yay": "bar"}' | opa eval --format pretty --bundle o2.tar.gz -I data.test # Tar paths opa build --output o3.tar.gz test/cli/smoke github_actions_group assert_contains '/test/cli/smoke/test.rego' "$(tar -tf o3.tar.gz /test/cli/smoke/test.rego)" + +# Data files - correct namespaces +echo "::group:: Data files - correct namespaces" +assert_contains "data.namesapce | test${PATH_SEPARATOR}cli${PATH_SEPARATOR}smoke${PATH_SEPARATOR}namesapce${PATH_SEPARATOR}data.json" "$(opa inspect test/cli/smoke)" +echo "::endgroup::" \ No newline at end of file diff --git a/internal/bundle/inspect/inspect.go b/internal/bundle/inspect/inspect.go index 58d8438e1c..2636915a1a 100644 --- a/internal/bundle/inspect/inspect.go +++ b/internal/bundle/inspect/inspect.go @@ -8,6 +8,7 @@ import ( "bytes" "fmt" "io" + "os" "path/filepath" "strings" @@ -128,11 +129,11 @@ func (bi *Info) getBundleDataWasmAndSignatures(name string) error { for _, f := range descriptors { path := filepath.Clean(f.Path()) - key := strings.Split(strings.TrimPrefix(path, "/"), "/") + key := strings.Split(strings.TrimPrefix(path, string(os.PathSeparator)), string(os.PathSeparator)) value := path if bl.IsDir { - value = f.URL() + value = filepath.Clean(f.URL()) } if len(key) > 1 { diff --git a/test/cli/smoke/namesapce/data.json b/test/cli/smoke/namesapce/data.json new file mode 100644 index 0000000000..e63d37b65a --- /dev/null +++ b/test/cli/smoke/namesapce/data.json @@ -0,0 +1,3 @@ +{ + "foo": "bar" +}