mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
TestParseInitVersion: add some additional tests
Also slightly harden parseInitVersion Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
f5bb374a0c
commit
2030daf2ee
2 changed files with 26 additions and 10 deletions
|
@ -26,12 +26,24 @@ func TestParseInitVersion(t *testing.T) {
|
|||
}, {
|
||||
output: "tini version 0.13.2",
|
||||
version: "0.13.2",
|
||||
}, {
|
||||
output: "tini version 0.13.2 - ",
|
||||
version: "0.13.2",
|
||||
}, {
|
||||
output: " - git.949e6fa",
|
||||
commit: "949e6fa",
|
||||
}, {
|
||||
output: "tini version0.13.2",
|
||||
invalid: true,
|
||||
}, {
|
||||
output: "version 0.13.0",
|
||||
invalid: true,
|
||||
}, {
|
||||
output: "",
|
||||
invalid: true,
|
||||
}, {
|
||||
output: " - ",
|
||||
invalid: true,
|
||||
}, {
|
||||
output: "hello world",
|
||||
invalid: true,
|
||||
|
@ -39,14 +51,17 @@ func TestParseInitVersion(t *testing.T) {
|
|||
}
|
||||
|
||||
for _, test := range tests {
|
||||
version, commit, err := parseInitVersion(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)
|
||||
test := test
|
||||
t.Run(test.output, func(t *testing.T) {
|
||||
version, commit, err := parseInitVersion(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)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue