Skip to content

Commit

Permalink
Check value of ok in tests
Browse files Browse the repository at this point in the history
To make sure we don't accidentally skip the comparison between want and
got
  • Loading branch information
bobcatfish committed Apr 22, 2020
1 parent 45ef5d7 commit d6c8235
Showing 1 changed file with 24 additions and 22 deletions.
46 changes: 24 additions & 22 deletions pkg/apis/pipeline/v1beta1/resultref_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,15 +148,16 @@ func TestNewResultReference(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
expressions, ok := v1beta1.GetVarSubstitutionExpressionsForParam(tt.args.param)
if ok {
got, err := v1beta1.NewResultRefs(expressions)
if tt.wantErr != (err != nil) {
t.Errorf("TestNewResultReference/%s wantErr %v, error = %v", tt.name, tt.wantErr, err)
return
}
if d := cmp.Diff(tt.want, got); d != "" {
t.Errorf("TestNewResultReference/%s (-want, +got) = %v", tt.name, d)
}
if !ok {
t.Fatalf("expected to find expressions but didn't find any")
}
got, err := v1beta1.NewResultRefs(expressions)
if tt.wantErr != (err != nil) {
t.Errorf("TestNewResultReference/%s wantErr %v, error = %v", tt.name, tt.wantErr, err)
return
}
if d := cmp.Diff(tt.want, got); d != "" {
t.Errorf("TestNewResultReference/%s (-want, +got) = %v", tt.name, d)
}
})
}
Expand Down Expand Up @@ -260,20 +261,21 @@ func TestHasResultReference(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
expressions, ok := v1beta1.GetVarSubstitutionExpressionsForParam(tt.args.param)
if ok {
got, _ := v1beta1.NewResultRefs(expressions)
sort.Slice(got, func(i, j int) bool {
if got[i].PipelineTask > got[j].PipelineTask {
return false
}
if got[i].Result > got[j].Result {
return false
}
return true
})
if d := cmp.Diff(tt.wantRef, got); d != "" {
t.Errorf("TestHasResultReference/%s (-want, +got) = %v", tt.name, d)
if !ok {
t.Fatalf("expected to find expressions but didn't find any")
}
got, _ := v1beta1.NewResultRefs(expressions)
sort.Slice(got, func(i, j int) bool {
if got[i].PipelineTask > got[j].PipelineTask {
return false
}
if got[i].Result > got[j].Result {
return false
}
return true
})
if d := cmp.Diff(tt.wantRef, got); d != "" {
t.Errorf("TestHasResultReference/%s (-want, +got) = %v", tt.name, d)
}
})
}
Expand Down

0 comments on commit d6c8235

Please sign in to comment.