diff --git a/.github/workflows/build-tests.yml b/.github/workflows/build-tests.yml new file mode 100644 index 0000000..a3eeb9b --- /dev/null +++ b/.github/workflows/build-tests.yml @@ -0,0 +1,22 @@ +name: build-tests + +on: + push: + branches: + - main + pull_request: + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 + with: + go-version-file: go.mod + check-latest: true + - run: make deps + - run: make build + - run: make lint + - run: make test + timeout-minutes: 30 \ No newline at end of file diff --git a/Makefile b/Makefile index 5fb9845..6c871dd 100644 --- a/Makefile +++ b/Makefile @@ -15,6 +15,10 @@ VERSION_LDFLAGS=\ COBRA_CLI_PACKAGE ?= github.com/spf13/cobra-cli@v1.3.0 GOLANGCI_LINT_PACKAGE ?= github.com/golangci/golangci-lint/cmd/golangci-lint@v1.55.2 +TEST_TAGS ?= +GOTESTFLAGS ?= + + ifeq ($(IS_WINDOWS),yes) GOFLAGS := -v -buildmode=exe EXECUTABLE ?= teachart.exe @@ -59,4 +63,9 @@ lint: .PHONY: lint-fix lint-fix: - $(GO) run $(GOLANGCI_LINT_PACKAGE) run --fix \ No newline at end of file + $(GO) run $(GOLANGCI_LINT_PACKAGE) run --fix + +.PHONY: test +test: + @echo "Running go test with -tags '$(TEST_TAGS)'" + @$(GO) test $(GOTESTFLAGS) -tags='$(TEST_TAGS)' ./... . \ No newline at end of file diff --git a/pkg/engine/engine_test.go b/pkg/engine/engine_test.go new file mode 100644 index 0000000..51b5acb --- /dev/null +++ b/pkg/engine/engine_test.go @@ -0,0 +1,25 @@ +package engine + +import ( + "testing" + + "github.com/stretchr/testify/assert" + "github.com/yp05327/teachart/pkg/app" + "helm.sh/helm/v3/pkg/cli/values" +) + +const testChartDir = "../../tests/chart" + +var testTeaChart = TeaChart{ + ProjectName: "test", + ProjectDir: "", + TempDir: app.DefaultTemplatesDir, +} + +func TestHelmRender(t *testing.T) { + e, err := NewRenderEngine(testChartDir, &testTeaChart) + assert.NoError(t, err) + + _, err = e.Render(values.Options{}, false) + assert.NoError(t, err) +} diff --git a/tests/chart/Chart.yaml b/tests/chart/Chart.yaml new file mode 100644 index 0000000..41d1162 --- /dev/null +++ b/tests/chart/Chart.yaml @@ -0,0 +1,4 @@ +name: gitea +description: test chart for teachart +version: 0.0.1 +appVersion: nightly diff --git a/tests/chart/templates/test_values.yaml b/tests/chart/templates/test_values.yaml new file mode 100644 index 0000000..5633a47 --- /dev/null +++ b/tests/chart/templates/test_values.yaml @@ -0,0 +1,10 @@ +# should have .Values.TeaChart +{{ .Values.TeaChart.ProjectName }} +{{ .Values.TeaChart.ProjectDir }} +{{ .Values.TeaChart.TempDir }} + +# helm chart metadata +{{ .Chart.Name }} +{{ .Chart.Description }} +{{ .Chart.Version }} +{{ .Chart.AppVersion }} diff --git a/tests/chart/values.yaml b/tests/chart/values.yaml new file mode 100644 index 0000000..e69de29 diff --git a/tests/values.yaml b/tests/values.yaml new file mode 100644 index 0000000..e69de29