nolint:tparallel
(t *testing.T)
| 1329 | |
| 1330 | //nolint:tparallel |
| 1331 | func TestAgentNameInvalid(t *testing.T) { |
| 1332 | t.Parallel() |
| 1333 | ctx, logger := ctxAndLogger(t) |
| 1334 | |
| 1335 | // nolint:dogsled |
| 1336 | _, filename, _, _ := runtime.Caller(0) |
| 1337 | |
| 1338 | dir := filepath.Join(filepath.Dir(filename), "testdata", "resources", "multiple-agents") |
| 1339 | tfPlanRaw, err := os.ReadFile(filepath.Join(dir, "multiple-agents.tfplan.json")) |
| 1340 | require.NoError(t, err) |
| 1341 | var tfPlan tfjson.Plan |
| 1342 | err = json.Unmarshal(tfPlanRaw, &tfPlan) |
| 1343 | require.NoError(t, err) |
| 1344 | tfPlanGraph, err := os.ReadFile(filepath.Join(dir, "multiple-agents.tfplan.dot")) |
| 1345 | require.NoError(t, err) |
| 1346 | |
| 1347 | cases := []struct { |
| 1348 | name string |
| 1349 | errContains string |
| 1350 | }{ |
| 1351 | {name: "bad--name", errContains: "does not match regex"}, |
| 1352 | {name: "bad_name", errContains: "contains underscores"}, // custom error for underscores |
| 1353 | {name: "valid-name-123", errContains: ""}, |
| 1354 | {name: "valid", errContains: ""}, |
| 1355 | {name: "UppercaseValid", errContains: ""}, |
| 1356 | } |
| 1357 | |
| 1358 | //nolint:paralleltest |
| 1359 | for i, c := range cases { |
| 1360 | t.Run(fmt.Sprintf("case-%d", i), func(t *testing.T) { |
| 1361 | // Change the first agent name to match the current case. |
| 1362 | for _, resource := range tfPlan.PlannedValues.RootModule.Resources { |
| 1363 | if resource.Type == "coder_agent" { |
| 1364 | resource.Name = c.name |
| 1365 | break |
| 1366 | } |
| 1367 | } |
| 1368 | |
| 1369 | _, err := terraform.ConvertState(ctx, []*tfjson.StateModule{tfPlan.PlannedValues.RootModule}, string(tfPlanGraph), logger) |
| 1370 | if c.errContains != "" { |
| 1371 | require.ErrorContains(t, err, c.errContains) |
| 1372 | } else { |
| 1373 | require.NoError(t, err) |
| 1374 | } |
| 1375 | }) |
| 1376 | } |
| 1377 | } |
| 1378 | |
| 1379 | func TestAgentNameDuplicate(t *testing.T) { |
| 1380 | t.Parallel() |
nothing calls this directly
no test coverage detected