-
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.
Extracting validation error from apply dry run output
Signed-off-by: Laszlo Fogas <laszlo@laszlo.cloud>
- Loading branch information
Showing
3 changed files
with
37 additions
and
2 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
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
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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package controllers | ||
|
||
import ( | ||
"strings" | ||
"testing" | ||
) | ||
|
||
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) | ||
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(` | ||
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) | ||
} | ||
} |