ovnutils_test.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. // Copyright 2019 Yunion
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package ovnutils
  15. import (
  16. "testing"
  17. )
  18. func TestMustGetOvnVersion(t *testing.T) {
  19. cases := []struct {
  20. in string
  21. out string
  22. }{
  23. {
  24. in: `
  25. ovn-controller (Open vSwitch) 2.9
  26. OpenFlow versions 0x4:0x4
  27. `,
  28. out: "2.9",
  29. },
  30. {
  31. in: `
  32. ovn-controller (Open vSwitch) 2.9.6
  33. OpenFlow versions 0x4:0x4
  34. `,
  35. out: "2.9.6",
  36. },
  37. {
  38. in: `
  39. ovn-controller (Open vSwitch) 2.9.100
  40. OpenFlow versions 0x4:0x4
  41. `,
  42. out: "2.9.100",
  43. },
  44. {
  45. in: `
  46. ovn-controller (Open vSwitch) 2.9.1000
  47. OpenFlow versions 0x4:0x4
  48. `,
  49. out: "",
  50. },
  51. {
  52. in: `
  53. ovn-controller (Open vSwitch) 2.9.6.1
  54. `,
  55. out: "",
  56. },
  57. }
  58. for _, c := range cases {
  59. got := ovnExtractVersion(c.in)
  60. if got != c.out {
  61. t.Fatalf("got: %s, want: %s, input:\n%s", got, c.out, c.in)
  62. }
  63. }
  64. }