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

Function TestInstanceTypeAssociation

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

Source from the content-addressed store, hash-verified

1560}
1561
1562func TestInstanceTypeAssociation(t *testing.T) {
1563 t.Parallel()
1564 type tc struct {
1565 ResourceType string
1566 InstanceTypeKey string
1567 }
1568 for _, tc := range []tc{{
1569 ResourceType: "google_compute_instance",
1570 InstanceTypeKey: "machine_type",
1571 }, {
1572 ResourceType: "aws_instance",
1573 InstanceTypeKey: "instance_type",
1574 }, {
1575 ResourceType: "aws_spot_instance_request",
1576 InstanceTypeKey: "instance_type",
1577 }, {
1578 ResourceType: "azurerm_linux_virtual_machine",
1579 InstanceTypeKey: "size",
1580 }, {
1581 ResourceType: "azurerm_windows_virtual_machine",
1582 InstanceTypeKey: "size",
1583 }} {
1584 t.Run(tc.ResourceType, func(t *testing.T) {
1585 t.Parallel()
1586 ctx, logger := ctxAndLogger(t)
1587 instanceType, err := cryptorand.String(12)
1588 require.NoError(t, err)
1589 state, err := terraform.ConvertState(ctx, []*tfjson.StateModule{{
1590 Resources: []*tfjson.StateResource{{
1591 Address: tc.ResourceType + ".dev",
1592 Type: tc.ResourceType,
1593 Name: "dev",
1594 Mode: tfjson.ManagedResourceMode,
1595 AttributeValues: map[string]interface{}{
1596 tc.InstanceTypeKey: instanceType,
1597 },
1598 }},
1599 // This is manually created to join the edges.
1600 }}, `digraph {
1601 compound = "true"
1602 newrank = "true"
1603 subgraph "root" {
1604 "[root] `+tc.ResourceType+`.dev" [label = "`+tc.ResourceType+`.dev", shape = "box"]
1605 }
1606}`, logger)
1607 require.NoError(t, err)
1608 require.Len(t, state.Resources, 1)
1609 require.Equal(t, state.Resources[0].GetInstanceType(), instanceType)
1610 })
1611 }
1612}
1613
1614func TestInstanceIDAssociation(t *testing.T) {
1615 t.Parallel()

Callers

nothing calls this directly

Calls 7

StringFunction · 0.92
ConvertStateFunction · 0.92
ctxAndLoggerFunction · 0.85
GetInstanceTypeMethod · 0.80
RunMethod · 0.65
LenMethod · 0.45
EqualMethod · 0.45

Tested by

no test coverage detected