Fix 'flux get all --status-selector' for empty results
Signed-off-by: Matheus Pimenta <matheuscscp@gmail.com>
This commit is contained in:
@@ -207,6 +207,9 @@ func (get getCommand) run(cmd *cobra.Command, args []string) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
if getAll && len(rows) == 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
err = printers.TablePrinter(header).Print(cmd.OutOrStdout(), rows)
|
err = printers.TablePrinter(header).Print(cmd.OutOrStdout(), rows)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -103,6 +103,68 @@ func Test_GetCmdStatusSelector(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Test_GetAllCmdStatusSelectorNoMatches(t *testing.T) {
|
||||||
|
tmpl := map[string]string{
|
||||||
|
"fluxns": allocateNamespace("flux-system"),
|
||||||
|
}
|
||||||
|
testEnv.CreateObjectFile("./testdata/get/status_objects.yaml", tmpl, t)
|
||||||
|
|
||||||
|
cmd := cmdTestCase{
|
||||||
|
args: "get all --status-selector foo=bar -n " + tmpl["fluxns"],
|
||||||
|
assert: assertGoldenValue(""),
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd.runTestCmd(t)
|
||||||
|
}
|
||||||
|
|
||||||
|
func Test_GetAllCmdStatusSelectorKustomizationOnlyMatches(t *testing.T) {
|
||||||
|
tmpl := map[string]string{
|
||||||
|
"fluxns": allocateNamespace("flux-system"),
|
||||||
|
}
|
||||||
|
testEnv.CreateObjectFile("./testdata/get/kustomization_only.yaml", tmpl, t)
|
||||||
|
|
||||||
|
unfilteredOutput, err := executeCommand("get all -n " + tmpl["fluxns"])
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("get all failed: %v", err)
|
||||||
|
}
|
||||||
|
if unfilteredOutput == "" {
|
||||||
|
t.Fatal("expected get all output for namespace with one Kustomization")
|
||||||
|
}
|
||||||
|
|
||||||
|
filteredOutput, err := executeCommand("get all --status-selector Ready=True -n " + tmpl["fluxns"])
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("get all with matching status selector failed: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if filteredOutput != unfilteredOutput {
|
||||||
|
t.Fatalf("expected filtered output to match unfiltered output:\nfiltered:\n%s\nunfiltered:\n%s", filteredOutput, unfilteredOutput)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func Test_GetAllCmdStatusSelectorKustomizationOnlyNoMatch(t *testing.T) {
|
||||||
|
tmpl := map[string]string{
|
||||||
|
"fluxns": allocateNamespace("flux-system"),
|
||||||
|
}
|
||||||
|
testEnv.CreateObjectFile("./testdata/get/kustomization_only.yaml", tmpl, t)
|
||||||
|
|
||||||
|
emptyNamespace := allocateNamespace("empty")
|
||||||
|
setupTestNamespace(emptyNamespace, t)
|
||||||
|
|
||||||
|
emptyOutput, err := executeCommand("get all -n " + emptyNamespace)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("get all in empty namespace failed: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
filteredOutput, err := executeCommand("get all --status-selector Ready=False -n " + tmpl["fluxns"])
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("get all with non-matching status selector failed: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if filteredOutput != emptyOutput {
|
||||||
|
t.Fatalf("expected filtered output to match empty namespace output:\nfiltered:\n%s\nempty namespace:\n%s", filteredOutput, emptyOutput)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func Test_GetCmdErrors(t *testing.T) {
|
func Test_GetCmdErrors(t *testing.T) {
|
||||||
tmpl := map[string]string{
|
tmpl := map[string]string{
|
||||||
"fluxns": allocateNamespace("flux-system"),
|
"fluxns": allocateNamespace("flux-system"),
|
||||||
|
|||||||
+26
@@ -0,0 +1,26 @@
|
|||||||
|
---
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Namespace
|
||||||
|
metadata:
|
||||||
|
name: {{ .fluxns }}
|
||||||
|
---
|
||||||
|
apiVersion: kustomize.toolkit.fluxcd.io/v1
|
||||||
|
kind: Kustomization
|
||||||
|
metadata:
|
||||||
|
name: podinfo
|
||||||
|
namespace: {{ .fluxns }}
|
||||||
|
spec:
|
||||||
|
interval: 5m
|
||||||
|
path: ./clusters/production
|
||||||
|
prune: true
|
||||||
|
sourceRef:
|
||||||
|
kind: GitRepository
|
||||||
|
name: podinfo
|
||||||
|
status:
|
||||||
|
lastAppliedRevision: main@sha1:696f056df216eea4f9401adbee0ff744d4df390f
|
||||||
|
conditions:
|
||||||
|
- lastTransitionTime: "2021-08-01T04:52:56Z"
|
||||||
|
message: 'Applied revision: main@sha1:696f056df216eea4f9401adbee0ff744d4df390f'
|
||||||
|
reason: ReconciliationSucceeded
|
||||||
|
status: "True"
|
||||||
|
type: Ready
|
||||||
Reference in New Issue
Block a user