2023-04-05 12:16:05 +00:00
|
|
|
package cli_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"context"
|
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
2023-08-18 18:55:43 +00:00
|
|
|
"github.com/coder/coder/v2/cli/clitest"
|
|
|
|
"github.com/coder/coder/v2/testutil"
|
2023-04-05 12:16:05 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestVersion(t *testing.T) {
|
2023-09-07 21:28:22 +00:00
|
|
|
t.Parallel()
|
2023-05-14 20:23:13 +00:00
|
|
|
|
2023-04-05 12:16:05 +00:00
|
|
|
expectedText := `Coder v0.0.0-devel
|
|
|
|
https://github.com/coder/coder
|
|
|
|
|
2023-09-07 21:28:22 +00:00
|
|
|
Full build of Coder, supports the server subcommand.
|
2023-04-05 12:16:05 +00:00
|
|
|
`
|
|
|
|
expectedJSON := `{
|
|
|
|
"version": "v0.0.0-devel",
|
|
|
|
"build_time": "0001-01-01T00:00:00Z",
|
|
|
|
"external_url": "https://github.com/coder/coder",
|
|
|
|
"slim": false,
|
2023-09-06 08:48:27 +00:00
|
|
|
"agpl": false,
|
|
|
|
"boring_crypto": false
|
2023-04-05 12:16:05 +00:00
|
|
|
}
|
|
|
|
`
|
|
|
|
for _, tt := range []struct {
|
|
|
|
Name string
|
|
|
|
Args []string
|
|
|
|
Expected string
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
Name: "Defaults to human-readable output",
|
|
|
|
Args: []string{"version"},
|
|
|
|
Expected: expectedText,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "JSON output",
|
|
|
|
Args: []string{"version", "--output=json"},
|
|
|
|
Expected: expectedJSON,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "Text output",
|
|
|
|
Args: []string{"version", "--output=text"},
|
|
|
|
Expected: expectedText,
|
|
|
|
},
|
|
|
|
} {
|
|
|
|
tt := tt
|
|
|
|
t.Run(tt.Name, func(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitShort)
|
|
|
|
t.Cleanup(cancel)
|
|
|
|
inv, _ := clitest.New(t, tt.Args...)
|
|
|
|
buf := new(bytes.Buffer)
|
|
|
|
inv.Stdout = buf
|
|
|
|
err := inv.WithContext(ctx).Run()
|
|
|
|
require.NoError(t, err)
|
|
|
|
actual := buf.String()
|
|
|
|
actual = strings.ReplaceAll(actual, "\r\n", "\n")
|
|
|
|
require.Equal(t, tt.Expected, actual)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|