Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Added wait for tests on an update #193

Merged
merged 1 commit into from
Oct 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
185 changes: 185 additions & 0 deletions kubernetes/resource_kubectl_manifest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,7 @@ EOF
})
log.Println(config)
}

func TestAccKubectl_WaitForField(t *testing.T) {
//language=hcl
config := `
Expand Down Expand Up @@ -683,6 +684,190 @@ YAML
})
}

func TestAccKubectl_WaitForConditionUpdate(t *testing.T) {
//language=hcl
createConfig := `
resource "kubectl_manifest" "test" {
wait_for_rollout = true
yaml_body = <<YAML
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
labels:
app: nginx
spec:
replicas: 1
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.27.0
ports:
- containerPort: 80
readinessProbe:
httpGet:
path: "/"
port: 80
initialDelaySeconds: 10
YAML
}
`

updateConfig := `
resource "kubectl_manifest" "test" {
wait_for_rollout = false
wait_for {
condition {
type = "Available"
status = "True"
}
}
yaml_body = <<YAML
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
labels:
app: nginx
spec:
replicas: 1
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.27.2
ports:
- containerPort: 80
readinessProbe:
httpGet:
path: "/"
port: 80
initialDelaySeconds: 10
YAML
}
`

//start := time.Now()
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckkubectlDestroy,
Steps: []resource.TestStep{
{
Config: createConfig,
},
{
Config: updateConfig,
},
},
})
}

func TestAccKubectl_WaitForFieldUpdate(t *testing.T) {
//language=hcl
createConfig := `
resource "kubectl_manifest" "test" {
wait_for_rollout = true
yaml_body = <<YAML
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
labels:
app: nginx
spec:
replicas: 1
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.27.0
ports:
- containerPort: 80
readinessProbe:
httpGet:
path: "/"
port: 80
initialDelaySeconds: 10
YAML
}
`

updateConfig := `
resource "kubectl_manifest" "test" {
wait_for_rollout = false
wait_for {
field {
key = "status.observedGeneration"
value = "2"
}
}
yaml_body = <<YAML
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
labels:
app: nginx
spec:
replicas: 1
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.27.2
ports:
- containerPort: 80
readinessProbe:
httpGet:
path: "/"
port: 80
initialDelaySeconds: 10
YAML
}
`

//start := time.Now()
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckkubectlDestroy,
Steps: []resource.TestStep{
{
Config: createConfig,
},
{
Config: updateConfig,
},
},
})
}

//func TestAccKubect_Debug(t *testing.T) {
// //language=hcl
// config := `
Expand Down
Loading