Skip to content

Commit 49d4329

Browse files
committed
Apply tf dev override in unit test
1 parent 9594fae commit 49d4329

File tree

2 files changed

+30
-14
lines changed

2 files changed

+30
-14
lines changed

Makefile

+4-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ build:
55
GO111MODULE=on go build -o ${build_dir}/tfplan2cai ./cmd/tfplan2cai
66

77
test:
8-
GO111MODULE=on go test -short ./...
8+
go version
9+
terraform --version
10+
./config-tf-dev-override.sh
11+
TF_CLI_CONFIG_FILE="${PWD}/${TF_CONFIG_FILE}" GO111MODULE=on go test -short ./...
912

1013
test-integration:
1114
go version

docs/contributing/index.md

+26-13
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Contributing
22

3-
If you want to contribute to Terraform Google Conversion, check out the [contribution guidelines](../../CONTRIBUTING.md)
3+
If you want to contribute to Terraform Google Conversion, check out the
4+
[contribution guidelines](../../CONTRIBUTING.md)
45

56
## Table of Contents
67

@@ -11,23 +12,21 @@ If you want to contribute to Terraform Google Conversion, check out the [contrib
1112
- [Integration Test](#integration-test)
1213
- [Add a new resource](#add-a-new-resource)
1314

14-
1515
## Testing
1616

17-
### Unit Test
18-
```bash
19-
# Unit tests
20-
make test
21-
```
17+
The read test(one of the unit tests) and integration test installs the provider
18+
binary and creates a terraform dev override file tf-dev-override.tfrc.
19+
[Dev override](https://googlecloudplatform.github.io/magic-modules/develop/run-tests/#optional-test-manually)
20+
is to make sure the test runs against the provider version specified in the go
21+
module. You can place your own config to point to a different go binary
22+
destination within tf-dev-override.tfrc. If the file already exists, it will not
23+
be overwritten.
2224

23-
### Integration Test
25+
It is better to run both the unit test and integration tests inside a Docker
26+
container to match the CI/CD pipeline.
2427

2528
**Note:** Integration tests require a test project.
2629

27-
It is better to run the integration tests inside a Docker container to match the CI/CD pipeline.
28-
29-
The integration test installs the provider binary and creates a terraform dev override file tf-dev-override.tfrc. [Dev override](https://googlecloudplatform.github.io/magic-modules/develop/run-tests/#optional-test-manually) is to make sure the test runs against the provider version specified in the go module. You can place your own config within tf-dev-override.tfrc. If the file already exists, it will not be overwritten.
30-
3130
```bash
3231
# Integration tests (interacts with real APIs)
3332

@@ -38,13 +37,27 @@ export TEST_CREDENTIALS=~/.config/gcloud/application_default_credentials.json
3837

3938
# Spin up a docker container to run tests.
4039
make run-docker
40+
```
41+
42+
### Unit Test
4143

44+
The read test(tfplan2cai/test/read_test.go) runs terraform binary to generate
45+
`.tfplan.json` files. It requires gcloud credential during that process.
46+
47+
```bash
48+
# Inside the docker container,
49+
# run this to setup dev override and run unit tests.
50+
make test
51+
```
52+
53+
### Integration Test
54+
55+
```bash
4256
# Inside the docker container,
4357
# run this to setup dev override and run integration tests.
4458
make test-integration
4559
```
4660

47-
4861
### Add a new resource
4962

5063
See [Add a new resource](./add_new_resource.md)

0 commit comments

Comments
 (0)