(t *testing.T)
| 56 | } |
| 57 | |
| 58 | func TestNewVersionCommand_EmptyFields(t *testing.T) { |
| 59 | // Save and restore original values |
| 60 | origVersion := Version |
| 61 | origBuildGoVersion := BuildGoVersion |
| 62 | origBuildTime := BuildTime |
| 63 | defer func() { |
| 64 | Version = origVersion |
| 65 | BuildGoVersion = origBuildGoVersion |
| 66 | BuildTime = origBuildTime |
| 67 | }() |
| 68 | |
| 69 | Version = "" |
| 70 | BuildGoVersion = "" |
| 71 | BuildTime = "" |
| 72 | |
| 73 | cmd := NewVersionCommand() |
| 74 | |
| 75 | // Capture stdout |
| 76 | old := os.Stdout |
| 77 | r, w, _ := os.Pipe() |
| 78 | os.Stdout = w |
| 79 | |
| 80 | cmd.Run(cmd, []string{}) |
| 81 | |
| 82 | w.Close() |
| 83 | os.Stdout = old |
| 84 | |
| 85 | var buf bytes.Buffer |
| 86 | buf.ReadFrom(r) |
| 87 | output := buf.String() |
| 88 | |
| 89 | assert.Contains(t, output, "(dev)", |
| 90 | "output should show (dev) when all fields are empty") |
| 91 | } |
| 92 | |
| 93 | func TestNewVersionCommand_PartialFieldsSet(t *testing.T) { |
| 94 | // Save and restore original values |
nothing calls this directly
no test coverage detected