Skip to content

Commit 7354e87

Browse files
committed
tests
1 parent 782a75c commit 7354e87

File tree

3 files changed

+129
-0
lines changed

3 files changed

+129
-0
lines changed

test/e2e/e2e_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,19 @@ func TestOperator(t *testing.T) {
272272
))
273273
}
274274
},
275+
// controller-exec runs a command inside the controller pod (e.g. to inspect DATA_DIR).
276+
"controller-exec": func(ts *testscript.TestScript, neg bool, args []string) {
277+
if len(args) < 1 {
278+
ts.Fatalf("usage: controller-exec <command> [args...]")
279+
}
280+
execArgs := append([]string{"exec", "-n", nsController, ts.Getenv("CONTROLLER"), "--"}, args...)
281+
err := ts.Exec("kubectl", execArgs...)
282+
if !neg {
283+
ts.Check(err)
284+
} else if err == nil {
285+
ts.Fatalf("unexpected success")
286+
}
287+
},
275288
},
276289
})
277290
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Test that the operator runs atlas login (with --grant-only) per resource and stores
2+
# .atlas under DATA_DIR in a resource-specific directory (namespace/name).
3+
# Requires the controller to be deployed with DATA_DIR set (e.g. config/manager).
4+
db postgres:15.4 DB_URL
5+
db postgres:15.4 DEV_URL postgres-dev
6+
kubectl create secret generic db-creds --from-literal=url=${DB_URL}
7+
kubectl create secret generic atlas-token --from-literal=ATLAS_TOKEN=${ATLAS_TOKEN}
8+
9+
kubectl cp -n ${CONTROLLER_NS} ${WORK} ${CONTROLLER}:/tmp/${NAMESPACE}/
10+
atlas schema push atlas-operator --tag=registry-v1 --dev-url=${DEV_URL} --url=file:///tmp/${NAMESPACE}/schema-v1.hcl
11+
12+
kubectl apply -f schema.yaml
13+
kubectl-wait-ready AtlasSchema/postgres
14+
15+
# Verify per-resource HOME: the operator sets HOME to DATA_DIR/namespace/name and runs
16+
# atlas login --grant-only, so .atlas must exist under that path.
17+
controller-exec test -d /data/${NAMESPACE}/postgres/.atlas
18+
19+
# Show the directory contents for debugging
20+
controller-exec ls -la /data/${NAMESPACE}/postgres/
21+
-- schema-v1.hcl --
22+
table "users" {
23+
schema = schema.public
24+
column "id" {
25+
null = false
26+
type = integer
27+
}
28+
primary_key {
29+
columns = [column.id]
30+
}
31+
}
32+
schema "public" {}
33+
-- schema.yaml --
34+
apiVersion: db.atlasgo.io/v1alpha1
35+
kind: AtlasSchema
36+
metadata:
37+
name: postgres
38+
spec:
39+
urlFrom:
40+
secretKeyRef:
41+
name: db-creds
42+
key: url
43+
schema:
44+
url: atlas://atlas-operator?tag=registry-v1
45+
cloud:
46+
tokenFrom:
47+
secretKeyRef:
48+
name: atlas-token
49+
key: ATLAS_TOKEN
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# Test that each resource gets its own HOME under DATA_DIR (namespace/name).
2+
# Two AtlasSchemas in the same namespace must have separate .atlas directories.
3+
db postgres:15.4 DB_URL
4+
db postgres:15.4 DEV_URL postgres-dev
5+
kubectl create secret generic db-creds --from-literal=url=${DB_URL}
6+
kubectl create secret generic atlas-token --from-literal=ATLAS_TOKEN=${ATLAS_TOKEN}
7+
8+
kubectl cp -n ${CONTROLLER_NS} ${WORK} ${CONTROLLER}:/tmp/${NAMESPACE}/
9+
atlas schema push atlas-operator --tag=registry-a --dev-url=${DEV_URL} --url=file:///tmp/${NAMESPACE}/schema-a.hcl
10+
atlas schema push atlas-operator --tag=registry-b --dev-url=${DEV_URL} --url=file:///tmp/${NAMESPACE}/schema-b.hcl
11+
12+
kubectl apply -f schema-a.yaml
13+
kubectl apply -f schema-b.yaml
14+
kubectl-wait-ready AtlasSchema/postgres-a
15+
kubectl-wait-ready AtlasSchema/postgres-b
16+
17+
# Each resource must have its own directory and .atlas under DATA_DIR.
18+
controller-exec test -d /data/${NAMESPACE}/postgres-a/.atlas
19+
controller-exec test -d /data/${NAMESPACE}/postgres-b/.atlas
20+
-- schema-a.hcl --
21+
table "users_a" {
22+
schema = schema.public
23+
column "id" { null = false; type = integer }
24+
primary_key { columns = [column.id] }
25+
}
26+
schema "public" {}
27+
-- schema-b.hcl --
28+
table "users_b" {
29+
schema = schema.public
30+
column "id" { null = false; type = integer }
31+
primary_key { columns = [column.id] }
32+
}
33+
schema "public" {}
34+
-- schema-a.yaml --
35+
apiVersion: db.atlasgo.io/v1alpha1
36+
kind: AtlasSchema
37+
metadata:
38+
name: postgres-a
39+
spec:
40+
urlFrom:
41+
secretKeyRef:
42+
name: db-creds
43+
key: url
44+
schema:
45+
url: atlas://atlas-operator?tag=registry-a
46+
cloud:
47+
tokenFrom:
48+
secretKeyRef:
49+
name: atlas-token
50+
key: ATLAS_TOKEN
51+
-- schema-b.yaml --
52+
apiVersion: db.atlasgo.io/v1alpha1
53+
kind: AtlasSchema
54+
metadata:
55+
name: postgres-b
56+
spec:
57+
urlFrom:
58+
secretKeyRef:
59+
name: db-creds
60+
key: url
61+
schema:
62+
url: atlas://atlas-operator?tag=registry-b
63+
cloud:
64+
tokenFrom:
65+
secretKeyRef:
66+
name: atlas-token
67+
key: ATLAS_TOKEN

0 commit comments

Comments
 (0)