Skip to content

Commit

Permalink
Fix flakey detection tests
Browse files Browse the repository at this point in the history
Signed-off-by: Stephen Levine <stephen.levine@gmail.com>
  • Loading branch information
sclevine committed Jul 26, 2019
1 parent 723079f commit 6e07d44
Showing 1 changed file with 33 additions and 11 deletions.
44 changes: 33 additions & 11 deletions detector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"log"
"os"
"path/filepath"
"reflect"
"strings"
"testing"

Expand Down Expand Up @@ -102,8 +103,8 @@ func testDetector(t *testing.T, when spec.G, it spec.S) {
t.Fatalf("Unexpected group:\n%s\n", s)
}

if s := cmp.Diff(plan.Entries, []lifecycle.BuildPlanEntry(nil)); s != "" {
t.Fatalf("Unexpected :\n%s\n", s)
if !hasEntries(plan.Entries, []lifecycle.BuildPlanEntry(nil)) {
t.Fatalf("Unexpected entries:\n%+v\n", plan.Entries)
}

if s := outLog.String(); !strings.HasSuffix(s,
Expand Down Expand Up @@ -191,7 +192,7 @@ func testDetector(t *testing.T, when spec.G, it spec.S) {
t.Fatalf("Unexpected group:\n%s\n", s)
}

if s := cmp.Diff(plan.Entries, []lifecycle.BuildPlanEntry{
if !hasEntries(plan.Entries, []lifecycle.BuildPlanEntry{
{
Providers: []lifecycle.Buildpack{
{ID: "A", Version: "v1"},
Expand All @@ -207,8 +208,8 @@ func testDetector(t *testing.T, when spec.G, it spec.S) {
},
Requires: []lifecycle.Require{{Name: "dep2"}, {Name: "dep2"}, {Name: "dep2"}},
},
}); s != "" {
t.Fatalf("Unexpected results:\n%s\n", s)
}) {
t.Fatalf("Unexpected entries:\n%+v\n", plan.Entries)
}

if s := outLog.String(); !strings.HasSuffix(s,
Expand Down Expand Up @@ -305,13 +306,13 @@ func testDetector(t *testing.T, when spec.G, it spec.S) {
t.Fatalf("Unexpected group:\n%s\n", s)
}

if s := cmp.Diff(plan.Entries, []lifecycle.BuildPlanEntry{
if !hasEntries(plan.Entries, []lifecycle.BuildPlanEntry{
{
Providers: []lifecycle.Buildpack{{ID: "B", Version: "v1"}},
Requires: []lifecycle.Require{{Name: "dep-present"}},
},
}); s != "" {
t.Fatalf("Unexpected results:\n%s\n", s)
}) {
t.Fatalf("Unexpected entries:\n%+v\n", plan.Entries)
}

if s := outLog.String(); !strings.HasSuffix(s,
Expand Down Expand Up @@ -371,7 +372,7 @@ func testDetector(t *testing.T, when spec.G, it spec.S) {
t.Fatalf("Unexpected group:\n%s\n", s)
}

if s := cmp.Diff(plan.Entries, []lifecycle.BuildPlanEntry{
if !hasEntries(plan.Entries, []lifecycle.BuildPlanEntry{
{
Providers: []lifecycle.Buildpack{{ID: "A", Version: "v1"}},
Requires: []lifecycle.Require{{Name: "dep1-present"}},
Expand All @@ -380,8 +381,8 @@ func testDetector(t *testing.T, when spec.G, it spec.S) {
Providers: []lifecycle.Buildpack{{ID: "C", Version: "v1"}},
Requires: []lifecycle.Require{{Name: "dep6-present"}},
},
}); s != "" {
t.Fatalf("Unexpected :\n%s\n", s)
}) {
t.Fatalf("Unexpected entries:\n%+v\n", plan.Entries)
}

if s := outLog.String(); !strings.HasSuffix(s,
Expand All @@ -397,6 +398,27 @@ func testDetector(t *testing.T, when spec.G, it spec.S) {
})
}

func hasEntry(l []lifecycle.BuildPlanEntry, entry lifecycle.BuildPlanEntry) bool {
for _, e := range l {
if reflect.DeepEqual(e, entry) {
return true
}
}
return false
}

func hasEntries(a, b []lifecycle.BuildPlanEntry) bool {
if len(a) != len(b) {
return false
}
for _, e := range a {
if !hasEntry(b, e) {
return false
}
}
return true
}

const outputFailureEv1 = `
======== Output: A@v1 ========
detect out: A@v1
Expand Down

0 comments on commit 6e07d44

Please sign in to comment.