Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update get subcommand column order #2467

Merged
merged 3 commits into from
Feb 28, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,13 @@ Then you can run the end-to-end tests with:
make e2e
```

When the output of the Flux CLI changes, to automatically update the golden
files used in the test, pass `-update` flag to the test as:

```bash
make e2e TEST_ARGS="-update"
```

Teardown the e2e environment with:

```bash
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ test: $(EMBEDDED_MANIFESTS_TARGET) tidy fmt vet install-envtest
KUBEBUILDER_ASSETS="$(KUBEBUILDER_ASSETS)" go test ./... -coverprofile cover.out --tags=unit

e2e: $(EMBEDDED_MANIFESTS_TARGET) tidy fmt vet
TEST_KUBECONFIG=$(TEST_KUBECONFIG) go test ./cmd/flux/... -coverprofile e2e.cover.out --tags=e2e -v -failfast
TEST_KUBECONFIG=$(TEST_KUBECONFIG) go test ./cmd/flux/... -coverprofile e2e.cover.out --tags=e2e -v -failfast $(TEST_ARGS)

test-with-kind: install-envtest
make setup-kind
Expand Down
4 changes: 2 additions & 2 deletions cmd/flux/get_alert.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,11 @@ func init() {
func (s alertListAdapter) summariseItem(i int, includeNamespace bool, includeKind bool) []string {
item := s.Items[i]
status, msg := statusAndMessage(item.Status.Conditions)
return append(nameColumns(&item, includeNamespace, includeKind), status, msg, strings.Title(strconv.FormatBool(item.Spec.Suspend)))
return append(nameColumns(&item, includeNamespace, includeKind), strings.Title(strconv.FormatBool(item.Spec.Suspend)), status, msg)
}

func (s alertListAdapter) headers(includeNamespace bool) []string {
headers := []string{"Name", "Ready", "Message", "Suspended"}
headers := []string{"Name", "Suspended", "Ready", "Message"}
if includeNamespace {
return append(namespaceHeader, headers...)
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/flux/get_helmrelease.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,11 @@ func (a helmReleaseListAdapter) summariseItem(i int, includeNamespace bool, incl
revision := item.Status.LastAppliedRevision
status, msg := statusAndMessage(item.Status.Conditions)
return append(nameColumns(&item, includeNamespace, includeKind),
status, msg, revision, strings.Title(strconv.FormatBool(item.Spec.Suspend)))
revision, strings.Title(strconv.FormatBool(item.Spec.Suspend)), status, msg)
}

func (a helmReleaseListAdapter) headers(includeNamespace bool) []string {
headers := []string{"Name", "Ready", "Message", "Revision", "Suspended"}
headers := []string{"Name", "Revision", "Suspended", "Ready", "Message"}
if includeNamespace {
headers = append([]string{"Namespace"}, headers...)
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/flux/get_image_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,11 @@ func init() {
func (s imagePolicyListAdapter) summariseItem(i int, includeNamespace bool, includeKind bool) []string {
item := s.Items[i]
status, msg := statusAndMessage(item.Status.Conditions)
return append(nameColumns(&item, includeNamespace, includeKind), status, msg, item.Status.LatestImage)
return append(nameColumns(&item, includeNamespace, includeKind), item.Status.LatestImage, status, msg)
}

func (s imagePolicyListAdapter) headers(includeNamespace bool) []string {
headers := []string{"Name", "Ready", "Message", "Latest image"}
headers := []string{"Name", "Latest image", "Ready", "Message"}
if includeNamespace {
return append(namespaceHeader, headers...)
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/flux/get_image_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,11 @@ func (s imageRepositoryListAdapter) summariseItem(i int, includeNamespace bool,
lastScan = item.Status.LastScanResult.ScanTime.Time.Format(time.RFC3339)
}
return append(nameColumns(&item, includeNamespace, includeKind),
status, msg, lastScan, strings.Title(strconv.FormatBool(item.Spec.Suspend)))
lastScan, strings.Title(strconv.FormatBool(item.Spec.Suspend)), status, msg)
}

func (s imageRepositoryListAdapter) headers(includeNamespace bool) []string {
headers := []string{"Name", "Ready", "Message", "Last scan", "Suspended"}
headers := []string{"Name", "Last scan", "Suspended", "Ready", "Message"}
if includeNamespace {
return append(namespaceHeader, headers...)
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/flux/get_image_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,11 @@ func (s imageUpdateAutomationListAdapter) summariseItem(i int, includeNamespace
if item.Status.LastAutomationRunTime != nil {
lastRun = item.Status.LastAutomationRunTime.Time.Format(time.RFC3339)
}
return append(nameColumns(&item, includeNamespace, includeKind), status, msg, lastRun, strings.Title(strconv.FormatBool(item.Spec.Suspend)))
return append(nameColumns(&item, includeNamespace, includeKind), lastRun, strings.Title(strconv.FormatBool(item.Spec.Suspend)), status, msg)
}

func (s imageUpdateAutomationListAdapter) headers(includeNamespace bool) []string {
headers := []string{"Name", "Ready", "Message", "Last run", "Suspended"}
headers := []string{"Name", "Last run", "Suspended", "Ready", "Message"}
if includeNamespace {
return append(namespaceHeader, headers...)
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/flux/get_kustomization.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,11 @@ func (a kustomizationListAdapter) summariseItem(i int, includeNamespace bool, in
msg = shortenCommitSha(msg)
}
return append(nameColumns(&item, includeNamespace, includeKind),
status, msg, revision, strings.Title(strconv.FormatBool(item.Spec.Suspend)))
revision, strings.Title(strconv.FormatBool(item.Spec.Suspend)), status, msg)
}

func (a kustomizationListAdapter) headers(includeNamespace bool) []string {
headers := []string{"Name", "Ready", "Message", "Revision", "Suspended"}
headers := []string{"Name", "Revision", "Suspended", "Ready", "Message"}
if includeNamespace {
headers = append([]string{"Namespace"}, headers...)
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/flux/get_receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,11 @@ func init() {
func (s receiverListAdapter) summariseItem(i int, includeNamespace bool, includeKind bool) []string {
item := s.Items[i]
status, msg := statusAndMessage(item.Status.Conditions)
return append(nameColumns(&item, includeNamespace, includeKind), status, msg, strings.Title(strconv.FormatBool(item.Spec.Suspend)))
return append(nameColumns(&item, includeNamespace, includeKind), strings.Title(strconv.FormatBool(item.Spec.Suspend)), status, msg)
}

func (s receiverListAdapter) headers(includeNamespace bool) []string {
headers := []string{"Name", "Ready", "Message", "Suspended"}
headers := []string{"Name", "Suspended", "Ready", "Message"}
if includeNamespace {
return append(namespaceHeader, headers...)
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/flux/get_source_bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,11 @@ func (a *bucketListAdapter) summariseItem(i int, includeNamespace bool, includeK
}
status, msg := statusAndMessage(item.Status.Conditions)
return append(nameColumns(&item, includeNamespace, includeKind),
status, msg, revision, strings.Title(strconv.FormatBool(item.Spec.Suspend)))
revision, strings.Title(strconv.FormatBool(item.Spec.Suspend)), status, msg)
}

func (a bucketListAdapter) headers(includeNamespace bool) []string {
headers := []string{"Name", "Ready", "Message", "Revision", "Suspended"}
headers := []string{"Name", "Revision", "Suspended", "Ready", "Message"}
if includeNamespace {
headers = append([]string{"Namespace"}, headers...)
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/flux/get_source_chart.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,11 @@ func (a *helmChartListAdapter) summariseItem(i int, includeNamespace bool, inclu
}
status, msg := statusAndMessage(item.Status.Conditions)
return append(nameColumns(&item, includeNamespace, includeKind),
status, msg, revision, strings.Title(strconv.FormatBool(item.Spec.Suspend)))
revision, strings.Title(strconv.FormatBool(item.Spec.Suspend)), status, msg)
}

func (a helmChartListAdapter) headers(includeNamespace bool) []string {
headers := []string{"Name", "Ready", "Message", "Revision", "Suspended"}
headers := []string{"Name", "Revision", "Suspended", "Ready", "Message"}
if includeNamespace {
headers = append([]string{"Namespace"}, headers...)
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/flux/get_source_git.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,11 @@ func (a *gitRepositoryListAdapter) summariseItem(i int, includeNamespace bool, i
msg = shortenCommitSha(msg)
}
return append(nameColumns(&item, includeNamespace, includeKind),
status, msg, revision, strings.Title(strconv.FormatBool(item.Spec.Suspend)))
revision, strings.Title(strconv.FormatBool(item.Spec.Suspend)), status, msg)
}

func (a gitRepositoryListAdapter) headers(includeNamespace bool) []string {
headers := []string{"Name", "Ready", "Message", "Revision", "Suspended"}
headers := []string{"Name", "Revision", "Suspended", "Ready", "Message"}
if includeNamespace {
headers = append([]string{"Namespace"}, headers...)
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/flux/get_source_helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,11 @@ func (a *helmRepositoryListAdapter) summariseItem(i int, includeNamespace bool,
}
status, msg := statusAndMessage(item.Status.Conditions)
return append(nameColumns(&item, includeNamespace, includeKind),
status, msg, revision, strings.Title(strconv.FormatBool(item.Spec.Suspend)))
revision, strings.Title(strconv.FormatBool(item.Spec.Suspend)), status, msg)
}

func (a helmRepositoryListAdapter) headers(includeNamespace bool) []string {
headers := []string{"Name", "Ready", "Message", "Revision", "Suspended"}
headers := []string{"Name", "Revision", "Suspended", "Ready", "Message"}
if includeNamespace {
headers = append([]string{"Namespace"}, headers...)
}
Expand Down
11 changes: 11 additions & 0 deletions cmd/flux/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"bufio"
"bytes"
"context"
"flag"
"fmt"
"io"
"os"
Expand All @@ -42,6 +43,9 @@ import (

var nextNamespaceId int64

// update allows golden files to be updated based on the current output.
var update = flag.Bool("update", false, "update golden files")

// Return a unique namespace with the specified prefix, for tests to create
// objects that won't collide with each other.
func allocateNamespace(prefix string) string {
Expand Down Expand Up @@ -298,6 +302,13 @@ func assertGoldenTemplateFile(goldenFile string, templateValues map[string]strin
expectedOutput = string(goldenFileContents)
}
if assertErr := assertGoldenValue(expectedOutput)(output, err); assertErr != nil {
// Update the golden files if comparision fails and the update flag is set.
if *update && output != "" {
if err := os.WriteFile(goldenFile, []byte(output), 0644); err != nil {
stefanprodan marked this conversation as resolved.
Show resolved Hide resolved
return fmt.Errorf("failed to update golden file '%s': %v", goldenFile, err)
}
return nil
}
return fmt.Errorf("Mismatch from golden file '%s': %v", goldenFile, assertErr)
}
return nil
Expand Down
4 changes: 2 additions & 2 deletions cmd/flux/testdata/helmrelease/get_helmrelease_from_git.golden
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
NAME READY MESSAGE REVISION SUSPENDED
thrfg True Release reconciliation succeeded 6.0.0 False
NAME REVISION SUSPENDED READY MESSAGE
thrfg 6.0.0 False True Release reconciliation succeeded
4 changes: 2 additions & 2 deletions cmd/flux/testdata/image/get_image_policy_regex.golden
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
NAME READY MESSAGE LATEST IMAGE
podinfo-regex True Latest image tag for 'ghcr.io/stefanprodan/podinfo' resolved to: 5.0.0 ghcr.io/stefanprodan/podinfo:5.0.0
NAME LATEST IMAGE READY MESSAGE
podinfo-regex ghcr.io/stefanprodan/podinfo:5.0.0 True Latest image tag for 'ghcr.io/stefanprodan/podinfo' resolved to: 5.0.0
4 changes: 2 additions & 2 deletions cmd/flux/testdata/image/get_image_policy_semver.golden
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
NAME READY MESSAGE LATEST IMAGE
podinfo-semver True Latest image tag for 'ghcr.io/stefanprodan/podinfo' resolved to: 5.0.3 ghcr.io/stefanprodan/podinfo:5.0.3
NAME LATEST IMAGE READY MESSAGE
podinfo-semver ghcr.io/stefanprodan/podinfo:5.0.3 True Latest image tag for 'ghcr.io/stefanprodan/podinfo' resolved to: 5.0.3
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
NAME READY MESSAGE REVISION SUSPENDED
tkfg True Applied revision: 6.0.0/627d5c4 6.0.0/627d5c4 False
NAME REVISION SUSPENDED READY MESSAGE
tkfg 6.0.0/627d5c4 False True Applied revision: 6.0.0/627d5c4