MCPcopy Create free account
hub / github.com/Driver-C/tryssh / TestNewVersionCommand_OnlyGoVersionSet

Function TestNewVersionCommand_OnlyGoVersionSet

cmd/version/version_test.go:129–165  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

127}
128
129func TestNewVersionCommand_OnlyGoVersionSet(t *testing.T) {
130 origVersion := Version
131 origBuildGoVersion := BuildGoVersion
132 origBuildTime := BuildTime
133 defer func() {
134 Version = origVersion
135 BuildGoVersion = origBuildGoVersion
136 BuildTime = origBuildTime
137 }()
138
139 Version = ""
140 BuildGoVersion = "go1.21.0"
141 BuildTime = ""
142
143 cmd := NewVersionCommand()
144
145 old := os.Stdout
146 r, w, _ := os.Pipe()
147 os.Stdout = w
148
149 cmd.Run(cmd, []string{})
150
151 w.Close()
152 os.Stdout = old
153
154 var buf bytes.Buffer
155 buf.ReadFrom(r)
156 output := buf.String()
157
158 assert.Contains(t, output, "GoVersion: go1.21.0")
159 assert.NotContains(t, output, "BuildTime:")
160 // Verify there's no standalone "Version:" line
161 for _, line := range strings.Split(output, "\n") {
162 assert.False(t, strings.HasPrefix(line, "Version:"),
163 "should not have a Version: line, got: %q", line)
164 }
165}

Callers

nothing calls this directly

Calls 2

NewVersionCommandFunction · 0.85
StringMethod · 0.80

Tested by

no test coverage detected