Skip to content

Commit 18a9384

Browse files
committed
Add tests to ensure tf-docs will create something at all
1 parent 52de8f0 commit 18a9384

File tree

11 files changed

+109
-5
lines changed

11 files changed

+109
-5
lines changed

Makefile

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ ifneq (,)
22
.error This Makefile requires GNU Make.
33
endif
44

5-
.PHONY: build rebuild lint test _test-version _test-run tag pull login push enter
5+
.PHONY: build rebuild lint test _test-version _test-run-one _test-run-two tag pull login push enter
66

77
CURRENT_DIR = $(dir $(abspath $(lastword $(MAKEFILE_LIST))))
88

@@ -27,7 +27,8 @@ lint:
2727

2828
test:
2929
@$(MAKE) --no-print-directory _test-version
30-
@$(MAKE) --no-print-directory _test-run
30+
@$(MAKE) --no-print-directory _test-run-one
31+
@$(MAKE) --no-print-directory _test-run-two
3132

3233
_test-version:
3334
@echo "------------------------------------------------------------"
@@ -42,7 +43,7 @@ _test-version:
4243
| head -1 \
4344
| sed 's/.*v//g' \
4445
)"; \
45-
echo "Testing for latest: $${LATEST}"; \
46+
echo "Testing for latest: dev"; \
4647
if ! docker run --rm $(IMAGE) | grep -E "^(terraform-docs[[:space:]])?(version[[:space:]])?dev"; then \
4748
echo "Failed"; \
4849
exit 1; \
@@ -56,9 +57,30 @@ _test-version:
5657
fi; \
5758
echo "Success"; \
5859

59-
_test-run:
60+
_test-run-one:
6061
@echo "------------------------------------------------------------"
61-
@echo "- Testing terraform-docs"
62+
@echo "- Testing terraform-docs (1/2)"
63+
@echo "------------------------------------------------------------"
64+
@echo '<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->' > tests/basic/TEST-$(TAG).md
65+
@echo >> tests/basic/TEST-$(TAG).md
66+
@echo '<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->' >> tests/basic/TEST-$(TAG).md
67+
@if ! docker run --rm -v $(CURRENT_DIR)/tests/basic:/data $(IMAGE) terraform-docs-replace md TEST-$(TAG).md; then \
68+
echo "Failed"; \
69+
exit 1; \
70+
fi; \
71+
if ! grep '## Inputs' tests/basic/TEST-$(TAG).md; then \
72+
echo "Failed"; \
73+
exit 1; \
74+
fi; \
75+
if ! grep 'test description' tests/basic/TEST-$(TAG).md; then \
76+
echo "Failed"; \
77+
exit 1; \
78+
fi; \
79+
echo "Success";
80+
81+
_test-run-two:
82+
@echo "------------------------------------------------------------"
83+
@echo "- Testing terraform-docs (2/2)"
6284
@echo "------------------------------------------------------------"
6385
$(eval TFDOC_ARG_SORT = $(shell \
6486
if [ "$(TAG)" = "latest" ] || [ "$(TAG)" = "0.6.0" ] || [ "$(TAG)" = "0.5.0" ]; then \
@@ -70,10 +92,12 @@ _test-run:
7092
echo "--with-aggregate-type-defaults"; \
7193
fi; \
7294
))
95+
@# ---- Test Terraform < 0.12 ----
7396
@if ! docker run --rm -v $(CURRENT_DIR)/tests/default:/data $(IMAGE) terraform-docs-replace $(TFDOC_ARG_SORT) $(TFDOC_ARG_AGGREGATE) md TEST-$(TAG).md; then \
7497
echo "Failed"; \
7598
exit 1; \
7699
fi
100+
@# ---- Test Terraform >= 0.12 ----
77101
@if ! docker run --rm -v $(CURRENT_DIR)/tests/0.12:/data $(IMAGE) terraform-docs-replace-012 $(TFDOC_ARG_SORT) $(TFDOC_ARG_AGGREGATE) md TEST-$(TAG).md; then \
78102
echo "Failed"; \
79103
exit 1; \

tests/basic/TEST-0.1.0.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
2+
3+
## Inputs
4+
5+
| Name | Description | Default | Required |
6+
|------|-------------|:-----:|:-----:|
7+
| test | test description | - | yes |
8+
9+
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->

tests/basic/TEST-0.1.1.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
2+
3+
## Inputs
4+
5+
| Name | Description | Type | Default | Required |
6+
|------|-------------|:----:|:-----:|:-----:|
7+
| test | test description | string | - | yes |
8+
9+
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->

tests/basic/TEST-0.2.0.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
2+
3+
## Inputs
4+
5+
| Name | Description | Type | Default | Required |
6+
|------|-------------|:----:|:-----:|:-----:|
7+
| test | test description | string | - | yes |
8+
9+
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->

tests/basic/TEST-0.3.0.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
2+
3+
## Inputs
4+
5+
| Name | Description | Type | Default | Required |
6+
|------|-------------|:----:|:-----:|:-----:|
7+
| test | test description | string | - | yes |
8+
9+
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->

tests/basic/TEST-0.4.0.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
2+
3+
## Inputs
4+
5+
| Name | Description | Type | Default | Required |
6+
|------|-------------|:----:|:-----:|:-----:|
7+
| test | test description | string | - | yes |
8+
9+
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->

tests/basic/TEST-0.4.5.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
2+
## Inputs
3+
4+
| Name | Description | Type | Default | Required |
5+
|------|-------------|:----:|:-----:|:-----:|
6+
| test | test description | string | - | yes |
7+
8+
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->

tests/basic/TEST-0.5.0.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
2+
## Inputs
3+
4+
| Name | Description | Type | Default | Required |
5+
|------|-------------|:----:|:-----:|:-----:|
6+
| test | test description | string | - | yes |
7+
8+
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->

tests/basic/TEST-0.6.0.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
2+
## Inputs
3+
4+
| Name | Description | Type | Default | Required |
5+
|------|-------------|:----:|:-----:|:-----:|
6+
| test | test description | string | n/a | yes |
7+
8+
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->

tests/basic/TEST-latest.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
2+
## Inputs
3+
4+
| Name | Description | Type | Default | Required |
5+
|------|-------------|:----:|:-----:|:-----:|
6+
| test | test description | string | n/a | yes |
7+
8+
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->

0 commit comments

Comments
 (0)