info_unix_test.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // +build !windows
  2. package daemon
  3. import (
  4. "testing"
  5. "github.com/docker/docker/api/types"
  6. "github.com/docker/docker/dockerversion"
  7. "github.com/stretchr/testify/assert"
  8. )
  9. func TestParseInitVersion(t *testing.T) {
  10. tests := []struct {
  11. version string
  12. result types.Commit
  13. invalid bool
  14. }{
  15. {
  16. version: "tini version 0.13.0 - git.949e6fa",
  17. result: types.Commit{ID: "949e6fa", Expected: dockerversion.InitCommitID[0:7]},
  18. }, {
  19. version: "tini version 0.13.0\n",
  20. result: types.Commit{ID: "v0.13.0", Expected: dockerversion.InitCommitID},
  21. }, {
  22. version: "tini version 0.13.2",
  23. result: types.Commit{ID: "v0.13.2", Expected: dockerversion.InitCommitID},
  24. }, {
  25. version: "tini version0.13.2",
  26. result: types.Commit{ID: "N/A", Expected: dockerversion.InitCommitID},
  27. invalid: true,
  28. }, {
  29. version: "",
  30. result: types.Commit{ID: "N/A", Expected: dockerversion.InitCommitID},
  31. invalid: true,
  32. }, {
  33. version: "hello world",
  34. result: types.Commit{ID: "N/A", Expected: dockerversion.InitCommitID},
  35. invalid: true,
  36. },
  37. }
  38. for _, test := range tests {
  39. ver, err := parseInitVersion(string(test.version))
  40. if test.invalid {
  41. assert.Error(t, err)
  42. } else {
  43. assert.NoError(t, err)
  44. }
  45. assert.Equal(t, test.result, ver)
  46. }
  47. }