mirror of
https://github.com/open-policy-agent/opa.git
synced 2026-08-27 18:55:54 -06:00
b0100a66cd
And a few other small fixes in tests. This i not so much about performance but about choosing the best tool for a given task :) But that the alternatives are also faster doesn't hurt either. Signed-off-by: Anders Eknert <anders@styra.com>
42 lines
927 B
Go
42 lines
927 B
Go
// Copyright 2023 The OPA Authors. All rights reserved.
|
|
// Use of this source code is governed by an Apache2
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package pathwatcher
|
|
|
|
import (
|
|
"path/filepath"
|
|
"slices"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/open-policy-agent/opa/v1/util/test"
|
|
)
|
|
|
|
func TestWatchPaths(t *testing.T) {
|
|
|
|
fs := map[string]string{
|
|
"/foo/bar/baz.json": "true",
|
|
"/foo/faz/baz.json": "true",
|
|
"/foo/baz.json": "true",
|
|
}
|
|
|
|
expected := []string{
|
|
"/foo", "/foo/bar", "/foo/faz",
|
|
}
|
|
|
|
test.WithTempFS(fs, func(rootDir string) {
|
|
paths, err := getWatchPaths([]string{"prefix:" + rootDir + "/foo"})
|
|
if err != nil {
|
|
t.Fatalf("Unexpected error: %v", err)
|
|
}
|
|
result := []string{}
|
|
for _, p := range paths {
|
|
result = append(result, filepath.Clean(strings.TrimPrefix(p, rootDir)))
|
|
}
|
|
if !slices.Equal(expected, result) {
|
|
t.Fatalf("Expected %q but got: %q", expected, result)
|
|
}
|
|
})
|
|
}
|