Skip to content

Commit 758cdee

Browse files
Ca-moesclaude
andcommitted
test(e2e): tier-1 dry-run smoke, no cluster/creds (#14)
Drives the assembled pipeline through the CLI over testdata/gitops-repo (a raw Deployment whose namespace is omitted + a KRR JSON proposing a downsize): KRR -> adapter -> discover -> policy -> yamledit, printed as a real unified diff. Asserts exit 0, the diff shows the downsized cpu/mem and the removed CPU limit, and the on-disk fixture is byte-for-byte unchanged. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 24b5b29 commit 758cdee

3 files changed

Lines changed: 108 additions & 0 deletions

File tree

‎e2e/e2e_test.go‎

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
// Package e2e exercises the assembled rere pipeline end-to-end through the CLI,
2+
// using no mocks: KRR JSON -> adapter -> discover -> policy -> yamledit, with
3+
// the result printed as a dry-run diff. No cluster and no credentials.
4+
package e2e
5+
6+
import (
7+
"bytes"
8+
"os"
9+
"path/filepath"
10+
"strings"
11+
"testing"
12+
13+
"github.com/Ca-moes/rere/internal/cli"
14+
)
15+
16+
func TestDryRunDownsize(t *testing.T) {
17+
repo := filepath.Join("testdata", "gitops-repo")
18+
manifest := filepath.Join(repo, "deployment.yaml")
19+
20+
before, err := os.ReadFile(manifest)
21+
if err != nil {
22+
t.Fatal(err)
23+
}
24+
25+
root := cli.NewRootCommand("test", "none", "now")
26+
var out bytes.Buffer
27+
root.SetOut(&out)
28+
root.SetErr(&out)
29+
root.SetArgs([]string{
30+
"run", "--dry-run",
31+
"--repo", repo,
32+
"--input", filepath.Join(repo, "krr.json"),
33+
})
34+
35+
if err := root.Execute(); err != nil {
36+
t.Fatalf("rere run --dry-run failed: %v\noutput:\n%s", err, out.String())
37+
}
38+
39+
got := out.String()
40+
// The diff is real (produced by yamledit) and shows the downsize.
41+
if !strings.Contains(got, "@@") {
42+
t.Errorf("expected a unified diff, got:\n%s", got)
43+
}
44+
if !strings.Contains(got, "250m") {
45+
t.Errorf("diff missing downsized cpu (250m):\n%s", got)
46+
}
47+
if !strings.Contains(got, "deployment.yaml") {
48+
t.Errorf("diff missing file header:\n%s", got)
49+
}
50+
// The CPU limit should be removed (a deletion line carrying the old "2").
51+
if !strings.Contains(got, `- cpu: "2"`) {
52+
t.Errorf("expected cpu limit removal in diff:\n%s", got)
53+
}
54+
55+
after, err := os.ReadFile(manifest)
56+
if err != nil {
57+
t.Fatal(err)
58+
}
59+
if !bytes.Equal(before, after) {
60+
t.Error("dry-run modified the on-disk fixture")
61+
}
62+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: web
5+
# namespace intentionally omitted (kustomize sets it); rere still matches.
6+
spec:
7+
replicas: 2
8+
template:
9+
spec:
10+
containers:
11+
- name: app
12+
image: web:1.0 # pinned
13+
resources:
14+
requests:
15+
cpu: "1"
16+
memory: 1Gi
17+
limits:
18+
cpu: "2"
19+
memory: 1Gi

‎e2e/testdata/gitops-repo/krr.json‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"scans": [
3+
{
4+
"object": {
5+
"namespace": "default",
6+
"kind": "Deployment",
7+
"name": "web",
8+
"container": "app",
9+
"allocations": {
10+
"requests": {"cpu": 1.0, "memory": 1073741824},
11+
"limits": {"cpu": 2.0, "memory": 1073741824}
12+
}
13+
},
14+
"recommended": {
15+
"requests": {
16+
"cpu": {"value": 0.25, "severity": "WARNING"},
17+
"memory": {"value": 268435456, "severity": "WARNING"}
18+
},
19+
"limits": {
20+
"cpu": {"value": null, "severity": "OK"},
21+
"memory": {"value": 268435456, "severity": "OK"}
22+
}
23+
},
24+
"severity": "WARNING"
25+
}
26+
]
27+
}

0 commit comments

Comments
 (0)