Skip to content

Commit 39b0080

Browse files
authored
ginkgo integration tests (#22)
ginkgo now used for testing cli instead of bash go version bump to 1.25 module names updated to reflect validatedpatterns org anisble cfg updated to ignore unparsed inventory warning isHubCluster removed since it is deprecated in clustergroup chart patternizer version bump to 1.0.0 uninstall added as a makefile target in common makefile
1 parent 3c79d5b commit 39b0080

38 files changed

Lines changed: 1130 additions & 1011 deletions

‎.github/workflows/lint-test.yaml‎

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,19 @@ on:
55
branches: ["main"]
66

77
env:
8-
GO_VERSION: '1.24'
8+
GO_VERSION: '1.25'
99

1010
jobs:
1111
lint:
1212
runs-on: ubuntu-latest
1313
steps:
1414
- name: Checkout code
15-
uses: actions/checkout@v5
15+
uses: actions/checkout@v6
1616
with:
1717
persist-credentials: false
1818

1919
- name: Set up Go
20-
uses: actions/setup-go@v5
20+
uses: actions/setup-go@v6
2121
with:
2222
go-version: ${{ env.GO_VERSION }}
2323
cache-dependency-path: src/go.sum
@@ -29,22 +29,19 @@ jobs:
2929
runs-on: ubuntu-latest
3030
steps:
3131
- name: Checkout code
32-
uses: actions/checkout@v4
32+
uses: actions/checkout@v6
3333

3434
- name: Set up Go
35-
uses: actions/setup-go@v5
35+
uses: actions/setup-go@v6
3636
with:
3737
go-version: ${{ env.GO_VERSION }}
3838
cache-dependency-path: src/go.sum
3939

40-
- name: Build binary
41-
run: make build
40+
- name: Install ginkgo
41+
run: make dev-setup
4242

43-
- name: Run unit tests
44-
run: make test-unit
43+
- name: Run tests
44+
run: make test
4545

4646
- name: Generate test coverage report
4747
run: make test-coverage
48-
49-
- name: Run integration tests
50-
run: make test-integration

‎Containerfile‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
ARG GO_VERSION=1.24
1+
ARG GO_VERSION=1.25.7
22
ARG GOARCH=amd64
33

44
# Build stage

‎Makefile‎

Lines changed: 9 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ GO_TEST := $(GO_CMD) test
1212
GO_CLEAN := $(GO_CMD) clean
1313
GO_VET := $(GO_CMD) vet
1414
GO_FMT := gofmt
15-
GO_VERSION := 1.24
16-
GOLANGCI_LINT_VERSION := v2.1.6
15+
GO_VERSION := 1.25.7
16+
GOLANGCI_LINT_VERSION := v2.10.1
17+
GINKGO_VERSION := v2.28.1
1718
SRC_DIR := src
1819

1920
# Default target
@@ -49,27 +50,16 @@ deps: ## Download and install Go dependencies
4950
.PHONY: test-unit
5051
test-unit: ## Run unit tests
5152
@echo "Running unit tests..."
52-
cd $(SRC_DIR) && $(GO_TEST) -v ./...
53+
ginkgo -v ./...
5354

5455
.PHONY: test-coverage
5556
test-coverage: ## Run unit tests with coverage report
5657
@echo "Running unit tests with coverage..."
5758
cd $(SRC_DIR) && $(GO_TEST) ./... -coverprofile=coverage.out
5859
cd $(SRC_DIR) && $(GO_CMD) tool cover -func=coverage.out
5960

60-
.PHONY: shellcheck
61-
shellcheck: ## Run shellcheck on integration test script
62-
@echo "Running shellcheck on integration test script..."
63-
@podman run --pull always -v "$(PWD):/mnt:z" docker.io/koalaman/shellcheck:stable test/integration_test.sh
64-
@echo "Shellcheck passed"
65-
66-
.PHONY: test-integration
67-
test-integration: build shellcheck ## Run integration tests
68-
@echo "Running integration tests..."
69-
PATTERNIZER_BINARY=./$(SRC_DIR)/$(NAME) ./test/integration_test.sh
70-
7161
.PHONY: test
72-
test: test-unit test-integration ## Run all tests (unit + integration)
62+
test: test-unit ## Run all tests (unit + integration)
7363

7464
.PHONY: lint
7565
lint: lint-fmt lint-vet lint-golangci ## Run all linting checks
@@ -116,19 +106,12 @@ dev-setup: deps ## Set up development environment
116106
echo "Installing golangci-lint..."; \
117107
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/HEAD/install.sh | sh -s -- -b $$(go env GOPATH)/bin $(GOLANGCI_LINT_VERSION); \
118108
fi
109+
@if ! command -v ginkgo >/dev/null 2>&1; then \
110+
echo "Installing ginkgo CLI..."; \
111+
go install github.com/onsi/ginkgo/v2/ginkgo@$(GINKGO_VERSION); \
112+
fi
119113
@echo "Development environment ready"
120114

121-
.PHONY: version
122-
version: ## Show version information
123-
@echo "Go version: $$(go version)"
124-
@echo "Git commit: $$(git rev-parse --short HEAD 2>/dev/null || echo 'unknown')"
125-
@echo "Build date: $$(date -u +%Y-%m-%dT%H:%M:%SZ)"
126-
127-
.PHONY: docs
128-
docs: ## Generate Go documentation
129-
@echo "Generating documentation..."
130-
cd $(SRC_DIR) && $(GO_CMD) doc -all ./...
131-
132115
.PHONY: check
133116
check: lint-fmt lint-vet build test-unit ## Quick check (format, vet, build, unit tests)
134117

‎README.md‎

Lines changed: 26 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
# Patternizer
22

3-
![Version: 0.2.1](https://img.shields.io/badge/Version-0.2.1-informational?style=flat-square)
3+
![Version: 1.0.0](https://img.shields.io/badge/Version-1.0.0-informational?style=flat-square)
44
[![Quay Repository](https://img.shields.io/badge/Quay.io-patternizer-blue?logo=quay)](https://quay.io/repository/validatedpatterns/patternizer)
55
[![CI Pipeline](https://github.com/validatedpatterns/patternizer/actions/workflows/build-push.yaml/badge.svg?branch=main)](https://github.com/validatedpatterns/patternizer/actions/workflows/build-push.yaml)
66

7-
**Patternizer** is a command-line tool that bootstraps a Git repository containing Helm charts into a ready-to-use Validated Pattern. It automatically generates the necessary scaffolding, configuration files, and utility scripts, so you can get your pattern up and running in minutes.
7+
**Patternizer** is a command-line tool that bootstraps a Git repository containing Helm charts into a ready-to-use Validated Pattern. It automatically generates the necessary scaffolding, configuration files, and utility scripts, so you can get your pattern up and running in minutes. It can also be used to upgrade existing patterns as described in [the Validated Pattern's blog](https://validatedpatterns.io/blog/2025-08-29-new-common-makefile-structure/).
88

9-
> **Note:** This tool was developed with assistance from [Cursor](https://cursor.sh), an AI-powered code editor.
9+
**Note:** This repo was developed with AI tools including [Cursor](https://cursor.com/), [Claude](https://claude.ai/login) and [Gemini](https://gemini.google.com/app).
1010

1111
- [Patternizer](#patternizer)
12-
- [Features](#features)
1312
- [Quick Start](#quick-start)
1413
- [Example Workflow](#example-workflow)
1514
- [Usage Details](#usage-details)
@@ -22,25 +21,10 @@
2221
- [Development \& Contributing](#development--contributing)
2322
- [Prerequisites](#prerequisites)
2423
- [Local Development Workflow](#local-development-workflow)
25-
- [Common Makefile Targets](#common-makefile-targets)
26-
- [Testing Strategy](#testing-strategy)
27-
- [Architecture](#architecture)
28-
- [CI/CD Pipeline](#cicd-pipeline)
2924
- [How to Contribute](#how-to-contribute)
3025

31-
## Features
32-
33-
- 🚀 **CLI-first design** with intuitive commands and help system
34-
- 📦 **Container-native** for consistent execution across all environments
35-
- 🔍 **Auto-discovery** of Helm charts and Git repository metadata
36-
- 🔐 **Optional secrets integration** with Vault and External Secrets
37-
- 🏗️ **Makefile-driven** utility scripts for easy pattern management
38-
- ♻️ **Upgrade command** to refresh existing pattern repositories to the latest common structure
39-
4026
## Quick Start
4127

42-
This guide assumes you have a Git repository containing one or more Helm charts.
43-
4428
**Prerequisites:**
4529

4630
- Podman or Docker
@@ -49,29 +33,28 @@ This guide assumes you have a Git repository containing one or more Helm charts.
4933
Navigate to your repository's root directory and run the initialization command:
5034

5135
```bash
52-
# In the root of your pattern-repo
53-
podman run -v "$PWD:$PWD:z" -w "$PWD" quay.io/validatedpatterns/patternizer init
36+
podman run --pull=newer -v "$PWD:$PWD:z" -w "$PWD" quay.io/validatedpatterns/patternizer init
5437
```
5538

5639
This single command will generate all the necessary files to turn your repository into a Validated Pattern.
5740

5841
## Example Workflow
5942

60-
1. **Clone or create your pattern repository:**
43+
1. **Clone or create your pattern repository**
6144

6245
```bash
6346
git clone https://github.com/your-org/your-pattern.git
6447
cd your-pattern
6548
git checkout -b initialize-pattern
6649
```
6750

68-
2. **Initialize the pattern using Patternizer:**
51+
2. **Initialize the pattern using Patternizer**
6952

7053
```bash
71-
podman run -v "$PWD:$PWD:z" -w "$PWD" quay.io/validatedpatterns/patternizer init
54+
podman run --pull=newer -v "$PWD:$PWD:z" -w "$PWD" quay.io/validatedpatterns/patternizer init
7255
```
7356

74-
3. **Review, commit, and push the generated files:**
57+
3. **Review, commit, and push the generated files**
7558

7659
```bash
7760
git status
@@ -80,7 +63,13 @@ This single command will generate all the necessary files to turn your repositor
8063
git push -u origin initialize-pattern
8164
```
8265

83-
4. **Install the pattern:**
66+
4. **Login to an OpenShift cluster**
67+
68+
```bash
69+
export KUBECONFIG=/path/to/cluster/kubeconfig
70+
```
71+
72+
5. **Install the pattern**
8473

8574
```bash
8675
./pattern.sh make install
@@ -90,18 +79,18 @@ This single command will generate all the necessary files to turn your repositor
9079

9180
### Container Usage (Recommended)
9281

93-
Using the prebuilt container is the easiest way to run Patternizer, as it requires no local installation. The `-v "$PWD:$PWD:z" -w "$PWD"` flag mounts your current directory into the container's `/repo` workspace.
82+
Using the prebuilt container is the easiest way to run Patternizer, as it requires no local installation.
9483

9584
#### **Initialize without secrets:**
9685

9786
```bash
98-
podman run -v "$PWD:$PWD:z" -w "$PWD" quay.io/validatedpatterns/patternizer init
87+
podman run --pull=newer -v "$PWD:$PWD:z" -w "$PWD" quay.io/validatedpatterns/patternizer init
9988
```
10089

10190
#### **Initialize with secrets support:**
10291

10392
```bash
104-
podman run -v "$PWD:$PWD:z" -w "$PWD" quay.io/validatedpatterns/patternizer init --with-secrets
93+
podman run --pull=newer -v "$PWD:$PWD:z" -w "$PWD" quay.io/validatedpatterns/patternizer init --with-secrets
10594
```
10695

10796
#### **Upgrade an existing pattern repository:**
@@ -110,19 +99,18 @@ Use this to migrate or refresh an existing pattern repo to the latest common str
11099

111100
```bash
112101
# Refresh common assets, keep your Makefile unless it lacks the include
113-
podman run -v "$PWD:$PWD:z" -w "$PWD" quay.io/validatedpatterns/patternizer upgrade
102+
podman run --pull=newer -v "$PWD:$PWD:z" -w "$PWD" quay.io/validatedpatterns/patternizer upgrade
114103
115104
# Replace your Makefile with the default from Patternizer
116-
podman run -v "$PWD:$PWD:z" -w "$PWD" quay.io/validatedpatterns/patternizer upgrade --replace-makefile
105+
podman run --pull=newer -v "$PWD:$PWD:z" -w "$PWD" quay.io/validatedpatterns/patternizer upgrade --replace-makefile
117106
```
118107

119108
What upgrade does:
120109

121110
- Removes the `common/` directory if it exists
122-
- Removes `./pattern.sh` if it exists (symlink or file)
123-
- Copies `resources/Makefile-common` and `resources/pattern.sh` into the repo root
111+
- Updates `ansible.cfg`, `Makefile-common`, and `pattern.sh` to the latest versions from [the resources directory](./resources/)
124112
- Makefile handling:
125-
- If `--replace-makefile` is set: copies the default `Makefile` into the repo root (overwriting any existing one)
113+
- If `--replace-makefile` is set: replaces an existing Makefile, if present, to [`Makefile`](./resources/Makefile) from the resources directory
126114
- If not set:
127115
- If no `Makefile` exists: copies the default `Makefile`
128116
- If a `Makefile` exists and already contains `include Makefile-common` anywhere: leaves it unchanged
@@ -147,6 +135,7 @@ Running `patternizer init` creates the following:
147135
- `pattern.sh`: A utility script for common pattern operations (`install`, `upgrade`, etc.).
148136
- `Makefile`: A simple Makefile that includes `Makefile-common`.
149137
- `Makefile-common`: The core Makefile with all pattern-related targets.
138+
- `ansible.cfg`: Configuration for the ansible installation used when `./pattern.sh` is called
150139

151140
Using the `--with-secrets` flag additionally creates:
152141

@@ -159,7 +148,7 @@ This section is for developers who want to contribute to the Patternizer project
159148

160149
### Prerequisites
161150

162-
- Go (see `go.mod` for version)
151+
- Go (see [`go.mod`](./src/go.mod) for version)
163152
- Podman or Docker
164153
- Git
165154
- Make
@@ -168,10 +157,10 @@ This section is for developers who want to contribute to the Patternizer project
168157

169158
```bash
170159
# 1. Clone the repository
171-
git clone https://github.com/dminnear-rh/patternizer.git
160+
git clone https://github.com/validatedpatterns/patternizer.git
172161
cd patternizer
173162
174-
# 2. Set up the development environment (installs tools)
163+
# 2. Set up the development environment
175164
make dev-setup
176165
177166
# 3. Make your changes...
@@ -180,45 +169,6 @@ make dev-setup
180169
make ci
181170
```
182171

183-
### Common Makefile Targets
184-
185-
The `Makefile` is the single source of truth for all development and CI tasks.
186-
187-
- `make help`: Show all available targets.
188-
- `make check`: Quick feedback loop (format, vet, build, unit tests).
189-
- `make build`: Build the `patternizer` binary.
190-
- `make test`: Run all tests (unit and integration).
191-
- `make test-unit`: Run unit tests only.
192-
- `make test-integration`: Run integration tests only.
193-
- `make lint`: Run all code quality checks.
194-
- `make amd64`: Build the amd64 container image locally.
195-
- `make arm64`: Build the arm64 container image locally.
196-
197-
### Testing Strategy
198-
199-
Patternizer has a comprehensive test suite to ensure stability and correctness.
200-
201-
- **Unit Tests:** Located alongside the code they test (e.g., `src/internal/helm/helm_test.go`), these tests cover individual functions and packages in isolation. They validate Helm chart detection, Git URL parsing, and YAML processing logic.
202-
- **Integration Tests:** The integration test suite (`test/integration_test.sh`) validates the end-to-end CLI workflow against a real Git repository. Key scenarios include:
203-
1. **Basic Init:** Validates default file generation without secrets.
204-
2. **Init with Secrets:** Ensures secrets-related applications and files are correctly added.
205-
3. **Configuration Preservation:** Verifies that existing custom values are preserved when the tool is re-run.
206-
4. **Sequential Execution:** Tests running `init` and then `init --with-secrets` to ensure a clean upgrade.
207-
5. **Selective File Overwriting:** Confirms that running `init` on a repository with pre-existing custom files correctly **merges YAML configurations**, preserves user-modified files (like `Makefile` and `values-secret.yaml.template`), and only overwrites essential, generated scripts (`pattern.sh`, `Makefile-common`).
208-
6. **Mixed State Handling:** Validates that the tool correctly initializes a partially-configured repository, **creating files that are missing** while leaving existing ones untouched.
209-
7. **Upgrade (no replace):** Removes legacy `common/` and `pattern.sh` symlink, copies `Makefile-common`/`pattern.sh`, and injects `include Makefile-common` at the top of `Makefile` when missing.
210-
8. **Upgrade (include present):** Leaves the existing `Makefile` unchanged when it already contains `include Makefile-common` anywhere.
211-
9. **Upgrade with `--replace-makefile`:** Replaces `Makefile` with the default and refreshes common assets.
212-
10. **Upgrade (no Makefile present):** Creates the default `Makefile` and refreshes common assets when a `Makefile` does not exist.
213-
214-
### Architecture
215-
216-
The CLI is organized into focused packages following Go best practices, with a clean separation of concerns between command-line logic (`cmd`), core business logic (`internal`), and file operations (`fileutils`). This modular design makes the codebase maintainable, testable, and extensible.
217-
218-
### CI/CD Pipeline
219-
220-
The GitHub Actions pipeline (`.github/workflows/ci.yaml`) runs on every push and pull request. It uses the same `Makefile` targets that developers use locally, ensuring perfect consistency between local and CI environments.
221-
222172
### How to Contribute
223173

224174
1. Fork the repository.

‎resources/Makefile-common‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MAKEFLAGS += --no-print-directory
2-
ANSIBLE_STDOUT_CALLBACK ?= null # null silences all ansible output. Override this with default, minimal, oneline, etc. when debugging.
3-
ANSIBLE_RUN := ANSIBLE_STDOUT_CALLBACK=$(ANSIBLE_STDOUT_CALLBACK) ansible-playbook $(EXTRA_PLAYBOOK_OPTS)
2+
ANSIBLE_STDOUT_CALLBACK ?= rhvp.cluster_utils.readable
3+
ANSIBLE_RUN ?= ANSIBLE_STDOUT_CALLBACK=$(ANSIBLE_STDOUT_CALLBACK) ansible-playbook $(EXTRA_PLAYBOOK_OPTS)
44
DOCS_URL := https://validatedpatterns.io/blog/2025-08-29-new-common-makefile-structure/
55

66
.PHONY: help
@@ -20,9 +20,9 @@ operator-deploy operator-upgrade: ## Installs/updates the pattern on a cluster (
2020
.PHONY: install
2121
install: pattern-install ## Installs the pattern onto a cluster (Loads secrets as well if configured)
2222

23-
.PHONY: uninstall ## Prints a notice that patterns cannot currently be uninstalled
24-
uninstall:
25-
@echo "Uninstall is not possible at the moment so this target is empty. We are working to implement it as well as we can."
23+
.PHONY:
24+
uninstall: uninstall ## (EXPERIMENTAL) See https://validatedpatterns.io/blog/2026-02-16-pattern-uninstall/.
25+
@$(ANSIBLE_RUN) rhvp.cluster_utils.uninstall
2626

2727
.PHONY: pattern-install
2828
pattern-install:

‎resources/ansible.cfg‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,6 @@ filter_plugins=~/.ansible/plugins/filter:./ansible/plugins/filter:/usr/share/ans
1010
# use the collections from the util. container,
1111
# change below if you want to test local collections
1212
collections_path=/usr/share/ansible/collections
13+
14+
[inventory]
15+
inventory_unparsed_warning=False

0 commit comments

Comments
 (0)