Skip to content

Commit

Permalink
test/e2e: added test for destructive error
Browse files Browse the repository at this point in the history
  • Loading branch information
giautm committed Oct 24, 2024
1 parent 9724ba4 commit 26bbc9e
Showing 1 changed file with 134 additions and 0 deletions.
134 changes: 134 additions & 0 deletions test/e2e/testscript/schema-lint-destructive.txtar
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
env DB_URL=mysql://root:pass@mysql.${NAMESPACE}:3306/myapp
kubectl apply -f database.yaml
kubectl create secret generic db-creds --from-literal=url=${DB_URL}
# Wait for the DB ready before creating the schema
kubectl-wait-ready -l app=mysql pods

# Create the schema
kubectl apply -f schema.yaml
kubectl-wait-ready AtlasSchema/mysql

# Inspect the schema to ensure it's correct
atlas schema inspect -u ${DB_URL}
cmp stdout schema.hcl

kubectl patch -f schema.yaml --type merge --patch-file patch-remove-bio.yaml

# Wait for the controller to detect the change
exec sleep 10

# Ensure the controller is aware of the change
kubectl wait --for=jsonpath='{.status.conditions[*].reason}'=LintPolicyError --timeout=120s AtlasSchemas/mysql
# Check the error message
kubectl get AtlasSchema/mysql -o jsonpath --template='{.status.conditions[*].message}'
stdout 'destructive changes detected:'
stdout '- Dropping non-virtual column "short_bio"'
-- schema.hcl --
table "users" {
schema = schema.myapp
column "id" {
null = false
type = int
auto_increment = true
}
column "name" {
null = false
type = varchar(255)
}
column "email" {
null = false
type = varchar(255)
}
column "short_bio" {
null = false
type = varchar(255)
}
primary_key {
columns = [column.id]
}
index "email" {
unique = true
columns = [column.email]
}
}
schema "myapp" {
charset = "utf8mb4"
collate = "utf8mb4_0900_ai_ci"
}
-- patch-remove-bio.yaml --
spec:
schema:
sql: |
create table users (
id int not null auto_increment,
name varchar(255) not null,
email varchar(255) unique not null,
primary key (id)
);
-- schema.yaml --
apiVersion: db.atlasgo.io/v1alpha1
kind: AtlasSchema
metadata:
name: mysql
spec:
urlFrom:
secretKeyRef:
name: db-creds
key: url
policy:
lint:
destructive:
error: true
schema:
sql: |
create table users (
id int not null auto_increment,
name varchar(255) not null,
email varchar(255) unique not null,
short_bio varchar(255) not null,
primary key (id)
);
-- database.yaml --
apiVersion: v1
kind: Service
metadata:
name: mysql
spec:
selector:
app: mysql
ports:
- name: mysql
port: 3306
targetPort: mysql
type: ClusterIP
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: mysql
spec:
selector:
matchLabels:
app: mysql
replicas: 1
template:
metadata:
labels:
app: mysql
spec:
containers:
- name: mysql
image: mysql:latest
env:
- name: MYSQL_ROOT_PASSWORD
value: pass
- name: MYSQL_DATABASE
value: myapp
ports:
- containerPort: 3306
name: mysql
startupProbe:
exec:
command: [ "mysql", "-ppass", "-h", "127.0.0.1", "-e", "SELECT 1" ]
failureThreshold: 30
periodSeconds: 10

0 comments on commit 26bbc9e

Please sign in to comment.