Skip to content

Commit d4457c4

Browse files
authored
test: cleanup test setup (#829)
- Remove unused script - Remove custom linting script in favor of golangci lint - Remove old TTS leftover - Format/cleanf files - Pick go version from go.mod file
1 parent 7f6cb76 commit d4457c4

12 files changed

+55
-181
lines changed

.errcheck_excludes.txt

-1
This file was deleted.

.github/workflows/dev_release.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jobs:
2828
name: Set up Go
2929
uses: actions/setup-go@v5
3030
with:
31-
go-version: "1.21"
31+
go-version-file: go.mod
3232
-
3333
name: Import GPG key
3434
id: import_gpg

.github/workflows/lint.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ jobs:
1212
- uses: actions/checkout@v4
1313
- uses: actions/setup-go@v5
1414
with:
15-
go-version: "1.21"
15+
go-version-file: go.mod
1616
cache: false
17-
17+
1818
- uses: golangci/golangci-lint-action@v3
1919
with:
2020
version: v1.55.2 # renovate: datasource=github-releases depName=golangci/golangci-lint

.github/workflows/release.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ jobs:
2929
name: Set up Go
3030
uses: actions/setup-go@v5
3131
with:
32-
go-version: "1.21"
32+
go-version-file: go.mod
3333
-
3434
name: Import GPG key
3535
id: import_gpg

.github/workflows/test.yml

+27-45
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,58 @@
11
name: Test
22

33
on:
4+
push:
5+
branches: [main]
46
pull_request:
57

68
jobs:
9+
test:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v4
13+
14+
- uses: actions/setup-go@v5
15+
with:
16+
go-version-file: go.mod
17+
18+
- run: make test
19+
720
integration:
8-
name: Integration ${{ matrix.terraform }}
21+
runs-on: ubuntu-latest
22+
923
permissions:
1024
id-token: write
11-
runs-on: ubuntu-latest
25+
1226
strategy:
1327
matrix:
14-
terraform: [ v1.5.x, v1.6.x ]
28+
terraform: [v1.5.x, v1.6.x]
1529
fail-fast: false
30+
1631
steps:
17-
- name: Checkout
18-
uses: actions/checkout@v4
19-
- name: Unshallow
20-
run: git fetch --prune --unshallow
32+
- uses: actions/checkout@v4
33+
2134
- uses: hashicorp/setup-terraform@v3
2235
with:
2336
terraform_version: ${{ matrix.terraform }}
2437
terraform_wrapper: false
25-
- name: Set up Go
26-
uses: actions/setup-go@v5
38+
39+
- uses: actions/setup-go@v5
2740
with:
28-
go-version: "1.21"
29-
- name: HCLOUD_TOKEN
30-
env:
31-
HCLOUD_TOKEN: ${{ secrets.HCLOUD_TOKEN }}
32-
run: |
33-
echo "HCLOUD_TOKEN=$HCLOUD_TOKEN" >> "$GITHUB_ENV"
41+
go-version-file: go.mod
3442

3543
- uses: hetznercloud/tps-action@main
36-
if: ${{ vars.USE_TPS }}
3744

38-
- name: check HCLOUD_TOKEN
39-
run: |
40-
if [[ "${HCLOUD_TOKEN:-}" == "" ]]; then
41-
echo "::error ::Couldn't determine HCLOUD_TOKEN. Are repository secrets correctly set?"
42-
exit 1
43-
fi
44-
- name: Run tests
45+
- run: make testacc
4546
env:
46-
# Domain must be available in the account running the tests. This domain is available in the account
47-
# running the public integration tests.
47+
# Domain must be available in the account running the tests. This domain is
48+
# available in the account running the public integration tests.
4849
CERT_DOMAIN: hc-integrations-test.de
4950

50-
# Debug Logs
5151
TF_LOG: DEBUG
5252
TF_LOG_PATH: test.log
53-
run: |
54-
make testacc
55-
make
5653

5754
- uses: actions/upload-artifact@v4
58-
if: always() # Also run if the tests failed
55+
if: always()
5956
with:
6057
name: debug-logs-${{ matrix.terraform }}
6158
path: internal/e2etests/**/test.log
62-
63-
unit_tests:
64-
runs-on: ubuntu-latest
65-
steps:
66-
- name: Checkout
67-
uses: actions/checkout@v4
68-
- name: Unshallow
69-
run: git fetch --prune --unshallow
70-
- name: Set up Go
71-
uses: actions/setup-go@v5
72-
with:
73-
go-version: "1.21"
74-
- name: Run tests
75-
run: |
76-
make test

.golangci.yaml

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
---
22
linters-settings:
33
errcheck:
4-
exclude: ./.errcheck_excludes.txt
4+
exclude-functions:
5+
- (*github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.ResourceData).Set
56
misspell:
6-
locale: "US"
7+
locale: US
78

89
linters:
910
disable-all: true
1011
enable:
12+
- gofmt
1113
- bodyclose
1214
- errcheck
1315
- exportloopref
@@ -33,8 +35,5 @@ issues:
3335
- exportloopref
3436
- gosec
3537
- errcheck
36-
- path: testing.go
38+
- path: testing\.go
3739
text: unused-parameter
38-
- linters:
39-
- gosec
40-
text: "G401:"

GNUmakefile

+9-35
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
TEST?=$$(go list ./... |grep -v 'vendor')
2-
GOFMT_FILES?=$$(find . -name '*.go' |grep -v vendor)
1+
TEST?=./...
32
VERSION=$(shell ./scripts/git-version.sh)
43
PKG_NAME=hcloud
54
WEBSITE_REPO=github.com/hashicorp/terraform-website
65
export CGO_ENABLED:=0
76

87
default: build
98

10-
build: fmtcheck
9+
build:
1110
go install
1211

1312
clean:
@@ -56,39 +55,14 @@ _output/terraform-provider-hcloud_%.zip: bin/%/terraform-provider-hcloud
5655
cp bin/$*/terraform-provider-hcloud README.md CHANGELOG.md LICENSE $(DEST)
5756
cd $(DEST) && zip -r ../$(NAME).zip .
5857

59-
test: fmtcheck
60-
go test $(TEST) || exit 1
61-
echo $(TEST) | \
62-
xargs -t -n4 go test $(TESTARGS) -timeout=30s -parallel=8
58+
lint:
59+
golangci-lint run --fix
6360

64-
testacc: fmtcheck
65-
TF_ACC=1 go test $(TEST) -v $(TESTARGS) -timeout 30m -parallel=8
61+
test:
62+
go test $(TEST) $(TESTARGS) -v -timeout=30s -parallel=8
6663

67-
vet:
68-
@echo "go vet ."
69-
@go vet $$(go list ./... | grep -v vendor/) ; if [ $$? -eq 1 ]; then \
70-
echo ""; \
71-
echo "Vet found suspicious constructs. Please check the reported constructs"; \
72-
echo "and fix them if necessary before submitting the code for review."; \
73-
exit 1; \
74-
fi
75-
76-
fmt:
77-
gofmt -w $(GOFMT_FILES)
78-
79-
fmtcheck:
80-
@sh -c "'$(CURDIR)/scripts/gofmtcheck.sh'"
81-
82-
errcheck:
83-
@sh -c "'$(CURDIR)/scripts/errcheck.sh'"
84-
85-
test-compile:
86-
@if [ "$(TEST)" = "./..." ]; then \
87-
echo "ERROR: Set TEST to a specific package. For example,"; \
88-
echo " make test-compile TEST=./aws"; \
89-
exit 1; \
90-
fi
91-
go test -c $(TEST) $(TESTARGS)
64+
testacc:
65+
TF_ACC=1 go test $(TEST) $(TESTARGS) -v -timeout=30m -parallel=8
9266

9367
website:
9468
ifeq (,$(wildcard $(GOPATH)/src/$(WEBSITE_REPO)))
@@ -105,4 +79,4 @@ endif
10579
@$(MAKE) -C $(GOPATH)/src/$(WEBSITE_REPO) website-provider-test PROVIDER_PATH=$(shell pwd) PROVIDER_NAME=$(PKG_NAME)
10680

10781

108-
.PHONY: build test testacc vet fmt fmtcheck errcheck test-compile release clean clean-release website website-test
82+
.PHONY: build test testacc release clean clean-release website website-test

scripts/changelog-links.sh

-31
This file was deleted.

scripts/errcheck.sh

-24
This file was deleted.

scripts/git-version.sh

+10-12
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,29 @@
11
#!/usr/bin/env bash
22

3-
set -e
3+
set -eu
44

55
# parse the current git commit hash
6-
COMMIT=`git rev-parse HEAD`
6+
COMMIT="$(git rev-parse HEAD)"
77

88
# check if the current commit has a matching tag
9-
TAG=$(git describe --exact-match --abbrev=0 --tags ${COMMIT} 2> /dev/null || true)
10-
SUFFIX=''
11-
DETAIL=''
9+
TAG="$(git describe --exact-match --abbrev=0 --tags "$COMMIT" 2> /dev/null || true)"
10+
SUFFIX=""
11+
DETAIL=""
1212

1313
# use the matching tag as the version, if available
1414
if [ -z "$TAG" ]; then
1515
TAG=$(git describe --abbrev=0)
16-
COMMITS=$(git --no-pager log ${TAG}..HEAD --oneline)
17-
COMMIT_COUNT=$(echo -e "${COMMITS}" | wc -l)
18-
COMMIT_COUNT_PADDING=$(printf %03d $COMMIT_COUNT)
16+
COMMITS=$(git --no-pager log "$TAG..HEAD" --oneline)
17+
COMMIT_COUNT=$(echo -e "$COMMITS" | wc -l)
18+
COMMIT_COUNT_PADDING=$(printf %03d "$COMMIT_COUNT")
1919
SHORT_COMMIT_ID=$(git rev-parse --short HEAD)
2020

21-
SUFFIX='-dev'
21+
SUFFIX="-dev"
2222
DETAIL=".${COMMIT_COUNT_PADDING}.${SHORT_COMMIT_ID}"
2323
fi
2424

2525
if [ -n "$(git diff --shortstat 2> /dev/null | tail -n1)" ]; then
2626
SUFFIX="-dirty"
2727
fi
2828

29-
30-
VERSION="${TAG}${SUFFIX}${DETAIL}"
31-
echo $VERSION
29+
echo "${TAG}${SUFFIX}${DETAIL}"

scripts/gofmtcheck.sh

-13
This file was deleted.

scripts/gogetcookies.sh

-10
This file was deleted.

0 commit comments

Comments
 (0)