MCPcopy Create free account
hub / github.com/coder/coder / TestAgentNameDuplicate

Function TestAgentNameDuplicate

provisioner/terraform/resources_test.go:1379–1410  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1377}
1378
1379func TestAgentNameDuplicate(t *testing.T) {
1380 t.Parallel()
1381 ctx, logger := ctxAndLogger(t)
1382
1383 // nolint:dogsled
1384 _, filename, _, _ := runtime.Caller(0)
1385
1386 dir := filepath.Join(filepath.Dir(filename), "testdata", "resources", "multiple-agents")
1387 tfPlanRaw, err := os.ReadFile(filepath.Join(dir, "multiple-agents.tfplan.json"))
1388 require.NoError(t, err)
1389 var tfPlan tfjson.Plan
1390 err = json.Unmarshal(tfPlanRaw, &tfPlan)
1391 require.NoError(t, err)
1392 tfPlanGraph, err := os.ReadFile(filepath.Join(dir, "multiple-agents.tfplan.dot"))
1393 require.NoError(t, err)
1394
1395 for _, resource := range tfPlan.PlannedValues.RootModule.Resources {
1396 if resource.Type == "coder_agent" {
1397 switch resource.Name {
1398 case "dev1":
1399 resource.Name = "dev"
1400 case "dev2":
1401 resource.Name = "Dev"
1402 }
1403 }
1404 }
1405
1406 state, err := terraform.ConvertState(ctx, []*tfjson.StateModule{tfPlan.PlannedValues.RootModule}, string(tfPlanGraph), logger)
1407 require.Nil(t, state)
1408 require.Error(t, err)
1409 require.ErrorContains(t, err, "duplicate agent name")
1410}
1411
1412func TestMetadataResourceDuplicate(t *testing.T) {
1413 t.Parallel()

Callers

nothing calls this directly

Calls 5

ConvertStateFunction · 0.92
ctxAndLoggerFunction · 0.85
ReadFileMethod · 0.65
UnmarshalMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected