Skip to content

Commit

Permalink
Fix opa inspect data namespaces on windows
Browse files Browse the repository at this point in the history
Signed-off-by: shm12 <[email protected]>
  • Loading branch information
shm12 committed Dec 28, 2022
1 parent 9bd1bfb commit a6204a7
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
12 changes: 12 additions & 0 deletions build/binary-smoke-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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::"
5 changes: 3 additions & 2 deletions internal/bundle/inspect/inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"bytes"
"fmt"
"io"
"os"
"path/filepath"
"strings"

Expand Down Expand Up @@ -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 {
Expand Down
3 changes: 3 additions & 0 deletions test/cli/smoke/namesapce/data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"foo": "bar"
}

0 comments on commit a6204a7

Please sign in to comment.