Skip to content

Commit

Permalink
Confirm the right string is returned
Browse files Browse the repository at this point in the history
Signed-off-by: Kazuki Suda <kazuki.suda@gmail.com>
  • Loading branch information
superbrothers committed Apr 27, 2021
1 parent 178ae70 commit 4a45df2
Showing 1 changed file with 38 additions and 27 deletions.
65 changes: 38 additions & 27 deletions controllers/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,41 +5,52 @@ import (
"testing"
)

func Test_parseApplyError(t *testing.T) {
filtered := parseApplyError([]byte(`
func TestParseApply(t *testing.T) {
tests := []struct {
name string
in []byte
filtered string
}{
{
"apply",
[]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)
numLines := len(strings.Split(filtered, "\n"))
if numLines != 1 {
t.Errorf("Should filter out all but one line from the error output, but got %d lines", numLines)
}
}

func Test_parseApplyError_dryRun(t *testing.T) {
filtered := parseApplyError([]byte(`
The Service "webhook-receiver" is invalid: spec.clusterIP: Invalid value: "10.200.133.61": field is immutable
`),
`The Service "webhook-receiver" is invalid: spec.clusterIP: Invalid value: "10.200.133.61": field is immutable`,
},
{
"client dry-run",
[]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)
numLines := len(strings.Split(filtered, "\n"))
if numLines != 1 {
t.Errorf("Should filter out all but one line from the error output, but got %d lines", numLines)
}
}

func Test_parseApplyError_serverDryRun(t *testing.T) {
filtered := parseApplyError([]byte(`
error: error validating data: unknown field "ima ge" in io.k8s.api.core.v1.Container
`),
`error: error validating data: unknown field "ima ge" in io.k8s.api.core.v1.Container`,
},
{
"server dry-run",
[]byte(`
gitrepository.source.toolkit.fluxcd.io/flux-workspaces unchanged (server dry run)
ingressroute.traefik.containo.us/flux-receiver configured (server dry run)
service/notification-controller created (server dry run)
error: error validating data: unknown field "ima ge" in io.k8s.api.core.v1.Container`))
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, but got %d lines", numLines)
error: error validating data: unknown field "ima ge" in io.k8s.api.core.v1.Container
`),
`error: error validating data: unknown field "ima ge" in io.k8s.api.core.v1.Container`,
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
filtered := parseApplyError(tt.in)
filtered = strings.TrimSpace(filtered)

if tt.filtered != filtered {
t.Errorf("expected %q, but actual %q", tt.filtered, filtered)
}
})
}
}

0 comments on commit 4a45df2

Please sign in to comment.