Skip to content

Commit

Permalink
test: use ci job matrix and fix acceptance tests
Browse files Browse the repository at this point in the history
Co-Authored-by: pauhull <[email protected]>
  • Loading branch information
jooola and phm07 committed Nov 3, 2023
1 parent 451abe2 commit 1a9a88d
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 154 deletions.
46 changes: 0 additions & 46 deletions .github/workflows/go-test-darwin.yml

This file was deleted.

44 changes: 0 additions & 44 deletions .github/workflows/go-test-linux.yml

This file was deleted.

45 changes: 0 additions & 45 deletions .github/workflows/go-test-windows.yml

This file was deleted.

45 changes: 45 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Test

on:
push:
branches: [main]
pull_request:

permissions:
contents: read

jobs:
unit:
strategy:
fail-fast: false
matrix:
runs-on: [ubuntu-latest, windows-latest, macos-latest]

runs-on: ${{ matrix.runs-on }}
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
go-version: "1.20"

- run: make test

acceptance:
strategy:
fail-fast: false
matrix:
runs-on: [ubuntu-latest, windows-latest, macos-latest]

permissions:
id-token: write # Required by hetznercloud/tps-action

runs-on: ${{ matrix.runs-on }}
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
go-version: "1.20"

- uses: hetznercloud/tps-action@main

- run: make testacc
36 changes: 20 additions & 16 deletions GNUmakefile
Original file line number Diff line number Diff line change
@@ -1,34 +1,38 @@
NAME=hcloud
BINARY=packer-plugin-${NAME}
BINARY=packer-plugin-$(NAME)
ifeq ($(OS), Windows_NT)
# Prevent "Ignoring plugin match packer-plugin-hcloud, no exe extension"
BINARY=packer-plugin-$(NAME).exe
endif

COUNT?=1
TEST?=$(shell go list ./...)
TEST?=./...
HASHICORP_PACKER_PLUGIN_SDK_VERSION?=$(shell go list -m github.com/hashicorp/packer-plugin-sdk | cut -d " " -f2)

.PHONY: dev

build:
@go build -o ${BINARY}
go build -o $(BINARY)

dev: build
@mkdir -p ~/.packer.d/plugins/
@mv ${BINARY} ~/.packer.d/plugins/${BINARY}
mkdir -p ~/.config/packer/plugins
mv $(BINARY) ~/.config/packer/plugins

test:
@go test -race -count $(COUNT) $(TEST) -timeout=3m
go test -race -count $(COUNT) -v $(TEST) -timeout=3m

install-packer-sdc: ## Install packer sofware development command
@go install github.com/hashicorp/packer-plugin-sdk/cmd/packer-sdc@${HASHICORP_PACKER_PLUGIN_SDK_VERSION}
install-packer-sdc: ## Install packer software development command
go install github.com/hashicorp/packer-plugin-sdk/cmd/packer-sdc@$(HASHICORP_PACKER_PLUGIN_SDK_VERSION)

plugin-check: install-packer-sdc build
@packer-sdc plugin-check ${BINARY}
packer-sdc plugin-check $(BINARY)

testacc: dev
@PACKER_ACC=1 go test -count $(COUNT) -v $(TEST) -timeout=120m
testacc: build
PACKER_ACC=1 PACKER_PLUGIN_PATH=$(PWD) go test -count $(COUNT) -v $(TEST) -timeout=120m

generate: install-packer-sdc
@go generate ./...
@rm -rf .docs
@packer-sdc renderdocs -src "docs" -partials docs-partials/ -dst ".docs/"
@./.web-docs/scripts/compile-to-webdocs.sh "." ".docs" ".web-docs" "hashicorp"
@rm -r ".docs"
go generate ./...
rm -rf .docs
packer-sdc renderdocs -src "docs" -partials docs-partials/ -dst ".docs/"
./.web-docs/scripts/compile-to-webdocs.sh "." ".docs" ".web-docs" "hashicorp"
rm -r ".docs"
16 changes: 13 additions & 3 deletions builder/hcloud/builder_acc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,22 @@ func TestBuilderAcc_basic(t *testing.T) {
return nil
},
Template: testBuilderAccBasic,
Check: func(buildCommand *exec.Cmd, logfile string) error {
Check: func(buildCommand *exec.Cmd, logFile string) error {
if buildCommand.ProcessState != nil {
if buildCommand.ProcessState.ExitCode() != 0 {
return fmt.Errorf("Bad exit code. Logfile: %s", logfile)
if buildCommand.ProcessState.ExitCode() == 0 {
return nil
}

logs, err := os.ReadFile(logFile)
if err != nil {
return err
}
return fmt.Errorf("invalid exit code: %d\n%s",
buildCommand.ProcessState.ExitCode(),
logs,
)
}

return nil
},
}
Expand Down

0 comments on commit 1a9a88d

Please sign in to comment.