Skip to content

Commit

Permalink
add possible error message patterns
Browse files Browse the repository at this point in the history
Signed-off-by: akihikokuroda <akihikokuroda2020@gmail.com>
  • Loading branch information
akihikokuroda committed Jan 11, 2022
1 parent e6428a1 commit 52f0359
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions pkg/controller/registry/resolver/resolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"errors"
"fmt"
"math/rand"
"strings"
"testing"
"time"

Expand Down Expand Up @@ -108,7 +109,7 @@ func TestSolveOperators_WithSystemConstraints(t *testing.T) {
csvs []*v1alpha1.ClusterServiceVersion
subs []*v1alpha1.Subscription
snapshotEntries []*cache.Entry
err string
err []string
}{
{
title: "No runtime constraints",
Expand All @@ -117,7 +118,7 @@ func TestSolveOperators_WithSystemConstraints(t *testing.T) {
expectedOperators: cache.OperatorSet{"packageA.v1": packageA, "packageB.v1": packageB},
csvs: nil,
subs: []*v1alpha1.Subscription{packageASub},
err: "",
err: nil,
},
{
title: "Runtime constraints only accept packages A and C",
Expand All @@ -126,7 +127,7 @@ func TestSolveOperators_WithSystemConstraints(t *testing.T) {
expectedOperators: cache.OperatorSet{"packageA.v1": packageA, "packageC.v1": packageC},
csvs: nil,
subs: []*v1alpha1.Subscription{packageASub},
err: "",
err: nil,
},
{
title: "Existing packages are ignored",
Expand All @@ -135,7 +136,7 @@ func TestSolveOperators_WithSystemConstraints(t *testing.T) {
expectedOperators: cache.OperatorSet{"packageA.v1": packageA, "packageC.v1": packageC},
csvs: []*v1alpha1.ClusterServiceVersion{existingPackageD},
subs: []*v1alpha1.Subscription{packageASub, packageDSub},
err: "",
err: nil,
},
{
title: "Runtime constraints don't allow A",
Expand All @@ -144,7 +145,7 @@ func TestSolveOperators_WithSystemConstraints(t *testing.T) {
expectedOperators: nil,
csvs: nil,
subs: []*v1alpha1.Subscription{packageASub},
err: "packageA is not white listed",
err: []string{"packageA is not white listed", "packageB is not white listed"},
},
}

Expand All @@ -159,9 +160,14 @@ func TestSolveOperators_WithSystemConstraints(t *testing.T) {
systemConstraintsProvider: testCase.systemConstraintsProvider,
}
operators, err := satResolver.SolveOperators([]string{namespace}, testCase.csvs, testCase.subs)

if testCase.err != "" {
require.Containsf(t, err.Error(), testCase.err, "Test %s failed", testCase.title)
if testCase.err != nil {
found := false
for _, msg := range testCase.err {
if strings.Contains(err.Error(), msg) {
found = true
}
}
require.True(t, found, "Test %s failed", testCase.title)
} else {
require.NoErrorf(t, err, "Test %s failed", testCase.title)
}
Expand Down

0 comments on commit 52f0359

Please sign in to comment.