(t *testing.T)
| 91 | } |
| 92 | |
| 93 | func TestNewVersionCommand_PartialFieldsSet(t *testing.T) { |
| 94 | // Save and restore original values |
| 95 | origVersion := Version |
| 96 | origBuildGoVersion := BuildGoVersion |
| 97 | origBuildTime := BuildTime |
| 98 | defer func() { |
| 99 | Version = origVersion |
| 100 | BuildGoVersion = origBuildGoVersion |
| 101 | BuildTime = origBuildTime |
| 102 | }() |
| 103 | |
| 104 | Version = "0.9.0" |
| 105 | BuildGoVersion = "" |
| 106 | BuildTime = "" |
| 107 | |
| 108 | cmd := NewVersionCommand() |
| 109 | |
| 110 | // Capture stdout |
| 111 | old := os.Stdout |
| 112 | r, w, _ := os.Pipe() |
| 113 | os.Stdout = w |
| 114 | |
| 115 | cmd.Run(cmd, []string{}) |
| 116 | |
| 117 | w.Close() |
| 118 | os.Stdout = old |
| 119 | |
| 120 | var buf bytes.Buffer |
| 121 | buf.ReadFrom(r) |
| 122 | output := buf.String() |
| 123 | |
| 124 | assert.Contains(t, output, "Version: 0.9.0") |
| 125 | assert.NotContains(t, output, "GoVersion:") |
| 126 | assert.NotContains(t, output, "BuildTime:") |
| 127 | } |
| 128 | |
| 129 | func TestNewVersionCommand_OnlyGoVersionSet(t *testing.T) { |
| 130 | origVersion := Version |
nothing calls this directly
no test coverage detected