-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Abhishek Sharma <[email protected]>
- Loading branch information
1 parent
2fc37cb
commit 10ea8e5
Showing
9 changed files
with
721 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/* | ||
| Protect your secrets, protect your sensitive data. | ||
: Explore VMware Secrets Manager docs at https://vsecm.com/ | ||
</ | ||
<>/ keep your secrets... secret | ||
>/ | ||
<>/' Copyright 2023-present VMware Secrets Manager contributors. | ||
>/' SPDX-License-Identifier: BSD-2-Clause | ||
*/ | ||
|
||
package filter | ||
|
||
import ( | ||
"errors" | ||
"reflect" | ||
"testing" | ||
) | ||
|
||
func TestValueFromPath(t *testing.T) { | ||
type args struct { | ||
data any | ||
path string | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
want any | ||
wantErr error | ||
}{ | ||
{ | ||
name: "empty path", | ||
args: args{path: "", data: ""}, | ||
want: "", | ||
wantErr: nil, | ||
}, | ||
{ | ||
name: "path without dotted notation", | ||
args: args{path: "samplePath", data: "sampleData"}, | ||
want: "sampleData", | ||
wantErr: nil, | ||
}, | ||
{ | ||
name: "path with dotted notation, valid data", | ||
args: args{path: "path1.path2", data: map[string]interface{}{"path1": map[string]interface{}{"path2": "data"}}}, | ||
want: "data", | ||
wantErr: nil, | ||
}, | ||
{ | ||
name: "path with dotted notation, invalid key", | ||
args: args{path: "invalidPath.path2", data: map[string]interface{}{"path1": map[string]interface{}{"path2": "data"}}}, | ||
want: nil, | ||
wantErr: errors.New("key not found: invalidPath"), | ||
}, | ||
{ | ||
name: "path with dotted notation, array type data", | ||
args: args{path: "path1.path2", data: map[string]interface{}{"path1": []interface{}{"data"}}}, | ||
want: nil, | ||
wantErr: errors.New("arrays are not supported in path queries"), | ||
}, | ||
{ | ||
name: "path with dotted notation, invalid data", | ||
args: args{path: "path1.path2", data: map[string]interface{}{"path1": "data"}}, | ||
want: nil, | ||
wantErr: errors.New("cannot navigate further from data"), | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
got, err := ValueFromPath(tt.args.data, tt.args.path) | ||
if !reflect.DeepEqual(err, tt.wantErr) { | ||
t.Errorf("ValueFromPath() error = %v, wantErr %v", err, tt.wantErr) | ||
return | ||
} | ||
if !reflect.DeepEqual(got, tt.want) { | ||
t.Errorf("ValueFromPath() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.