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

Function runCase

internal/test/resourcegroup/e2e_cases_test.go:23–88  ·  view source on GitHub ↗
(t *testing.T, d test.Data, c cases.Case)

Source from the content-addressed store, hash-verified

21)
22
23func runCase(t *testing.T, d test.Data, c cases.Case) {
24 tfexecPath := test.EnsureTF(t)
25
26 provisionDir := t.TempDir()
27 if test.Keep() {
28 provisionDir, _ = os.MkdirTemp("", "")
29 t.Log(provisionDir)
30 }
31
32 if err := os.WriteFile(filepath.Join(provisionDir, "main.tf"), []byte(c.Tpl(d)), 0644); err != nil {
33 t.Fatalf("created to create the TF config file: %v", err)
34 }
35 tf, err := tfexec.NewTerraform(provisionDir, tfexecPath)
36 if err != nil {
37 t.Fatalf("failed to new terraform: %v", err)
38 }
39 ctx := context.Background()
40 t.Log("Running: terraform init")
41 if err := tf.Init(ctx); err != nil {
42 t.Fatalf("terraform init failed: %v", err)
43 }
44 t.Log("Running: terraform apply")
45 if err := tf.Apply(ctx); err != nil {
46 t.Fatalf("terraform apply failed: %v", err)
47 }
48 if !test.Keep() {
49 defer func() {
50 t.Log("Running: terraform destroy")
51 if err := tf.Destroy(ctx); err != nil {
52 t.Logf("terraform destroy failed: %v", err)
53 }
54 }()
55 }
56
57 const delay = time.Minute
58 t.Logf("Sleep for %v to wait for the just created resources be recorded in ARG\n", delay)
59 time.Sleep(delay)
60
61 aztfexportDir := t.TempDir()
62
63 cred, clientOpt := test.BuildCredAndClientOpt(t)
64
65 cfg := internalconfig.NonInteractiveModeConfig{
66 Config: config.Config{
67 CommonConfig: config.CommonConfig{
68 Logger: slog.New(slog.NewTextHandler(io.Discard, nil)),
69 SubscriptionId: os.Getenv("ARM_SUBSCRIPTION_ID"),
70 AzureSDKCredential: cred,
71 AzureSDKClientOption: *clientOpt,
72 OutputDir: aztfexportDir,
73 BackendType: "local",
74 DevProvider: true,
75 Parallelism: 10,
76 ProviderName: "azurerm",
77 },
78 ResourceGroupName: d.RandomRgName(),
79 ResourceNamePattern: "res-",
80 },

Callers 6

TestVnetFunction · 0.70
TestComputeVMDiskFunction · 0.70
TestSignalRServiceFunction · 0.70
TestKeyVaultNestedItemsFunction · 0.70
TestStorageFileShareFunction · 0.70

Calls 9

EnsureTFFunction · 0.92
KeepFunction · 0.92
BuildCredAndClientOptFunction · 0.92
BatchImportFunction · 0.92
VerifyFunction · 0.92
RandomRgNameMethod · 0.80
TplMethod · 0.65
InitMethod · 0.65
TotalMethod · 0.65

Tested by

no test coverage detected