-
Notifications
You must be signed in to change notification settings - Fork 182
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Laszlo Fogas <[email protected]>
- Loading branch information
Showing
1 changed file
with
16 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,32 @@ | ||
package controllers | ||
|
||
import ( | ||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
"sigs.k8s.io/controller-runtime/pkg/envtest/printer" | ||
"strings" | ||
"testing" | ||
) | ||
|
||
func TestUtils(t *testing.T) { | ||
RegisterFailHandler(Fail) | ||
|
||
RunSpecsWithDefaultAndCustomReporters(t, | ||
"Utils Suite", | ||
[]Reporter{printer.NewlineReporter{}}) | ||
} | ||
|
||
var _ = Describe("Utils", func() { | ||
Context("parseApplyError()", func() { | ||
|
||
When("the apply result contains unchanged/configured/created services", func() { | ||
It("should filter out service lines", func() { | ||
filtered := parseApplyError([]byte(` | ||
func Test_parseApplyError(t *testing.T) { | ||
filtered := parseApplyError([]byte(` | ||
gitrepository.source.toolkit.fluxcd.io/flux-workspaces unchanged | ||
ingressroute.traefik.containo.us/flux-receiver configured | ||
service/notification-controller created | ||
The Service "webhook-receiver" is invalid: spec.clusterIP: Invalid value: "10.200.133.61": field is immutable`)) | ||
filtered = strings.TrimSpace(filtered) | ||
Expect(len(strings.Split(filtered, "\n"))).To(Equal(1)) | ||
}) | ||
}) | ||
filtered = strings.TrimSpace(filtered) | ||
numLines := len(strings.Split(filtered, "\n")) | ||
if numLines != 1 { | ||
t.Errorf("Should filter out all but one line from the error output, numLines %d", numLines) | ||
} | ||
} | ||
|
||
When("the apply dry run contains unchanged/configured/created services", func() { | ||
It("should filter out service lines", func() { | ||
filtered := parseApplyError([]byte(` | ||
func Test_parseApplyError_dryRun(t *testing.T) { | ||
filtered := parseApplyError([]byte(` | ||
gitrepository.source.toolkit.fluxcd.io/flux-workspaces unchanged (dry run) | ||
ingressroute.traefik.containo.us/flux-receiver configured (dry run) | ||
service/notification-controller created (dry run) | ||
error: error validating data: unknown field "ima ge" in io.k8s.api.core.v1.Container`)) | ||
filtered = strings.TrimSpace(filtered) | ||
Expect(len(strings.Split(filtered, "\n"))).To(Equal(1)) | ||
}) | ||
}) | ||
}) | ||
}) | ||
filtered = strings.TrimSpace(filtered) | ||
numLines := len(strings.Split(filtered, "\n")) | ||
if numLines != 1 { | ||
t.Errorf("Should filter out all but one line from the error output, numLines %d", numLines) | ||
} | ||
} |