Skip to content

Commit 1337eff

Browse files
DEVOPS-362 terratest cases
1 parent 6f66c15 commit 1337eff

File tree

4 files changed

+192
-8
lines changed

4 files changed

+192
-8
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
## Examples
1010

11-
Please find the [examples]((https://github.com/devwithkrishna/terraform-azure-datafactory//tree/main/examples)) here
11+
Please find the [examples]((https://github.com/devwithkrishna/terraform-azure-datafactory/tree/main/examples)) here
1212

1313
## 📂 Structure
1414

test/go.mod

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
module github.com/devwithkrishna/terraform-azure-datafactory/test
2+
3+
go 1.24.0
4+
5+
toolchain go1.24.9
6+
7+
require (
8+
github.com/gruntwork-io/terratest v0.51.0
9+
github.com/stretchr/testify v1.11.1
10+
)
11+
12+
require (
13+
github.com/agext/levenshtein v1.2.3 // indirect
14+
github.com/apparentlymart/go-textseg/v15 v15.0.0 // indirect
15+
github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d // indirect
16+
github.com/davecgh/go-spew v1.1.1 // indirect
17+
github.com/hashicorp/errwrap v1.0.0 // indirect
18+
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
19+
github.com/hashicorp/go-getter/v2 v2.2.3 // indirect
20+
github.com/hashicorp/go-multierror v1.1.1 // indirect
21+
github.com/hashicorp/go-safetemp v1.0.0 // indirect
22+
github.com/hashicorp/go-version v1.7.0 // indirect
23+
github.com/hashicorp/hcl/v2 v2.22.0 // indirect
24+
github.com/hashicorp/terraform-json v0.23.0 // indirect
25+
github.com/jinzhu/copier v0.0.0-20190924061706-b57f9002281a // indirect
26+
github.com/klauspost/compress v1.16.5 // indirect
27+
github.com/mattn/go-zglob v0.0.2-0.20190814121620-e3c945676326 // indirect
28+
github.com/mitchellh/go-homedir v1.1.0 // indirect
29+
github.com/mitchellh/go-testing-interface v1.14.1 // indirect
30+
github.com/mitchellh/go-wordwrap v1.0.1 // indirect
31+
github.com/pmezard/go-difflib v1.0.0 // indirect
32+
github.com/tmccombs/hcl2json v0.6.4 // indirect
33+
github.com/ulikunitz/xz v0.5.10 // indirect
34+
github.com/zclconf/go-cty v1.15.0 // indirect
35+
golang.org/x/crypto v0.36.0 // indirect
36+
golang.org/x/mod v0.21.0 // indirect
37+
golang.org/x/net v0.38.0 // indirect
38+
golang.org/x/sync v0.12.0 // indirect
39+
golang.org/x/sys v0.31.0 // indirect
40+
golang.org/x/text v0.23.0 // indirect
41+
golang.org/x/tools v0.26.0 // indirect
42+
gopkg.in/yaml.v3 v3.0.1 // indirect
43+
)

test/go.sum

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
github.com/agext/levenshtein v1.2.3 h1:YB2fHEn0UJagG8T1rrWknE3ZQzWM06O8AMAatNn7lmo=
2+
github.com/agext/levenshtein v1.2.3/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki2W0IB5558=
3+
github.com/apparentlymart/go-textseg/v15 v15.0.0 h1:uYvfpb3DyLSCGWnctWKGj857c6ew1u1fNQOlOtuGxQY=
4+
github.com/apparentlymart/go-textseg/v15 v15.0.0/go.mod h1:K8XmNZdhEBkdlyDdvbmmsvpAG721bKi0joRfFdHIWJ4=
5+
github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d h1:xDfNPAt8lFiC1UJrqV3uuy861HCTo708pDMbjHHdCas=
6+
github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d/go.mod h1:6QX/PXZ00z/TKoufEY6K/a0k6AhaJrQKdFe6OfVXsa4=
7+
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
8+
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
9+
github.com/go-test/deep v1.0.7 h1:/VSMRlnY/JSyqxQUzQLKVMAskpY/NZKFA5j2P+0pP2M=
10+
github.com/go-test/deep v1.0.7/go.mod h1:QV8Hv/iy04NyLBxAdO9njL0iVPN1S4d/A3NVv1V36o8=
11+
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
12+
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
13+
github.com/gruntwork-io/terratest v0.51.0 h1:RCXlCwWlHqhUoxgF6n3hvywvbvrsTXqoqt34BrnLekw=
14+
github.com/gruntwork-io/terratest v0.51.0/go.mod h1:evZHXb8VWDgv5O5zEEwfkwMhkx9I53QR/RB11cISrpg=
15+
github.com/hashicorp/errwrap v1.0.0 h1:hLrqtEDnRye3+sgx6z4qVLNuviH3MR5aQ0ykNJa/UYA=
16+
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
17+
github.com/hashicorp/go-cleanhttp v0.5.2 h1:035FKYIWjmULyFRBKPs8TBQoi0x6d9G4xc9neXJWAZQ=
18+
github.com/hashicorp/go-cleanhttp v0.5.2/go.mod h1:kO/YDlP8L1346E6Sodw+PrpBSV4/SoxCXGY6BqNFT48=
19+
github.com/hashicorp/go-getter/v2 v2.2.3 h1:6CVzhT0KJQHqd9b0pK3xSP0CM/Cv+bVhk+jcaRJ2pGk=
20+
github.com/hashicorp/go-getter/v2 v2.2.3/go.mod h1:hp5Yy0GMQvwWVUmwLs3ygivz1JSLI323hdIE9J9m7TY=
21+
github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo=
22+
github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM=
23+
github.com/hashicorp/go-safetemp v1.0.0 h1:2HR189eFNrjHQyENnQMMpCiBAsRxzbTMIgBhEyExpmo=
24+
github.com/hashicorp/go-safetemp v1.0.0/go.mod h1:oaerMy3BhqiTbVye6QuFhFtIceqFoDHxNAB65b+Rj1I=
25+
github.com/hashicorp/go-version v1.7.0 h1:5tqGy27NaOTB8yJKUZELlFAS/LTKJkrmONwQKeRZfjY=
26+
github.com/hashicorp/go-version v1.7.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
27+
github.com/hashicorp/hcl/v2 v2.22.0 h1:hkZ3nCtqeJsDhPRFz5EA9iwcG1hNWGePOTw6oyul12M=
28+
github.com/hashicorp/hcl/v2 v2.22.0/go.mod h1:62ZYHrXgPoX8xBnzl8QzbWq4dyDsDtfCRgIq1rbJEvA=
29+
github.com/hashicorp/terraform-json v0.23.0 h1:sniCkExU4iKtTADReHzACkk8fnpQXrdD2xoR+lppBkI=
30+
github.com/hashicorp/terraform-json v0.23.0/go.mod h1:MHdXbBAbSg0GvzuWazEGKAn/cyNfIB7mN6y7KJN6y2c=
31+
github.com/jinzhu/copier v0.0.0-20190924061706-b57f9002281a h1:zPPuIq2jAWWPTrGt70eK/BSch+gFAGrNzecsoENgu2o=
32+
github.com/jinzhu/copier v0.0.0-20190924061706-b57f9002281a/go.mod h1:yL958EeXv8Ylng6IfnvG4oflryUi3vgA3xPs9hmII1s=
33+
github.com/klauspost/compress v1.16.5 h1:IFV2oUNUzZaz+XyusxpLzpzS8Pt5rh0Z16For/djlyI=
34+
github.com/klauspost/compress v1.16.5/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE=
35+
github.com/mattn/go-zglob v0.0.2-0.20190814121620-e3c945676326 h1:ofNAzWCcyTALn2Zv40+8XitdzCgXY6e9qvXwN9W0YXg=
36+
github.com/mattn/go-zglob v0.0.2-0.20190814121620-e3c945676326/go.mod h1:9fxibJccNxU2cnpIKLRRFA7zX7qhkJIQWBb449FYHOo=
37+
github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y=
38+
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
39+
github.com/mitchellh/go-testing-interface v1.14.1 h1:jrgshOhYAUVNMAJiKbEu7EqAwgJJ2JqpQmpLJOu07cU=
40+
github.com/mitchellh/go-testing-interface v1.14.1/go.mod h1:gfgS7OtZj6MA4U1UrDRp04twqAjfvlZyCfX3sDjEym8=
41+
github.com/mitchellh/go-wordwrap v1.0.1 h1:TLuKupo69TCn6TQSyGxwI1EblZZEsQ0vMlAFQflz0v0=
42+
github.com/mitchellh/go-wordwrap v1.0.1/go.mod h1:R62XHJLzvMFRBbcrT7m7WgmE1eOyTSsCt+hzestvNj0=
43+
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
44+
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
45+
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
46+
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
47+
github.com/tmccombs/hcl2json v0.6.4 h1:/FWnzS9JCuyZ4MNwrG4vMrFrzRgsWEOVi+1AyYUVLGw=
48+
github.com/tmccombs/hcl2json v0.6.4/go.mod h1:+ppKlIW3H5nsAsZddXPy2iMyvld3SHxyjswOZhavRDk=
49+
github.com/ulikunitz/xz v0.5.10 h1:t92gobL9l3HE202wg3rlk19F6X+JOxl9BBrCCMYEYd8=
50+
github.com/ulikunitz/xz v0.5.10/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14=
51+
github.com/zclconf/go-cty v1.15.0 h1:tTCRWxsexYUmtt/wVxgDClUe+uQusuI443uL6e+5sXQ=
52+
github.com/zclconf/go-cty v1.15.0/go.mod h1:VvMs5i0vgZdhYawQNq5kePSpLAoz8u1xvZgrPIxfnZE=
53+
github.com/zclconf/go-cty-debug v0.0.0-20240509010212-0d6042c53940 h1:4r45xpDWB6ZMSMNJFMOjqrGHynW3DIBuR2H9j0ug+Mo=
54+
github.com/zclconf/go-cty-debug v0.0.0-20240509010212-0d6042c53940/go.mod h1:CmBdvvj3nqzfzJ6nTCIwDTPZ56aVGvDrmztiO5g3qrM=
55+
golang.org/x/crypto v0.36.0 h1:AnAEvhDddvBdpY+uR+MyHmuZzzNqXSe/GvuDeob5L34=
56+
golang.org/x/crypto v0.36.0/go.mod h1:Y4J0ReaxCR1IMaabaSMugxJES1EpwhBHhv2bDHklZvc=
57+
golang.org/x/mod v0.21.0 h1:vvrHzRwRfVKSiLrG+d4FMl/Qi4ukBCE6kZlTUkDYRT0=
58+
golang.org/x/mod v0.21.0/go.mod h1:6SkKJ3Xj0I0BrPOZoBy3bdMptDDU9oJrpohJ3eWZ1fY=
59+
golang.org/x/net v0.38.0 h1:vRMAPTMaeGqVhG5QyLJHqNDwecKTomGeqbnfZyKlBI8=
60+
golang.org/x/net v0.38.0/go.mod h1:ivrbrMbzFq5J41QOQh0siUuly180yBYtLp+CKbEaFx8=
61+
golang.org/x/sync v0.12.0 h1:MHc5BpPuC30uJk597Ri8TV3CNZcTLu6B6z4lJy+g6Jw=
62+
golang.org/x/sync v0.12.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
63+
golang.org/x/sys v0.31.0 h1:ioabZlmFYtWhL+TRYpcnNlLwhyxaM9kWTDEmfnprqik=
64+
golang.org/x/sys v0.31.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
65+
golang.org/x/term v0.30.0 h1:PQ39fJZ+mfadBm0y5WlL4vlM7Sx1Hgf13sMIY2+QS9Y=
66+
golang.org/x/term v0.30.0/go.mod h1:NYYFdzHoI5wRh/h5tDMdMqCqPJZEuNqVR5xJLd/n67g=
67+
golang.org/x/text v0.23.0 h1:D71I7dUrlY+VX0gQShAThNGHFxZ13dGLBHQLVl1mJlY=
68+
golang.org/x/text v0.23.0/go.mod h1:/BLNzu4aZCJ1+kcD0DNRotWKage4q2rGVAg4o22unh4=
69+
golang.org/x/tools v0.26.0 h1:v/60pFQmzmT9ExmjDv2gGIfi3OqfKoEP6I5+umXlbnQ=
70+
golang.org/x/tools v0.26.0/go.mod h1:TPVVj70c7JJ3WCazhD8OdXcZg/og+b9+tH/KxylGwH0=
71+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
72+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
73+
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
74+
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

test/terratest_test.go

Lines changed: 74 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,24 @@ package test
55

66
import (
77
"os"
8+
"strings"
89
"testing"
10+
"time"
911

12+
"github.com/gruntwork-io/terratest/modules/random"
13+
"github.com/gruntwork-io/terratest/modules/terraform"
14+
"github.com/stretchr/testify/assert"
1015
"github.com/stretchr/testify/require"
1116
)
1217

13-
// TestAzureCredentialsProvided verifies required Azure env vars for Terratest auth are set.
14-
func TestAzureCredentialsProvided(t *testing.T) {
15-
t.Parallel()
18+
// GenerateRandomString generates a random string of specified length using terratest's random package.
19+
// Helper function — reusable in any test
20+
func GenerateRandomString() string {
21+
return random.UniqueId()
22+
}
1623

24+
// TestAzureCredentialsProvided verifies required Azure env vars for Terratest auth are set.
25+
func ValidateAzureCredentials(t *testing.T) {
1726
required := []string{
1827
"ARM_CLIENT_ID",
1928
"ARM_CLIENT_SECRET",
@@ -27,9 +36,67 @@ func TestAzureCredentialsProvided(t *testing.T) {
2736
}
2837
}
2938

30-
// TestTerraformModulePlaceholder is a placeholder for future Terratest integration tests.
31-
// Replace the body with actual terraform.Options, InitAndApply, assertions, and defer Destroy.
32-
func TestTerraformModulePlaceholder(t *testing.T) {
39+
func TestAzureDataFactory(t *testing.T) {
3340
t.Parallel()
34-
t.Skip("placeholder test - implement terraform apply/destroy tests here")
41+
randomString := GenerateRandomString()
42+
t.Logf("Generated random string: %s", randomString)
43+
// 🔹 Step 1: Validate credentials first
44+
ValidateAzureCredentials(t)
45+
resourceGroupName := "rg-adf-" + randomString
46+
t.Logf("Generated resource group name: %s", resourceGroupName)
47+
48+
terraformOptions := &terraform.Options{
49+
// Path to the example usage of the module
50+
TerraformDir: "../examples/sample",
51+
52+
Vars: map[string]interface{}{
53+
"resource_group_name": resourceGroupName,
54+
"location": "centralindia",
55+
"data_factory_name": resourceGroupName + "-df",
56+
57+
// module tags/metadata
58+
"environment": "DEV",
59+
"application_name": "devwithkrishna",
60+
"temporary": "TRUE",
61+
"managed_virtual_network_enabled": false,
62+
"public_network_enabled": true,
63+
},
64+
65+
// Retry settings: Azure sometimes needs extra time for provisioning
66+
MaxRetries: 3,
67+
TimeBetweenRetries: 10 * time.Second,
68+
}
69+
70+
// ensure cleanup
71+
defer terraform.Destroy(t, terraformOptions)
72+
73+
// init + apply
74+
terraform.InitAndApply(t, terraformOptions)
75+
76+
// read outputs
77+
rgOut := terraform.Output(t, terraformOptions, "resource_group_name")
78+
datafactoryNameOut := terraform.Output(t, terraformOptions, "data_factory_name")
79+
publicAccessOut := terraform.Output(t, terraformOptions, "public_access_enabled")
80+
dataFactoryIdout := terraform.Output(t, terraformOptions, "data_factory_id")
81+
tags := terraform.OutputMap(t, terraformOptions, "datafactory_tags")
82+
t.Logf("Datafactory Resource Id: %s", dataFactoryIdout)
83+
t.Logf("Outputs: resourceGroup=%s, DataFactory=%s, DataFactoryId=%s, PublicAccessEnabled=%s", rgOut, datafactoryNameOut, dataFactoryIdout, publicAccessOut)
84+
85+
// basic assertions
86+
assert.Equal(t, resourceGroupName, rgOut)
87+
assert.NotEqual(t, resourceGroupName, datafactoryNameOut)
88+
assert.NotEmpty(t, dataFactoryIdout)
89+
// checking datafactory resource id contains expected substrings
90+
assert.True(t, strings.Contains(dataFactoryIdout, "/Microsoft.DataFactory/factories/"))
91+
// checking datafactory name contains expected substrings
92+
assert.Contains(t, datafactoryNameOut, "df", "Expected Data Factory name to contain 'df'")
93+
// assert.True(t, publicAccessOut, "Expected public access to be enabled")
94+
95+
// ✅ Check that required tags exist
96+
assert.Contains(t, tags, "Environment", "Expected tag 'Environment' to be present")
97+
assert.Contains(t, tags, "ApplicationName", "Expected tag 'ApplicationName' to be present")
98+
99+
// Optional: Check tag values
100+
assert.Equal(t, "DEV", tags["Environment"], "Expected environment=DEV")
101+
35102
}

0 commit comments

Comments
 (0)