2017-03-29 07:44:14 -04:00
|
|
|
// +build !windows
|
|
|
|
|
2018-02-05 16:05:59 -05:00
|
|
|
package daemon // import "github.com/docker/docker/daemon"
|
2017-03-29 07:44:14 -04:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/docker/docker/api/types"
|
|
|
|
"github.com/docker/docker/dockerversion"
|
2018-03-13 15:28:34 -04:00
|
|
|
"github.com/gotestyourself/gotestyourself/assert"
|
|
|
|
is "github.com/gotestyourself/gotestyourself/assert/cmp"
|
2017-03-29 07:44:14 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestParseInitVersion(t *testing.T) {
|
|
|
|
tests := []struct {
|
|
|
|
version string
|
|
|
|
result types.Commit
|
|
|
|
invalid bool
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
version: "tini version 0.13.0 - git.949e6fa",
|
|
|
|
result: types.Commit{ID: "949e6fa", Expected: dockerversion.InitCommitID[0:7]},
|
|
|
|
}, {
|
|
|
|
version: "tini version 0.13.0\n",
|
|
|
|
result: types.Commit{ID: "v0.13.0", Expected: dockerversion.InitCommitID},
|
|
|
|
}, {
|
|
|
|
version: "tini version 0.13.2",
|
|
|
|
result: types.Commit{ID: "v0.13.2", Expected: dockerversion.InitCommitID},
|
|
|
|
}, {
|
|
|
|
version: "tini version0.13.2",
|
|
|
|
result: types.Commit{ID: "N/A", Expected: dockerversion.InitCommitID},
|
|
|
|
invalid: true,
|
|
|
|
}, {
|
|
|
|
version: "",
|
|
|
|
result: types.Commit{ID: "N/A", Expected: dockerversion.InitCommitID},
|
|
|
|
invalid: true,
|
|
|
|
}, {
|
|
|
|
version: "hello world",
|
|
|
|
result: types.Commit{ID: "N/A", Expected: dockerversion.InitCommitID},
|
|
|
|
invalid: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, test := range tests {
|
|
|
|
ver, err := parseInitVersion(string(test.version))
|
|
|
|
if test.invalid {
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.Check(t, is.ErrorContains(err, ""))
|
2017-03-29 07:44:14 -04:00
|
|
|
} else {
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.Check(t, err)
|
2017-03-29 07:44:14 -04:00
|
|
|
}
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.Check(t, is.DeepEqual(test.result, ver))
|
2017-03-29 07:44:14 -04:00
|
|
|
}
|
|
|
|
}
|