TestRenderInvalidTalosVersion verifies that malformed TalosVersion values surface a user-friendly error before template rendering, instead of the opaque "error calling semverCompare: invalid semantic version" that escapes from deep inside the Helm engine.
(t *testing.T)
| 4139 | // opaque "error calling semverCompare: invalid semantic version" that escapes |
| 4140 | // from deep inside the Helm engine. |
| 4141 | func TestRenderInvalidTalosVersion(t *testing.T) { |
| 4142 | chartRoot := createTestChart(t, "dummy", "config.yaml", "machine:\n type: worker\n") |
| 4143 | |
| 4144 | tests := []struct { |
| 4145 | name string |
| 4146 | version string |
| 4147 | }{ |
| 4148 | {"plain word", "latest"}, |
| 4149 | {"garbage", "foobar"}, |
| 4150 | {"v-prefixed garbage", "vlatest"}, |
| 4151 | } |
| 4152 | |
| 4153 | for _, tt := range tests { |
| 4154 | t.Run(tt.name, func(t *testing.T) { |
| 4155 | opts := Options{ |
| 4156 | Offline: true, |
| 4157 | Root: chartRoot, |
| 4158 | TalosVersion: tt.version, |
| 4159 | TemplateFiles: []string{"templates/config.yaml"}, |
| 4160 | } |
| 4161 | _, err := Render(context.Background(), nil, opts) |
| 4162 | if err == nil { |
| 4163 | t.Fatalf("Render(%q) expected error, got nil", tt.version) |
| 4164 | } |
| 4165 | if !strings.Contains(err.Error(), "invalid talos-version") { |
| 4166 | t.Errorf("Render(%q) error = %q, want prefix 'invalid talos-version'", tt.version, err.Error()) |
| 4167 | } |
| 4168 | }) |
| 4169 | } |
| 4170 | } |
| 4171 | |
| 4172 | // simpleNicLookup returns a lookup fixture exposing one physical |
| 4173 | // interface (eth0) with address 192.168.201.10/24 and default route |
nothing calls this directly
no test coverage detected