MCPcopy
hub / github.com/Azure/aztfexport / TestQueryMode

Function TestQueryMode

internal/test/query/query_test.go:22–142  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

20)
21
22func TestQueryMode(t *testing.T) {
23 t.Parallel()
24 test.Precheck(t)
25 d := test.NewData()
26 tfexecPath := test.EnsureTF(t)
27
28 provisionDir := t.TempDir()
29 if test.Keep() {
30 provisionDir, _ = os.MkdirTemp("", "")
31 t.Log(provisionDir)
32 }
33
34 if err := os.WriteFile(filepath.Join(provisionDir, "main.tf"), fmt.Appendf([]byte{}, `
35provider "azurerm" {
36 features {
37 resource_group {
38 prevent_deletion_if_contains_resources = false
39 }
40 }
41}
42resource "azurerm_resource_group" "test" {
43 name = "%[1]s"
44 location = "WestEurope"
45}
46resource "azurerm_virtual_network" "test" {
47 address_space = ["10.0.0.0/16"]
48 location = "westeurope"
49 name = "%[1]s"
50 resource_group_name = azurerm_resource_group.test.name
51}
52resource "azurerm_subnet" "test" {
53 address_prefixes = ["10.0.2.0/24"]
54 name = "internal"
55 resource_group_name = azurerm_virtual_network.test.resource_group_name
56 virtual_network_name = azurerm_virtual_network.test.name
57}
58`, d.RandomRgName()), 0644); err != nil {
59 t.Fatalf("failed to create the TF config file: %v", err)
60 }
61 tf, err := tfexec.NewTerraform(provisionDir, tfexecPath)
62 if err != nil {
63 t.Fatalf("failed to new terraform: %v", err)
64 }
65 ctx := context.Background()
66 t.Log("Running: terraform init")
67 if err := tf.Init(ctx); err != nil {
68 t.Fatalf("terraform init failed: %v", err)
69 }
70 t.Log("Running: terraform apply")
71 if err := tf.Apply(ctx); err != nil {
72 t.Fatalf("terraform apply failed: %v", err)
73 }
74
75 if !test.Keep() {
76 defer func() {
77 t.Log("Running: terraform destroy")
78 if err := tf.Destroy(ctx); err != nil {
79 t.Logf("terraform destroy failed: %v", err)

Callers

nothing calls this directly

Calls 10

PrecheckFunction · 0.92
NewDataFunction · 0.92
EnsureTFFunction · 0.92
KeepFunction · 0.92
BuildCredAndClientOptFunction · 0.92
RemoveEverythingUnderFunction · 0.92
BatchImportFunction · 0.92
VerifyFunction · 0.92
RandomRgNameMethod · 0.80
InitMethod · 0.65

Tested by

no test coverage detected