Skip to content

Commit 406c4f3

Browse files
committed
terratest changes
1 parent cecb1af commit 406c4f3

File tree

1 file changed

+31
-22
lines changed

1 file changed

+31
-22
lines changed

articles/terraform/terratest-in-terraform-modules.md

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -243,14 +243,17 @@ func TestUT_StorageAccountName(t *testing.T) {
243243

244244
To run the unit tests, complete the following steps on the command line:
245245

246+
```azurecli
247+
az login # Required when no service principal environment variables are present
248+
```
249+
246250
```shell
247-
$ cd [Your GoPath]/src/staticwebpage
248-
GoPath/src/staticwebpage$ dep init # Run only once for this folder
249-
GoPath/src/staticwebpage$ dep ensure # Required to run if you imported new packages in test cases
250-
GoPath/src/staticwebpage$ cd test
251-
GoPath/src/staticwebpage/test$ go fmt
252-
GoPath/src/staticwebpage/test$ az login # Required when no service principal environment variables are present
253-
GoPath/src/staticwebpage/test$ go test -run TestUT_StorageAccountName
251+
cd [Your GoPath]/src/staticwebpage
252+
dep init # Run only once for this folder
253+
dep ensure # Required to run if you imported new packages in test cases
254+
cd test
255+
go fmt
256+
go test -run TestUT_StorageAccountName
254257
```
255258

256259
The traditional Go test result returns in about a minute.
@@ -364,21 +367,24 @@ func TestIT_HelloWorldExample(t *testing.T) {
364367

365368
To run the integration tests, complete the following steps on the command line:
366369

370+
```azurecli
371+
az login # Required when no service principal environment variables are present
372+
```
373+
367374
```shell
368-
$ cd [Your GoPath]/src/staticwebpage
369-
GoPath/src/staticwebpage$ dep init # Run only once for this folder
370-
GoPath/src/staticwebpage$ dep ensure # Required to run if you imported new packages in test cases
371-
GoPath/src/staticwebpage$ cd test
372-
GoPath/src/staticwebpage/test$ go fmt
373-
GoPath/src/staticwebpage/test$ az login # Required when no service principal environment variables are present
374-
GoPath/src/staticwebpage/test$ go test -run TestIT_HelloWorldExample
375+
cd [Your GoPath]/src/staticwebpage
376+
dep init # Run only once for this folder
377+
dep ensure # Required to run if you imported new packages in test cases
378+
cd test
379+
go fmt
380+
go test -run TestIT_HelloWorldExample
375381
```
376382

377383
The traditional Go test result returns in about two minutes. You could also run both unit tests and integration tests by executing these commands:
378384

379385
```shell
380-
GoPath/src/staticwebpage/test$ go fmt
381-
GoPath/src/staticwebpage/test$ go test
386+
go fmt
387+
go test
382388
```
383389

384390
Integration tests take much longer than unit tests (two minutes for one integration case compared to one minute for five unit cases). But it's your decision whether to use unit tests or integration tests in a scenario. Typically, we prefer to use unit tests for complex logic by using Terraform HCL functions. We usually use integration tests for the end-to-end perspective of a user.
@@ -491,13 +497,16 @@ func Clean() error {
491497

492498
You can use the following commands to execute a full test suite. The code is similar to the running steps we used in an earlier section.
493499

500+
```azurecli
501+
az login # Required when no service principal environment variables are present
502+
```
503+
494504
```shell
495-
$ cd [Your GoPath]/src/staticwebpage
496-
GoPath/src/staticwebpage$ dep init # Run only once for this folder
497-
GoPath/src/staticwebpage$ dep ensure # Required to run if you imported new packages in magefile or test cases
498-
GoPath/src/staticwebpage$ go fmt # Only required when you change the magefile
499-
GoPath/src/staticwebpage$ az login # Required when no service principal environment variables are present
500-
GoPath/src/staticwebpage$ mage
505+
cd [Your GoPath]/src/staticwebpage
506+
dep init # Run only once for this folder
507+
dep ensure # Required to run if you imported new packages in magefile or test cases
508+
go fmt # Only required when you change the magefile
509+
mage
501510
```
502511

503512
You can replace the last command line with additional mage steps. For example, you can use `mage unit` or `mage clean`. It's a good idea to embed `dep` commands and `az login` in the magefile. We don't show the code here.

0 commit comments

Comments
 (0)