Skip to content

Commit

Permalink
Simplify tests; using go std lib
Browse files Browse the repository at this point in the history
  • Loading branch information
laszlocph committed Feb 19, 2021
1 parent 912f122 commit c610422
Showing 1 changed file with 16 additions and 30 deletions.
46 changes: 16 additions & 30 deletions controllers/utils_test.go
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)
}
}

0 comments on commit c610422

Please sign in to comment.