Skip to content

Commit

Permalink
Merge pull request #2 from intelops/tests
Browse files Browse the repository at this point in the history
Update: Add tests, Makefile, golint-ci, and some restructuring
  • Loading branch information
devopstoday11 committed Oct 23, 2023
2 parents b248b73 + 2c1f051 commit c38ef30
Show file tree
Hide file tree
Showing 91 changed files with 1,152 additions and 476 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/golangci-lint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: golangci-lint
on:
push:
branches:
- "*"
- main
pull_request:

permissions:
contents: read
# Optional: allow read access to pull request. Use with `only-new-issues` option.
pull-requests: read

jobs:
golangci:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
go-version: '1.21'
cache: false
- name: Run tests
run: go test ./... -coverprofile=coverage.out -coverpkg=./... -covermode=atomic
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: v1.54
args: -v --config=.golangci.yml
3 changes: 3 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ jobs:
with:
go-version: 1.21 # Go version
cache: true
- name: Run tests
run: go test ./... -coverprofile=coverage.out -coverpkg=./... -covermode=atomic

- uses: sigstore/cosign-installer@v3.1.2 # installs cosign
- uses: anchore/sbom-action/download-syft@v0.14.3 # installs syft
- uses: goreleaser/goreleaser-action@v5 # run goreleaser
Expand Down
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/example
/bin
coverage.out
input.yaml
input.json
30 changes: 30 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
run:
timeout: 10m
concurrency: 4

concurrency: 4

linters:
disable-all: true
enable:
- errcheck
- gosimple
- govet
- ineffassign
- staticcheck
- unused
- misspell
- dupl
- stylecheck

linters-settings:
gofmt:
simplify: true
dupl:
threshold: 400

issues:
# Maximum issues count per one linter. Set to 0 to disable. Default is 50.
max-issues-per-linter: 0
# Maximum count of issues with the same text. Set to 0 to disable. Default is 3.
max-same-issues: 0
21 changes: 0 additions & 21 deletions Dockerfile-Nodejs

This file was deleted.

21 changes: 0 additions & 21 deletions Dockerfile-clang

This file was deleted.

22 changes: 0 additions & 22 deletions Dockerfile-golang

This file was deleted.

19 changes: 0 additions & 19 deletions Dockerfile-python

This file was deleted.

21 changes: 0 additions & 21 deletions Dockerfile-rust

This file was deleted.

43 changes: 43 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Variables
GOTEST=go test
PKGS=./...
TESTFLAGS=-v
GOOS ?= linux
GOARCH ?= amd64

default: help

help: ## Display this help.
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { split($$2, arr, "|"); printf " \033[36m%-20s\033[0m %s\n", $$1, arr[1]; for (i=2; i<=length(arr); i++) printf "%*s %s\n", targetWidth+22, " ", arr[i] } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)

test: ## Run full test suite
@echo "Running tests for all packages..."
@$(GOTEST) $(TESTFLAGS) $(PKGS)


testfunc: ## Runs test on a specific function specified in the arg.| Example usage `make testfunc validateInput`
@echo "Running specific test function..."
@$(GOTEST) $(TESTFLAGS) -run $(filter-out $@,$(MAKECMDGOALS)) $(PKGS)

.PHONY: test testfunc

coverage: ## Generate and view the test coverage
@go test -coverprofile=coverage.out $(PKGS)
@go tool cover -html=coverage.out

%:
@:
format: ## Format the source code
@echo "Formatting code..."
@gofmt -s -w .

vet: ## Vet the Go code for potential issues
@echo "Vetting code for potential issues..."
@go vet $(PKGS)

lint: ## Run a linter on the codebase using golangci-lint.
@docker run --rm -v $(shell pwd):/app -w /app golangci/golangci-lint:v1.54.2 golangci-lint run -v


build: ## builds the GenVal app for defined OS/Arch by passing GOOS=$(GOOS) GOARCH=$GOARCH args.| Example usage `make build GOOS=linux GOARCH=amd64`
@GOOS=$(GOOS) GOARCH=$(GOARCH) go build -ldflags="-X main.Version=$(shell git describe --tags --abbrev=0)" -o ./bin/genval
92 changes: 0 additions & 92 deletions cue/input.json

This file was deleted.

Binary file removed genval
Binary file not shown.
42 changes: 29 additions & 13 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,53 @@ module github.com/intelops/genval
go 1.21.1

require (
github.com/open-policy-agent/opa v0.56.0
github.com/open-policy-agent/opa v0.57.0
github.com/sirupsen/logrus v1.9.3
gopkg.in/yaml.v2 v2.4.0
github.com/stretchr/testify v1.8.4
gopkg.in/yaml.v3 v3.0.1
)

require (
github.com/OneOfOne/xxhash v1.2.8 // indirect
github.com/agnivade/levenshtein v1.1.1 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/go-ini/ini v1.67.0 // indirect
github.com/go-logr/logr v1.2.4 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/gobwas/glob v0.2.3 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/flatbuffers v23.5.26+incompatible // indirect
github.com/google/uuid v1.3.1 // indirect
github.com/gorilla/mux v1.8.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.18.0 // indirect
github.com/klauspost/compress v1.17.1 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/prometheus/client_golang v1.16.0 // indirect
github.com/prometheus/client_model v0.3.0 // indirect
github.com/prometheus/common v0.42.0 // indirect
github.com/prometheus/procfs v0.10.1 // indirect
github.com/rcrowley/go-metrics v0.0.0-20200313005456-10cdbea86bc0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_golang v1.17.0 // indirect
github.com/prometheus/client_model v0.5.0 // indirect
github.com/prometheus/common v0.44.0 // indirect
github.com/prometheus/procfs v0.12.0 // indirect
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect
github.com/tchap/go-patricia/v2 v2.3.1 // indirect
github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb // indirect
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
github.com/yashtewari/glob-intersection v0.2.0 // indirect
go.opentelemetry.io/otel v1.16.0 // indirect
go.opentelemetry.io/otel/metric v1.16.0 // indirect
go.opentelemetry.io/otel/sdk v1.16.0 // indirect
go.opentelemetry.io/otel/trace v1.16.0 // indirect
golang.org/x/sys v0.11.0 // indirect
google.golang.org/protobuf v1.30.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.45.0 // indirect
go.opentelemetry.io/otel v1.19.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.19.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.19.0 // indirect
go.opentelemetry.io/otel/metric v1.19.0 // indirect
go.opentelemetry.io/otel/sdk v1.19.0 // indirect
go.opentelemetry.io/otel/trace v1.19.0 // indirect
golang.org/x/net v0.17.0 // indirect
golang.org/x/sys v0.13.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20231016165738-49dd2c1f3d0b // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20231016165738-49dd2c1f3d0b // indirect
google.golang.org/grpc v1.59.0 // indirect
google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
sigs.k8s.io/yaml v1.3.0 // indirect
)
Loading

0 comments on commit c38ef30

Please sign in to comment.