72eddf42 | // +build !windows |
4f0d95fa | package daemon // import "github.com/docker/docker/daemon" |
72eddf42 | import ( "testing" |
38457285 | "gotest.tools/assert" is "gotest.tools/assert/cmp" |
72eddf42 | ) func TestParseInitVersion(t *testing.T) { tests := []struct { |
2137b8cc | output string |
72eddf42 | version string |
2137b8cc | commit string |
72eddf42 | invalid bool }{ { |
2137b8cc | output: "tini version 0.13.0 - git.949e6fa", version: "0.13.0", commit: "949e6fa", |
72eddf42 | }, { |
2137b8cc | output: "tini version 0.13.0\n", version: "0.13.0", |
72eddf42 | }, { |
2137b8cc | output: "tini version 0.13.2", version: "0.13.2", |
72eddf42 | }, { |
2137b8cc | output: "tini version0.13.2", |
72eddf42 | invalid: true, }, { |
2137b8cc | output: "", |
72eddf42 | invalid: true, }, { |
2137b8cc | output: "hello world", |
72eddf42 | invalid: true, }, } for _, test := range tests { |
2137b8cc | version, commit, err := parseInitVersion(string(test.output)) |
72eddf42 | if test.invalid { |
6be0f709 | assert.Check(t, is.ErrorContains(err, "")) |
72eddf42 | } else { |
6be0f709 | assert.Check(t, err) |
72eddf42 | } |
2137b8cc | assert.Equal(t, test.version, version) assert.Equal(t, test.commit, commit) } } func TestParseRuncVersion(t *testing.T) { tests := []struct { output string version string commit string invalid bool }{ { output: ` runc version 1.0.0-rc5+dev commit: 69663f0bd4b60df09991c08812a60108003fa340 spec: 1.0.0 `, version: "1.0.0-rc5+dev", commit: "69663f0bd4b60df09991c08812a60108003fa340", }, { output: ` runc version 1.0.0-rc5+dev spec: 1.0.0 `, version: "1.0.0-rc5+dev", }, { output: ` commit: 69663f0bd4b60df09991c08812a60108003fa340 spec: 1.0.0 `, commit: "69663f0bd4b60df09991c08812a60108003fa340", }, { output: "", invalid: true, }, { output: "hello world", invalid: true, }, } for _, test := range tests { version, commit, err := parseRuncVersion(string(test.output)) if test.invalid { assert.Check(t, is.ErrorContains(err, "")) } else { assert.Check(t, err) } assert.Equal(t, test.version, version) assert.Equal(t, test.commit, commit) |
72eddf42 | } } |