Skip to content

Commit

Permalink
Move acceptance and tools to root
Browse files Browse the repository at this point in the history
This sets up the acceptance tests as a separate go module and moves
acceptance and tools from `internal` to repository root to better
reflect them as modules.
  • Loading branch information
zregvart committed Jan 10, 2023
1 parent 670d591 commit 8b42166
Show file tree
Hide file tree
Showing 39 changed files with 3,080 additions and 1,156 deletions.
6 changes: 5 additions & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ updates:
schedule:
interval: "daily"
- package-ecosystem: "gomod"
directory: "/internal/tools/"
directory: "/tools/"
schedule:
interval: "daily"
- package-ecosystem: "gomod"
directory: "/acceptance/"
schedule:
interval: "daily"
4 changes: 2 additions & 2 deletions .github/workflows/checks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ jobs:
- name: Download go dependencies
run: |
go mod download
go mod download -modfile internal/tools/go.mod
go mod download -modfile tools/go.mod
go mod download -modfile acceptance/go.mod
- name: Test
run: make test
Expand Down Expand Up @@ -92,7 +93,6 @@ jobs:
- name: Download go dependencies
run: |
go mod download
go mod download -modfile internal/tools/go.mod
- name: Setup Tekton Test environment
run: hack/setup-test-environment.sh
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/codeql.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ jobs:
- name: Download go dependencies
run: |
go mod download
go mod download -modfile internal/tools/go.mod
go mod download -modfile tools/go.mod
go mod download -modfile acceptance/go.mod
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ jobs:
cache-dependency-path: '**/go.sum'

- name: Download go dependencies
run: go mod download
run: |
go mod download
go mod download -modfile tools/go.mod
go mod download -modfile acceptance/go.mod
- name: Lint
run: make lint
3 changes: 2 additions & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ jobs:
- name: Download go dependencies
run: |
go mod download
go mod download -modfile internal/tools/go.mod
go mod download -modfile tools/go.mod
go mod download -modfile acceptance/go.mod
- name: Build distribution
run: make dist
Expand Down
24 changes: 12 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -76,35 +76,35 @@ acceptance: ## Run acceptance tests
@trap cleanup EXIT
@cp -R . "$${ACCEPTANCE_WORKDIR}"
@cd "$${ACCEPTANCE_WORKDIR}"
@go run internal/acceptance/coverage/coverage.go .
@go run acceptance/coverage/coverage.go .
@$(MAKE) build
@export COVERAGE_FILEPATH="$${ACCEPTANCE_WORKDIR}"
@export COVERAGE_FILENAME="-acceptance"
@go test -tags=acceptance ./...
@go run -modfile internal/tools/go.mod github.com/wadey/gocovmerge "$${ACCEPTANCE_WORKDIR}"/coverage-acceptance*.out > "$(ROOT_DIR)/coverage-acceptance.out"
@cd acceptance && go test ./...
@go run -modfile "$${ACCEPTANCE_WORKDIR}/tools/go.mod" github.com/wadey/gocovmerge "$${ACCEPTANCE_WORKDIR}"/coverage-acceptance*.out > "$(ROOT_DIR)/coverage-acceptance.out"

