Skip to content

Add acceptance tests and ignore no such file or directory errors in cleaning rendered website dir #296

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changes/unreleased/BUG FIXES-20231108-172558.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: BUG FIXES
body: 'generate: fix `no such file or directory` error when running `generate` with
no existing rendered website directory.'
time: 2023-11-08T17:25:58.561956-05:00
custom:
Issue: "296"
3 changes: 3 additions & 0 deletions .copywrite.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ project {
".changes/unreleased/*.yaml",
".changie.yaml",

# examples used within documentation (prose)
"internal/provider/testdata/**",

# GitHub issue template configuration
".github/ISSUE_TEMPLATE/*.yml",

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@ jobs:
args: --timeout=3m
- name: go vet
run: go vet ./...
- name: Run tests
run: go test -v -cover -race ./...
- name: Run acceptance tests
run: make testacc
8 changes: 3 additions & 5 deletions GNUmakefile
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
TEST?=./...

default: build

.PHONY: build test
.PHONY: build testacc

build:
go install ./cmd/tfplugindocs

test:
go test $(TEST) $(TESTARGS) -timeout=5m
testacc:
ACCTEST=1 go test -v -cover -race -timeout 120m ./...

# Generate copywrite headers
generate:
Expand Down
18 changes: 18 additions & 0 deletions cmd/build/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

package build

var (
// These vars will be set by goreleaser.
version string = `dev`
commit string = ``
)

func GetVersion() string {
version := "tfplugindocs" + " Version " + version
if commit != "" {
version += " from commit " + commit
}
return version
}
17 changes: 1 addition & 16 deletions cmd/tfplugindocs/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,9 @@ package main
import (
"os"

"github.com/mattn/go-colorable"

"github.com/hashicorp/terraform-plugin-docs/internal/cmd"
)

func main() {
name := "tfplugindocs"
version := name + " Version " + version
if commit != "" {
version += " from commit " + commit
}

os.Exit(cmd.Run(
name,
version,
os.Args[1:],
os.Stdin,
colorable.NewColorableStdout(),
colorable.NewColorableStderr(),
))
os.Exit(cmd.Main())
}
40 changes: 40 additions & 0 deletions cmd/tfplugindocs/main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

package main

import (
"os"
"testing"

"github.com/rogpeppe/go-internal/testscript"

"github.com/hashicorp/terraform-plugin-docs/internal/cmd"
)

func TestMain(m *testing.M) {
os.Exit(testscript.RunMain(m, map[string]func() int{
"tfplugindocs": cmd.Main,
}))
}

func Test_GenerateAcceptanceTests(t *testing.T) {
t.Parallel()
if os.Getenv("ACCTEST") == "" {
t.Skip("ACCTEST env var not set; skipping acceptance tests.")
}
// Setting a custom temp dir instead of relying on os.TempDir()
// because Terraform providers fail to start up when $TMPDIR
// length is too long: https://github.com/hashicorp/terraform/issues/32787
tmpDir := "/tmp/tftmp"
err := os.MkdirAll(tmpDir, 0755)
if err != nil {
t.Errorf("Error creating temp dir for testing: %s", err.Error())
}
defer os.RemoveAll(tmpDir)

testscript.Run(t, testscript.Params{
Dir: "testdata/scripts/generate",
WorkdirRoot: tmpDir,
})
}
Loading