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

Function runCase

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

Source from the content-addressed store, hash-verified

23)
24
25func runCase(t *testing.T, d test.Data, c cases.Case) {
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"), []byte(c.Tpl(d)), 0644); err != nil {
35 t.Fatalf("created to create the TF config file: %v", err)
36 }
37 tf, err := tfexec.NewTerraform(provisionDir, tfexecPath)
38 if err != nil {
39 t.Fatalf("failed to new terraform: %v", err)
40 }
41 ctx := context.Background()
42 t.Log("Running: terraform init")
43 if err := tf.Init(ctx); err != nil {
44 t.Fatalf("terraform init failed: %v", err)
45 }
46 t.Log("Running: terraform apply")
47 if err := tf.Apply(ctx); err != nil {
48 t.Fatalf("terraform apply failed: %v", err)
49 }
50
51 if !test.Keep() {
52 defer func() {
53 t.Log("Running: terraform destroy")
54 if err := tf.Destroy(ctx); err != nil {
55 t.Logf("terraform destroy failed: %v", err)
56 }
57 }()
58 }
59
60 const delay = time.Minute
61 t.Logf("Sleep for %v to wait for the just created resources be recorded in ARG\n", delay)
62 time.Sleep(delay)
63
64 aztfexportDir := t.TempDir()
65
66 mapFile := filepath.Join(t.TempDir(), "mapping.json")
67 resMapping, err := c.ResourceMapping(d)
68 require.NoError(t, err)
69 bMapping, err := json.Marshal(resMapping)
70 require.NoError(t, err)
71 require.NoError(t, os.WriteFile(mapFile, bMapping, 0644))
72
73 cred, clientOpt := test.BuildCredAndClientOpt(t)
74
75 cfg := internalconfig.NonInteractiveModeConfig{
76 Config: config.Config{
77 CommonConfig: config.CommonConfig{
78 Logger: slog.New(slog.NewTextHandler(io.Discard, nil)),
79 SubscriptionId: os.Getenv("ARM_SUBSCRIPTION_ID"),
80 AzureSDKCredential: cred,
81 AzureSDKClientOption: *clientOpt,
82 OutputDir: aztfexportDir,

Callers 7

TestVnetFunction · 0.70
TestComputeVMDiskFunction · 0.70
TestSignalRServiceFunction · 0.70
TestKeyVaultNestedItemsFunction · 0.70
TestFunctionAppSlotFunction · 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
ResourceMappingMethod · 0.65

Tested by

no test coverage detected