info_unix_test.go 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. // +build !windows
  2. package daemon // import "github.com/docker/docker/daemon"
  3. import (
  4. "testing"
  5. "gotest.tools/assert"
  6. is "gotest.tools/assert/cmp"
  7. )
  8. func TestParseInitVersion(t *testing.T) {
  9. tests := []struct {
  10. output string
  11. version string
  12. commit string
  13. invalid bool
  14. }{
  15. {
  16. output: "tini version 0.13.0 - git.949e6fa",
  17. version: "0.13.0",
  18. commit: "949e6fa",
  19. }, {
  20. output: "tini version 0.13.0\n",
  21. version: "0.13.0",
  22. }, {
  23. output: "tini version 0.13.2",
  24. version: "0.13.2",
  25. }, {
  26. output: "tini version0.13.2",
  27. invalid: true,
  28. }, {
  29. output: "",
  30. invalid: true,
  31. }, {
  32. output: "hello world",
  33. invalid: true,
  34. },
  35. }
  36. for _, test := range tests {
  37. version, commit, err := parseInitVersion(string(test.output))
  38. if test.invalid {
  39. assert.Check(t, is.ErrorContains(err, ""))
  40. } else {
  41. assert.Check(t, err)
  42. }
  43. assert.Equal(t, test.version, version)
  44. assert.Equal(t, test.commit, commit)
  45. }
  46. }
  47. func parseRuncVersion(t *testing.T) {
  48. tests := []struct {
  49. output string
  50. runtime string
  51. version string
  52. commit string
  53. invalid bool
  54. }{
  55. {
  56. output: `
  57. runc version 1.0.0-rc5+dev
  58. commit: 69663f0bd4b60df09991c08812a60108003fa340
  59. spec: 1.0.0
  60. `,
  61. runtime: "runc",
  62. version: "1.0.0-rc5+dev",
  63. commit: "69663f0bd4b60df09991c08812a60108003fa340",
  64. },
  65. {
  66. output: `
  67. runc version 1.0.0-rc5+dev
  68. spec: 1.0.0
  69. `,
  70. runtime: "runc",
  71. version: "1.0.0-rc5+dev",
  72. },
  73. {
  74. output: `
  75. commit: 69663f0bd4b60df09991c08812a60108003fa340
  76. spec: 1.0.0
  77. `,
  78. commit: "69663f0bd4b60df09991c08812a60108003fa340",
  79. },
  80. {
  81. output: `
  82. crun version 0.7
  83. spec: 1.0.0
  84. +SYSTEMD +SELINUX +CAP +SECCOMP +EBPF +YAJL
  85. `,
  86. runtime: "crun",
  87. version: "0.7",
  88. },
  89. {
  90. output: "",
  91. invalid: true,
  92. },
  93. {
  94. output: "hello world",
  95. invalid: true,
  96. },
  97. }
  98. for _, test := range tests {
  99. runtime, version, commit, err := parseRuntimeVersion(string(test.output))
  100. if test.invalid {
  101. assert.Check(t, is.ErrorContains(err, ""))
  102. } else {
  103. assert.Check(t, err)
  104. }
  105. assert.Equal(t, test.runtime, runtime)
  106. assert.Equal(t, test.version, version)
  107. assert.Equal(t, test.commit, commit)
  108. }
  109. }