LICENSE_IGNORE=-ignore 'dist/reference/*.yaml'
LINT_TO_GITHUB_ANNOTATIONS='map(map(.)[])[][] as $$d | $$d.posn | split(":") as $$posn | "::warning file=\($$posn[0]),line=\($$posn[1]),col=\($$posn[2])::\($$d.message)"'
.PHONY: lint
lint: ## Run linter
# addlicense doesn't give us a nice explanation so we prefix it with one
@go run -modfile internal/tools/go.mod github.com/google/addlicense -c $(COPY) -s -check $(LICENSE_IGNORE) . | sed 's/^/Missing license header in: /g'
@go run -modfile tools/go.mod github.com/google/addlicense -c $(COPY) -s -check $(LICENSE_IGNORE) . | sed 's/^/Missing license header in: /g'
# piping to sed above looses the exit code, luckily addlicense is fast so we invoke it for the second time to exit 1 in case of issues
@go run -modfile internal/tools/go.mod github.com/google/addlicense -c $(COPY) -s -check $(LICENSE_IGNORE) . >/dev/null 2>&1
@go run -modfile internal/tools/go.mod github.com/golangci/golangci-lint/cmd/golangci-lint run --sort-results $(if $(GITHUB_ACTIONS), --out-format=github-actions --timeout=5m0s)
@go run -modfile tools/go.mod github.com/google/addlicense -c $(COPY) -s -check $(LICENSE_IGNORE) . >/dev/null 2>&1
@go run -modfile tools/go.mod github.com/golangci/golangci-lint/cmd/golangci-lint run --sort-results $(if $(GITHUB_ACTIONS), --out-format=github-actions --timeout=5m0s)
# We don't fail on the internal (error handling) linter, we just report the
# issues for now.
# TODO: resolve the error handling issues and enable the linter failure
@go run -modfile internal/tools/go.mod ./internal/lint $(if $(GITHUB_ACTIONS), -json) $$(go list ./... | grep -v '/internal/acceptance/') $(if $(GITHUB_ACTIONS), | jq -r $(LINT_TO_GITHUB_ANNOTATIONS))
@go run -modfile tools/go.mod ./internal/lint $(if $(GITHUB_ACTIONS), -json) $$(go list ./... | grep -v '/acceptance/') $(if $(GITHUB_ACTIONS), | jq -r $(LINT_TO_GITHUB_ANNOTATIONS))

.PHONY: lint-fix
lint-fix: ## Fix linting issues automagically
@go run -modfile internal/tools/go.mod github.com/google/addlicense -c $(COPY) -s -ignore 'dist/reference/*.yaml' .
@go run -modfile internal/tools/go.mod github.com/golangci/golangci-lint/cmd/golangci-lint run --fix
@go run -modfile tools/go.mod github.com/google/addlicense -c $(COPY) -s -ignore 'dist/reference/*.yaml' .
@go run -modfile tools/go.mod github.com/golangci/golangci-lint/cmd/golangci-lint run --fix
# We don't apply the fixes from the internal (error handling) linter.
# TODO: fix the outstanding error handling lint issues and enable the fixer
# @go run -modfile internal/tools/go.mod ./internal/lint -fix $$(go list ./... | grep -v '/internal/acceptance/')
@go run -modfile internal/tools/go.mod github.com/daixiang0/gci write -s standard -s default -s "prefix(github.com/hacbs-contract/ec-cli)" .
# @go run -modfile tools/go.mod ./internal/lint -fix $$(go list ./... | grep -v '/acceptance/')
@go run -modfile tools/go.mod github.com/daixiang0/gci write -s standard -s default -s "prefix(github.com/hacbs-contract/ec-cli)" .

.PHONY: ci
ci: test lint-fix acceptance ## Run the usual required CI tasks
Expand Down Expand Up @@ -187,7 +187,7 @@ TASK_VERSION ?= 0.1
TASK ?= task/$(TASK_VERSION)/verify-enterprise-contract.yaml
.PHONY: task-bundle
task-bundle: ## Push the Tekton Task bundle an image repository
@go run -modfile internal/tools/go.mod github.com/tektoncd/cli/cmd/tkn bundle push $(TASK_REPO):$(TASK_TAG) -f $(TASK)
@go run -modfile tools/go.mod github.com/tektoncd/cli/cmd/tkn bundle push $(TASK_REPO):$(TASK_TAG) -f $(TASK)

.PHONY: task-bundle-snapshot
task-bundle-snapshot: task-bundle ## Push task bundle and then tag with "snapshot"
Expand Down
6 changes: 3 additions & 3 deletions acceptance/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ following are supported:

