|
| 1 | +package cmd |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + // "fmt" |
| 6 | + // "bytes" |
| 7 | +) |
| 8 | + |
| 9 | +// No Flag config |
| 10 | +func TestConfigNoFlags(t *testing.T){ |
| 11 | + cmd := &ConfigCmd{} |
| 12 | + output := CaptureOutput(func(){ |
| 13 | + _ = cmd.Run() |
| 14 | + }) |
| 15 | + if want := "No config action specified. Use --help for options."; !contains(output, want){ |
| 16 | + t.Errorf("expected output to contain %q, got %q", want, output) |
| 17 | + } |
| 18 | +} |
| 19 | + |
| 20 | +// Set Default Cluster to tt-gpu-cluster-1 |
| 21 | +func TestConfigDefaultCluster(t *testing.T){ |
| 22 | + cmd := &ConfigCmd{DefaultCluster: "tt-gpu-cluster-1"} // Create config object |
| 23 | + |
| 24 | + output := CaptureOutput(func(){ |
| 25 | + _ = cmd.Run() |
| 26 | + }) |
| 27 | + |
| 28 | + // fmt.Printf("Captured the output: %s\n", output) |
| 29 | + |
| 30 | + if want := "Setting default cluster to: tt-gpu-cluster-1"; !contains(output, want) { |
| 31 | + t.Errorf("expected output to contain %q, got %q", want, output) |
| 32 | + } |
| 33 | +} |
| 34 | + |
| 35 | +// Show Config |
| 36 | +func TestConfigCmd_Show(t *testing.T){ |
| 37 | + cmd := &ConfigCmd{Show: true} |
| 38 | + output := CaptureOutput(func(){ |
| 39 | + _ = cmd.Run() |
| 40 | + }) |
| 41 | + |
| 42 | + if want := "Current configuration:"; !contains(output, want){ |
| 43 | + t.Errorf("expected output to contain %q, got %q", want, output) |
| 44 | + } |
| 45 | +} |
| 46 | + |
| 47 | +// Show Error message if both flags are sent |
| 48 | +func TestConfigBothFlagError(t *testing.T){ |
| 49 | + cmd := &ConfigCmd{DefaultCluster: "tt-gpu-cluster-1", Show: true} |
| 50 | + output := CaptureOutput(func(){ |
| 51 | + _ = cmd.Run() |
| 52 | + }) |
| 53 | + |
| 54 | + if want := "Cannot use --show and --default-cluster together"; !contains(output, want){ |
| 55 | + t.Errorf("Expected the error message of \"%s\", got %q", want, output) |
| 56 | + } |
| 57 | + |
| 58 | +} |
0 commit comments