Skip to content

Commit

Permalink
wip: only parse if validjsonpath
Browse files Browse the repository at this point in the history
  • Loading branch information
dibyom committed Nov 27, 2019
1 parent 85eb6a3 commit 2d6d96b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 20 deletions.
7 changes: 7 additions & 0 deletions pkg/template/jsonpath.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ func ParseJSONPath(input interface{}, expr string) (string, error) {
return "", err
}

// Copy of j.PrintResults
for ix := range fullResults {
if err := printResults(buf, fullResults[ix]); err != nil {
return "", err
Expand All @@ -85,6 +86,12 @@ func removeTektonVar(expr string) string {
return tektonVar.ReplaceAllString(expr, "$1")
}

// IsTektonJSONPath returns true if the expr is a valid JSONPath expression
// that is wrapped in the Tekton
func IsTektonJSONPath(expr string) {
// FIXME
}

// PrintResults writes the results into writer
// This is a copy of the original j.PrintResults
// in that it uses the modified evalToText function below
Expand Down
28 changes: 8 additions & 20 deletions pkg/template/jsonpath_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,38 +51,26 @@ func TestParseJSONPath_JSONStrings(t *testing.T) {
if diff := cmp.Diff(got, tt.want); diff != "" {
t.Errorf("ParseJSONPath() -got,+want: %s", diff)
}

fmt.Println("GOT")
fmt.Println(got)
fmt.Println("WANT")
fmt.Println(tt.want)
fmt.Println("")
})
}
}

// Tests for RelaxedJSONPath + TektonJSONPath
//


func TestTektonJSONPathExpression(t *testing.T) {
type args struct {
expr string
}
tests := []struct {
name string
args args
expr string
want string
wantErr bool
}{
// TODO: Add test cases.
{"$(metadata.name)", "{.metadata.name}", false},
{"$(.metadata.name)", "{.metadata.name}", false},
{"$({.metadata.name})", "{.metadata.name}", false},
{"{.metadata.name}", "", true},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := TektonJSONPathExpression(tt.args.expr)
t.Run(tt.expr, func(t *testing.T) {
got, err := TektonJSONPathExpression(tt.expr)
if (err != nil) != tt.wantErr {
t.Errorf("TektonJSONPathExpression() error = %v, wantErr %v", err, tt.wantErr)
return
t.Errorf("TektonJSONPathExpression() error = %v, wantErr %v, got = %v", err, tt.wantErr, got)
}
if got != tt.want {
t.Errorf("TektonJSONPathExpression() got = %v, want %v", got, tt.want)
Expand Down

0 comments on commit 2d6d96b

Please sign in to comment.