These arguments need to be prefixed with `-args` parameter, for example:

$ go test -tags=acceptance ./internal/acceptance -args -persist -tags=@focus
$ go test -tags=acceptance ./acceptance -args -persist -tags=@focus

Notice that there are two arguments called `-tags`. One is for specifying the
build tag, which is always `acceptance` for acceptance tests. The other is for
selecting acceptance test scenarios.

Also notice that there are different ways of specifying the path to the
acceptance tests. `./...` can only be be used if `-args` is NOT used. Use,
`./internal/acceptance` or `github.com/hacbs-contract/ec-cli/internal/acceptance`
`./acceptance` or `github.com/hacbs-contract/ec-cli/acceptance`
in such cases.

Depending on your setup Testcontainer's ryuk container might need to be run as
Expand All @@ -66,7 +66,7 @@ reason `make acceptance` builds the binary prior to running the tests.)

To use a debugger, like [delve](https://github.com/go-delve/delve), you must
determine what part of the code is being debugged. If it's part of the
acceptance module, `github.com/hacbs-contract/ec-cli/internal/acceptance`, or
acceptance module, `github.com/hacbs-contract/ec-cli/acceptance`, or
it is a dependency of the acceptance module, then the debugger can be invoked
directly. However, if the code to be debugged is in any other module, first
run the acceptance tests in `-persist` mode. The, scan the test logs for the
Expand Down
30 changes: 17 additions & 13 deletions acceptance/acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,28 @@
//
// SPDX-License-Identifier: Apache-2.0

//go:build acceptance

package acceptance

import (
"context"
"flag"
"os"
"path/filepath"
"runtime"
"testing"

"github.com/cucumber/godog"

"github.com/hacbs-contract/ec-cli/internal/acceptance/cli"
"github.com/hacbs-contract/ec-cli/internal/acceptance/crypto"
"github.com/hacbs-contract/ec-cli/internal/acceptance/git"
"github.com/hacbs-contract/ec-cli/internal/acceptance/image"
"github.com/hacbs-contract/ec-cli/internal/acceptance/kubernetes"
"github.com/hacbs-contract/ec-cli/internal/acceptance/registry"
"github.com/hacbs-contract/ec-cli/internal/acceptance/rekor"
"github.com/hacbs-contract/ec-cli/internal/acceptance/tekton"
"github.com/hacbs-contract/ec-cli/internal/acceptance/testenv"
"github.com/hacbs-contract/ec-cli/internal/acceptance/wiremock"
"github.com/hacbs-contract/ec-cli/acceptance/cli"
"github.com/hacbs-contract/ec-cli/acceptance/crypto"
"github.com/hacbs-contract/ec-cli/acceptance/git"
"github.com/hacbs-contract/ec-cli/acceptance/image"
"github.com/hacbs-contract/ec-cli/acceptance/kubernetes"
"github.com/hacbs-contract/ec-cli/acceptance/registry"
"github.com/hacbs-contract/ec-cli/acceptance/rekor"
"github.com/hacbs-contract/ec-cli/acceptance/tekton"
"github.com/hacbs-contract/ec-cli/acceptance/testenv"
"github.com/hacbs-contract/ec-cli/acceptance/wiremock"
)

// NOTE: flags need to be initialized with the package in order to be recognized
Expand Down Expand Up @@ -85,7 +84,12 @@ func setupContext(t *testing.T) context.Context {
// in random order in parallel threads equal to the number of available
// cores
func TestFeatures(t *testing.T) {
featuresDir, err := filepath.Abs("../../features")
// change the directory to repository root, makes for easier paths
if err := os.Chdir(".."); err != nil {
t.Error(err)
}

featuresDir, err := filepath.Abs("features")
if err != nil {
t.Error(err)
}
Expand Down
2 changes: 1 addition & 1 deletion acceptance/attestation/attestation.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (
"github.com/sigstore/sigstore/pkg/signature/dsse"
"github.com/sigstore/sigstore/pkg/signature/options"

"github.com/hacbs-contract/ec-cli/internal/acceptance/crypto"
"github.com/hacbs-contract/ec-cli/acceptance/crypto"
)

const (
Expand Down
18 changes: 9 additions & 9 deletions acceptance/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ import (
"github.com/yudai/gojsondiff"
"github.com/yudai/gojsondiff/formatter"

"github.com/hacbs-contract/ec-cli/internal/acceptance/crypto"
"github.com/hacbs-contract/ec-cli/internal/acceptance/git"
"github.com/hacbs-contract/ec-cli/internal/acceptance/image"
"github.com/hacbs-contract/ec-cli/internal/acceptance/kubernetes"
"github.com/hacbs-contract/ec-cli/internal/acceptance/log"
"github.com/hacbs-contract/ec-cli/internal/acceptance/registry"
"github.com/hacbs-contract/ec-cli/internal/acceptance/rekor"
"github.com/hacbs-contract/ec-cli/internal/acceptance/testenv"
"github.com/hacbs-contract/ec-cli/acceptance/crypto"
"github.com/hacbs-contract/ec-cli/acceptance/git"
"github.com/hacbs-contract/ec-cli/acceptance/image"
"github.com/hacbs-contract/ec-cli/acceptance/kubernetes"
"github.com/hacbs-contract/ec-cli/acceptance/log"
"github.com/hacbs-contract/ec-cli/acceptance/registry"
"github.com/hacbs-contract/ec-cli/acceptance/rekor"
"github.com/hacbs-contract/ec-cli/acceptance/testenv"
)

type status struct {
Expand All @@ -67,7 +67,7 @@ const (
func ecCommandIsRunWith(ctx context.Context, parameters string) (context.Context, error) {
// path to the ec* binary given specific operating system and archive as built by
// make build
ec := path.Join("..", "..", "dist", fmt.Sprintf("ec_%s_%s", runtime.GOOS, runtime.GOARCH))
ec := path.Join("dist", fmt.Sprintf("ec_%s_%s", runtime.GOOS, runtime.GOARCH))
info, err := os.Stat(ec)
if err != nil {
if errors.Is(err, os.ErrNotExist) {
Expand Down
2 changes: 0 additions & 2 deletions acceptance/cli/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
//
// SPDX-License-Identifier: Apache-2.0

//go:build unit

package cli

import (
Expand Down
2 changes: 1 addition & 1 deletion acceptance/crypto/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
"github.com/sigstore/cosign/pkg/cosign"
"github.com/sigstore/sigstore/pkg/signature"

"github.com/hacbs-contract/ec-cli/internal/acceptance/testenv"
"github.com/hacbs-contract/ec-cli/acceptance/testenv"
)

type keys int
Expand Down
8 changes: 4 additions & 4 deletions acceptance/git/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ import (
"github.com/testcontainers/testcontainers-go"
"github.com/testcontainers/testcontainers-go/wait"

"github.com/hacbs-contract/ec-cli/internal/acceptance/log"
"github.com/hacbs-contract/ec-cli/internal/acceptance/testenv"
"github.com/hacbs-contract/ec-cli/internal/acceptance/wiremock"
"github.com/hacbs-contract/ec-cli/acceptance/log"
"github.com/hacbs-contract/ec-cli/acceptance/testenv"
"github.com/hacbs-contract/ec-cli/acceptance/wiremock"
)

type key int
Expand Down Expand Up @@ -149,7 +149,7 @@ func createGitRepository(ctx context.Context, repositoryName string, files *godo
dest := path.Join(repositoryDir, file)
source := row.Cells[1].Value

b, err := os.ReadFile(source)
b, err := os.ReadFile(path.Join("acceptance", source))
if err != nil {
return err
}
Expand Down
Loading

0 comments on commit 8b42166

Please sign in to comment.