diff --git a/.temporalci.yaml b/.temporalci.yaml index 346f86f..a23c80a 100644 --- a/.temporalci.yaml +++ b/.temporalci.yaml @@ -1,15 +1,32 @@ steps: + # Stage 1: Build (runs first) - name: build image: golang:1.23 - command: go build ./... + command: go build -v ./... timeout: 5m - - name: test + + # Stage 2: These run in parallel after build + - name: unit-test image: golang:1.23 - command: go test -v ./... + command: go test -v -count=1 ./... timeout: 5m depends_on: [build] + - name: vet image: golang:1.23 command: go vet ./... timeout: 2m depends_on: [build] + + - name: format-check + image: golang:1.23 + command: test -z "$(gofmt -l .)" + timeout: 1m + depends_on: [build] + + # Stage 3: Runs after unit tests pass + - name: race-test + image: golang:1.23 + command: go test -race -count=1 ./... + timeout: 5m + depends_on: [unit-test] diff --git a/README.md b/README.md index 1ed91c5..4d3cd08 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,36 @@ # TemporalCI-test -A simple Go project used to test [TemporalCI](https://github.com/AndreKurait/TemporalCI) CI pipeline integration. +A test repository for [TemporalCI](https://github.com/AndreKurait/TemporalCI) — a Kubernetes-native CI system built on Temporal. -## What this tests +## What Happens When You Push -- PR-triggered CI via TemporalCI's reusable workflow -- Go build, test, and vet -- JUnit XML test result generation -- Test summary reporting +Every push and PR triggers a **TemporalCI pipeline** that: + +1. **Clones** this repo into an isolated K8s pod +2. **Runs steps as a DAG** — independent steps execute in parallel +3. **Reports results** directly on the PR with timing, logs, and a link to the Temporal Web UI + +### Pipeline (``.temporalci.yaml``) + +``` +build ──┬── unit-test ── race-test + ├── vet + └── format-check +``` + +- `build` runs first +- `unit-test`, `vet`, and `format-check` run **in parallel** after build +- `race-test` runs after unit tests pass + +### Helm Chart Testing + +This repo also includes a Helm chart at `deploy/helm/`. TemporalCI can lease an **ephemeral EKS cluster** from a warm pool, install the chart, run `helm test`, and report results — all orchestrated as a durable Temporal workflow. + +## Functions + +| Function | Description | +|----------|-------------| +| `Greet(name)` | Returns a greeting | +| `Reverse(s)` | Reverses a string | +| `IsPalindrome(s)` | Checks if a string is a palindrome | +| `Anagram(a, b)` | Checks if two strings are anagrams | diff --git a/anagram.go b/anagram.go new file mode 100644 index 0000000..964bffb --- /dev/null +++ b/anagram.go @@ -0,0 +1,22 @@ +package main + +import "strings" + +// Anagram checks if two strings are anagrams of each other. +func Anagram(a, b string) bool { + a, b = strings.ToLower(a), strings.ToLower(b) + if len(a) != len(b) { + return false + } + counts := make(map[rune]int) + for _, c := range a { + counts[c]++ + } + for _, c := range b { + counts[c]-- + if counts[c] < 0 { + return false + } + } + return true +} diff --git a/anagram_test.go b/anagram_test.go new file mode 100644 index 0000000..867c153 --- /dev/null +++ b/anagram_test.go @@ -0,0 +1,22 @@ +package main + +import "testing" + +func TestAnagram(t *testing.T) { + tests := []struct { + a, b string + want bool + }{ + {"listen", "silent", true}, + {"hello", "world", false}, + {"Astronomer", "Moon starer", false}, + {"abc", "cba", true}, + {"", "", true}, + {"a", "ab", false}, + } + for _, tt := range tests { + if got := Anagram(tt.a, tt.b); got != tt.want { + t.Errorf("Anagram(%q, %q) = %v, want %v", tt.a, tt.b, got, tt.want) + } + } +}