Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check that events are at least expected ones #3375

Merged
merged 1 commit into from
Oct 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 24 additions & 11 deletions test/cancel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"context"
"encoding/json"
"fmt"
"strings"
"sync"
"testing"

Expand Down Expand Up @@ -144,23 +145,35 @@ func TestTaskRunPipelineRunCancel(t *testing.T) {
trName = append(trName, taskrunItem.Name)
}

matchKinds := map[string][]string{"PipelineRun": {pipelineRun.Name}, "TaskRun": trName}
// Expected failure events: 1 for the pipelinerun cancel, 1 for each TaskRun
expectedNumberOfEvents := 1 + len(trName)
matchKinds := map[string][]string{"PipelineRun": {pipelineRun.Name}}
// Expected failure events: 1 for the pipelinerun cancel
expectedNumberOfEvents := 1
t.Logf("Making sure %d events were created from pipelinerun with kinds %v", expectedNumberOfEvents, matchKinds)
events, err := collectMatchingEvents(ctx, c.KubeClient, namespace, matchKinds, "Failed")
if err != nil {
t.Fatalf("Failed to collect matching events: %q", err)
}
if len(events) != expectedNumberOfEvents {
collectedEvents := ""
for i, event := range events {
collectedEvents += fmt.Sprintf("%#v", event)
if i < (len(events) - 1) {
collectedEvents += ", "
}
if len(events) < expectedNumberOfEvents {
afrittoli marked this conversation as resolved.
Show resolved Hide resolved
collectedEvents := make([]string, 0, len(events))
for _, event := range events {
collectedEvents = append(collectedEvents, fmt.Sprintf("%#v", event))
}
t.Fatalf("Expected %d number of failed events from pipelinerun but got %d; list of received events : %s", expectedNumberOfEvents, len(events), strings.Join(collectedEvents, ", "))
}
matchKinds = map[string][]string{"TaskRun": trName}
// Expected failure events: 1 for each TaskRun
expectedNumberOfEvents = len(trName)
t.Logf("Making sure %d events were created from taskruns with kinds %v", expectedNumberOfEvents, matchKinds)
events, err = collectMatchingEvents(ctx, c.KubeClient, namespace, matchKinds, "Failed")
if err != nil {
t.Fatalf("Failed to collect matching events: %q", err)
}
if len(events) < expectedNumberOfEvents {
collectedEvents := make([]string, 0, len(events))
for _, event := range events {
collectedEvents = append(collectedEvents, fmt.Sprintf("%#v", event))
}
t.Fatalf("Expected %d number of successful events from pipelinerun and taskrun but got %d; list of received events : %#v", expectedNumberOfEvents, len(events), collectedEvents)
t.Fatalf("Expected %d number of failed events from taskrun but got %d; list of received events : %s", expectedNumberOfEvents, len(events), strings.Join(collectedEvents, ", "))
}
})
}
Expand Down
35 changes: 24 additions & 11 deletions test/v1alpha1/cancel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"context"
"encoding/json"
"fmt"
"strings"
"sync"
"testing"

Expand Down Expand Up @@ -144,23 +145,35 @@ func TestTaskRunPipelineRunCancel(t *testing.T) {
for _, taskrunItem := range taskrunList.Items {
trName = append(trName, taskrunItem.Name)
}
matchKinds := map[string][]string{"PipelineRun": {pipelineRunName}, "TaskRun": trName}
// Expected failure events: 1 for the pipelinerun cancel, 1 for each TaskRun
expectedNumberOfEvents := 1 + len(trName)
matchKinds := map[string][]string{"PipelineRun": {pipelineRunName}}
// Expected failure events: 1 for the pipelinerun cancel
expectedNumberOfEvents := 1
t.Logf("Making sure %d events were created from pipelinerun with kinds %v", expectedNumberOfEvents, matchKinds)
events, err := collectMatchingEvents(ctx, c.KubeClient, namespace, matchKinds, "Failed")
if err != nil {
t.Fatalf("Failed to collect matching events: %q", err)
}
if len(events) != expectedNumberOfEvents {
collectedEvents := ""
for i, event := range events {
collectedEvents += fmt.Sprintf("%#v", event)
if i < (len(events) - 1) {
collectedEvents += ", "
}
if len(events) < expectedNumberOfEvents {
collectedEvents := make([]string, 0, len(events))
for _, event := range events {
collectedEvents = append(collectedEvents, fmt.Sprintf("%#v", event))
}
t.Fatalf("Expected %d number of failed events from pipelinerun but got %d; list of received events : %s", expectedNumberOfEvents, len(events), strings.Join(collectedEvents, ", "))
}
matchKinds = map[string][]string{"TaskRun": trName}
// Expected failure events: 1 for each TaskRun
expectedNumberOfEvents = len(trName)
t.Logf("Making sure %d events were created from taskruns with kinds %v", expectedNumberOfEvents, matchKinds)
events, err = collectMatchingEvents(ctx, c.KubeClient, namespace, matchKinds, "Failed")
if err != nil {
t.Fatalf("Failed to collect matching events: %q", err)
}
if len(events) < expectedNumberOfEvents {
collectedEvents := make([]string, 0, len(events))
for _, event := range events {
collectedEvents = append(collectedEvents, fmt.Sprintf("%#v", event))
}
t.Fatalf("Expected %d number of successful events from pipelinerun and taskrun but got %d; list of received events : %#v", expectedNumberOfEvents, len(events), collectedEvents)
t.Fatalf("Expected %d number of failed events from taskrun but got %d; list of received events : %s", expectedNumberOfEvents, len(events), strings.Join(collectedEvents, ", "))
}
})
}
Expand Down