|
| 1 | +package containerdisks |
| 2 | + |
| 3 | +import "testing" |
| 4 | + |
| 5 | +func TestResolve(t *testing.T) { |
| 6 | + t.Run("resolves known OS names to containerdisk images", func(t *testing.T) { |
| 7 | + tests := []struct { |
| 8 | + input string |
| 9 | + expected string |
| 10 | + }{ |
| 11 | + {"fedora", "quay.io/containerdisks/fedora:latest"}, |
| 12 | + {"ubuntu", "quay.io/containerdisks/ubuntu:latest"}, |
| 13 | + {"centos", "quay.io/containerdisks/centos-stream:latest"}, |
| 14 | + {"centos-stream", "quay.io/containerdisks/centos-stream:latest"}, |
| 15 | + {"debian", "quay.io/containerdisks/debian:latest"}, |
| 16 | + {"opensuse", "quay.io/containerdisks/opensuse-tumbleweed:latest"}, |
| 17 | + {"opensuse-tumbleweed", "quay.io/containerdisks/opensuse-tumbleweed:latest"}, |
| 18 | + {"opensuse-leap", "quay.io/containerdisks/opensuse-leap:latest"}, |
| 19 | + } |
| 20 | + |
| 21 | + for _, tt := range tests { |
| 22 | + t.Run(tt.input, func(t *testing.T) { |
| 23 | + result := Resolve(tt.input) |
| 24 | + if result != tt.expected { |
| 25 | + t.Errorf("Expected %s, got %s", tt.expected, result) |
| 26 | + } |
| 27 | + }) |
| 28 | + } |
| 29 | + }) |
| 30 | + |
| 31 | + t.Run("handles case insensitive input", func(t *testing.T) { |
| 32 | + tests := []struct { |
| 33 | + input string |
| 34 | + expected string |
| 35 | + }{ |
| 36 | + {"FEDORA", "quay.io/containerdisks/fedora:latest"}, |
| 37 | + {"Ubuntu", "quay.io/containerdisks/ubuntu:latest"}, |
| 38 | + {"CentOS", "quay.io/containerdisks/centos-stream:latest"}, |
| 39 | + } |
| 40 | + |
| 41 | + for _, tt := range tests { |
| 42 | + t.Run(tt.input, func(t *testing.T) { |
| 43 | + result := Resolve(tt.input) |
| 44 | + if result != tt.expected { |
| 45 | + t.Errorf("Expected %s, got %s", tt.expected, result) |
| 46 | + } |
| 47 | + }) |
| 48 | + } |
| 49 | + }) |
| 50 | + |
| 51 | + t.Run("handles input with extra whitespace", func(t *testing.T) { |
| 52 | + tests := []struct { |
| 53 | + input string |
| 54 | + expected string |
| 55 | + }{ |
| 56 | + {" ubuntu ", "quay.io/containerdisks/ubuntu:latest"}, |
| 57 | + {" fedora ", "quay.io/containerdisks/fedora:latest"}, |
| 58 | + {" debian ", "quay.io/containerdisks/debian:latest"}, |
| 59 | + } |
| 60 | + |
| 61 | + for _, tt := range tests { |
| 62 | + t.Run(tt.input, func(t *testing.T) { |
| 63 | + result := Resolve(tt.input) |
| 64 | + if result != tt.expected { |
| 65 | + t.Errorf("Expected %s, got %s", tt.expected, result) |
| 66 | + } |
| 67 | + }) |
| 68 | + } |
| 69 | + }) |
| 70 | + |
| 71 | + t.Run("returns full container image URLs as-is", func(t *testing.T) { |
| 72 | + tests := []struct { |
| 73 | + input string |
| 74 | + }{ |
| 75 | + {"quay.io/containerdisks/fedora:38"}, |
| 76 | + {"my-registry/my-image:v1.0"}, |
| 77 | + {"docker.io/library/ubuntu"}, |
| 78 | + {"registry.example.com/path/to/image:tag"}, |
| 79 | + } |
| 80 | + |
| 81 | + for _, tt := range tests { |
| 82 | + t.Run(tt.input, func(t *testing.T) { |
| 83 | + result := Resolve(tt.input) |
| 84 | + if result != tt.input { |
| 85 | + t.Errorf("Expected %s, got %s", tt.input, result) |
| 86 | + } |
| 87 | + }) |
| 88 | + } |
| 89 | + }) |
| 90 | + |
| 91 | + t.Run("returns images with tags as-is", func(t *testing.T) { |
| 92 | + tests := []struct { |
| 93 | + input string |
| 94 | + }{ |
| 95 | + {"myimage:v1.0"}, |
| 96 | + {"image:latest"}, |
| 97 | + {"test:123"}, |
| 98 | + } |
| 99 | + |
| 100 | + for _, tt := range tests { |
| 101 | + t.Run(tt.input, func(t *testing.T) { |
| 102 | + result := Resolve(tt.input) |
| 103 | + if result != tt.input { |
| 104 | + t.Errorf("Expected %s, got %s", tt.input, result) |
| 105 | + } |
| 106 | + }) |
| 107 | + } |
| 108 | + }) |
| 109 | + |
| 110 | + t.Run("constructs containerdisks URL for unknown OS names", func(t *testing.T) { |
| 111 | + tests := []struct { |
| 112 | + input string |
| 113 | + expected string |
| 114 | + }{ |
| 115 | + {"myos", "quay.io/containerdisks/myos:latest"}, |
| 116 | + {"customlinux", "quay.io/containerdisks/customlinux:latest"}, |
| 117 | + } |
| 118 | + |
| 119 | + for _, tt := range tests { |
| 120 | + t.Run(tt.input, func(t *testing.T) { |
| 121 | + result := Resolve(tt.input) |
| 122 | + if result != tt.expected { |
| 123 | + t.Errorf("Expected %s, got %s", tt.expected, result) |
| 124 | + } |
| 125 | + }) |
| 126 | + } |
| 127 | + }) |
| 128 | + |
| 129 | + t.Run("handles unknown OS with case normalization", func(t *testing.T) { |
| 130 | + result := Resolve("MyCustomOS") |
| 131 | + expected := "quay.io/containerdisks/mycustomos:latest" |
| 132 | + if result != expected { |
| 133 | + t.Errorf("Expected %s, got %s", expected, result) |
| 134 | + } |
| 135 | + }) |
| 136 | +} |
0 commit comments