slices_test.go 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*
  2. Copyright 2020 Docker Compose CLI authors
  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. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package utils
  14. import (
  15. "testing"
  16. specs "github.com/opencontainers/image-spec/specs-go/v1"
  17. )
  18. func TestContains(t *testing.T) {
  19. source := []specs.Platform{
  20. {
  21. Architecture: "linux/amd64",
  22. OS: "darwin",
  23. OSVersion: "",
  24. OSFeatures: nil,
  25. Variant: "",
  26. },
  27. {
  28. Architecture: "linux/arm64",
  29. OS: "linux",
  30. OSVersion: "12",
  31. OSFeatures: nil,
  32. Variant: "v8",
  33. },
  34. {
  35. Architecture: "",
  36. OS: "",
  37. OSVersion: "",
  38. OSFeatures: nil,
  39. Variant: "",
  40. },
  41. }
  42. type args struct {
  43. origin []specs.Platform
  44. element specs.Platform
  45. }
  46. tests := []struct {
  47. name string
  48. args args
  49. want bool
  50. }{
  51. {
  52. name: "element found",
  53. args: args{
  54. origin: source,
  55. element: specs.Platform{
  56. Architecture: "linux/arm64",
  57. OS: "linux",
  58. OSVersion: "12",
  59. OSFeatures: nil,
  60. Variant: "v8",
  61. },
  62. },
  63. want: true,
  64. },
  65. {
  66. name: "element not found",
  67. args: args{
  68. origin: source,
  69. element: specs.Platform{
  70. Architecture: "linux/arm64",
  71. OS: "darwin",
  72. OSVersion: "12",
  73. OSFeatures: nil,
  74. Variant: "v8",
  75. },
  76. },
  77. want: false,
  78. },
  79. }
  80. for _, tt := range tests {
  81. t.Run(tt.name, func(t *testing.T) {
  82. if got := Contains(tt.args.origin, tt.args.element); got != tt.want {
  83. t.Errorf("Contains() = %v, want %v", got, tt.want)
  84. }
  85. })
  86. }
  87. }