github.com/redhat-appstudio/e2e-tests@v0.0.0-20240520140907-9709f6f59323/pkg/utils/tekton/matchers_test.go (about)

     1  package tekton
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/assert"
     7  	pipeline "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1"
     8  )
     9  
    10  func TestTaskRunResultMatcherStringValue(t *testing.T) {
    11  	match, err := MatchTaskRunResult("a", "b").Match(pipeline.TaskRunResult{
    12  		Name:  "a",
    13  		Value: *pipeline.NewStructuredValues("b"),
    14  	})
    15  
    16  	assert.True(t, match)
    17  	assert.Nil(t, err)
    18  }
    19  
    20  func TestTaskRunResultMatcherJSONValue(t *testing.T) {
    21  	match, err := MatchTaskRunResultWithJSONValue("a", `{"b":1}`).Match(pipeline.TaskRunResult{
    22  		Name:  "a",
    23  		Value: *pipeline.NewStructuredValues(`{ "b" : 1 }`),
    24  	})
    25  
    26  	assert.True(t, match)
    27  	assert.Nil(t, err)
    28  }
    29  
    30  func TestMatchTaskRunResultWithJSONPathValue(t *testing.T) {
    31  	match, err := MatchTaskRunResultWithJSONPathValue("a", "{$.c[0].d}", "[2]").Match(pipeline.TaskRunResult{
    32  		Name:  "a",
    33  		Value: *pipeline.NewStructuredValues(`{"b":1, "c": [{"d": 2}]}`),
    34  	})
    35  
    36  	assert.True(t, match)
    37  	assert.Nil(t, err)
    38  }
    39  
    40  func TestMatchTaskRunResultWithJSONPathValueMultiple(t *testing.T) {
    41  	match, err := MatchTaskRunResultWithJSONPathValue("a", "{$.c[*].d}", "[2, 1]").Match(pipeline.TaskRunResult{
    42  		Name:  "a",
    43  		Value: *pipeline.NewStructuredValues(`{"b":1, "c": [{"d": 2}, {"d": 1}]}`),
    44  	})
    45  
    46  	assert.True(t, match)
    47  	assert.Nil(t, err)
    48  }