Skip to content

Commit

Permalink
fix: Add the --format option to the finch version command.
Browse files Browse the repository at this point in the history
Update a test name and fix to pass lint CI.

Signed-off-by: Hayato Kiwata <[email protected]>
  • Loading branch information
haytok committed May 2, 2024
1 parent 2ca261e commit 90bb82b
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions cmd/finch/version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,6 @@ const nerdctlMockVersion = `{
}
}`

// nolint: lll // Version output format is larger than 500
const finchVersionJSONOutput = "{\"Client\":{\"Version\":\"\",\"GitCommit\":\"\",\"NerdctlClient\":{\"Version\":\"v1.0.0\",\"GitCommit\":\"c00780a1f5b905b09812722459c54936c9e070e6\",\"GoVersion\":\"go1.19.2\",\"Os\":\"linux\",\"Arch\":\"arm64\",\"Components\":[{\"Name\":\"buildctl\",\"Version\":\"v0.10.5\",\"Details\":{\"GitCommit\":\"bc26045116045516ff2427201abd299043eaf8f7\"}}]}},\"Server\":{\"Components\":[{\"Name\":\"containerd\",\"Version\":\"v1.6.8\",\"Details\":{\"GitCommit\":\"9cd3357b7fd7218e4aec3eae239db1f68a5a6ec6\"}},{\"Name\":\"runc\",\"Version\":\"1.1.4\",\"Details\":{\"GitCommit\":\"v1.1.4-0-g5fd4c4d1\"}}]}}\n"

func TestNewVersionCommand(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -104,7 +101,7 @@ func TestVersionAction_runAdaptor(t *testing.T) {
},
},
{
name: "happy path",
name: "with --format json",
cmd: func(_ *testing.T) *cobra.Command {
c := &cobra.Command{
Use: "version",
Expand Down Expand Up @@ -273,7 +270,8 @@ func TestVersionAction_run(t *testing.T) {
command.EXPECT().Output().Return([]byte(nerdctlMockVersion), nil)
},
postRunCheck: func(t *testing.T, stdout []byte) {
assert.Equal(t, string(stdout), finchVersionJSONOutput)
//nolint: lll // Version output format is larger than 500
assert.Equal(t, string(stdout), "{\"Client\":{\"Version\":\"\",\"GitCommit\":\"\",\"NerdctlClient\":{\"Version\":\"v1.0.0\",\"GitCommit\":\"c00780a1f5b905b09812722459c54936c9e070e6\",\"GoVersion\":\"go1.19.2\",\"Os\":\"linux\",\"Arch\":\"arm64\",\"Components\":[{\"Name\":\"buildctl\",\"Version\":\"v0.10.5\",\"Details\":{\"GitCommit\":\"bc26045116045516ff2427201abd299043eaf8f7\"}}]}},\"Server\":{\"Components\":[{\"Name\":\"containerd\",\"Version\":\"v1.6.8\",\"Details\":{\"GitCommit\":\"9cd3357b7fd7218e4aec3eae239db1f68a5a6ec6\"}},{\"Name\":\"runc\",\"Version\":\"1.1.4\",\"Details\":{\"GitCommit\":\"v1.1.4-0-g5fd4c4d1\"}}]}}\n")
},
format: "json",
},
Expand All @@ -300,7 +298,8 @@ func TestVersionAction_run(t *testing.T) {
command.EXPECT().Output().Return([]byte(nerdctlMockVersion), nil)
},
postRunCheck: func(t *testing.T, stdout []byte) {
assert.Equal(t, string(stdout), finchVersionJSONOutput)
//nolint: lll // Version output format is larger than 500
assert.Equal(t, string(stdout), "{\"Client\":{\"Version\":\"\",\"GitCommit\":\"\",\"NerdctlClient\":{\"Version\":\"v1.0.0\",\"GitCommit\":\"c00780a1f5b905b09812722459c54936c9e070e6\",\"GoVersion\":\"go1.19.2\",\"Os\":\"linux\",\"Arch\":\"arm64\",\"Components\":[{\"Name\":\"buildctl\",\"Version\":\"v0.10.5\",\"Details\":{\"GitCommit\":\"bc26045116045516ff2427201abd299043eaf8f7\"}}]}},\"Server\":{\"Components\":[{\"Name\":\"containerd\",\"Version\":\"v1.6.8\",\"Details\":{\"GitCommit\":\"9cd3357b7fd7218e4aec3eae239db1f68a5a6ec6\"}},{\"Name\":\"runc\",\"Version\":\"1.1.4\",\"Details\":{\"GitCommit\":\"v1.1.4-0-g5fd4c4d1\"}}]}}\n")
},
format: "{{json .}}",
},
Expand All @@ -327,7 +326,7 @@ func TestVersionAction_run(t *testing.T) {
command.EXPECT().Output().Return([]byte(nerdctlMockVersion), nil)
},
postRunCheck: func(t *testing.T, stdout []byte) {
//nolint: lll // Version output format is larger than 500
//nolint: lll // Version output format is larger than 150
assert.Equal(t, string(stdout), "{ {v1.0.0 c00780a1f5b905b09812722459c54936c9e070e6 go1.19.2 linux arm64 [{buildctl v0.10.5 {bc26045116045516ff2427201abd299043eaf8f7}}]}}\n")
},
format: "{{.Client}}",
Expand Down Expand Up @@ -382,7 +381,7 @@ func TestVersionAction_run(t *testing.T) {
command.EXPECT().Output().Return([]byte(nerdctlMockVersion), nil)
},
postRunCheck: func(t *testing.T, stdout []byte) {
//nolint: lll // Version output format is larger than 500
//nolint: lll // Version output format is larger than 100
assert.Equal(t, string(stdout), "{[{containerd v1.6.8 {9cd3357b7fd7218e4aec3eae239db1f68a5a6ec6}} {runc 1.1.4 {v1.1.4-0-g5fd4c4d1}}]}\n")
},
format: "{{.Server}}",
Expand Down

0 comments on commit 90bb82b

Please sign in to comment.