Skip to content

Commit

Permalink
add: test
Browse files Browse the repository at this point in the history
  • Loading branch information
a5chin committed Nov 20, 2024
1 parent a8ef0bc commit 30d2ac2
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 5 deletions.
52 changes: 47 additions & 5 deletions modules/monitoring-tools/main.tftest.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,42 @@ run "valid_no_filter" {
}
}

run "invalid_label" {
module {
source = "./"
}

variables {
project_id = "project_id"

target = {
title = "Title"
metric = "xxx.googleapis.com/xxx/xxx"
resource_type = "xxx"
label = "resource.xxx"
name = "xxx"
filter = "AND xxx = xxx"
reducer = "REDUCE_NONE"
aligner = "ALIGN_DELTA"
alert = {
"warn" = {
channel = "#warn"
window = "300s"
value = 0.65
}
}
}

secrets = "auth_token: xoxb-xxx"
}

command = plan

expect_failures = [
var.target.label,
]
}

run "invalid_filter" {
module {
source = "./"
Expand Down Expand Up @@ -147,7 +183,7 @@ run "invalid_filter" {
]
}

run "invalid_label" {
run "invalid_channel" {
module {
source = "./"
}
Expand All @@ -159,16 +195,21 @@ run "invalid_label" {
title = "Title"
metric = "xxx.googleapis.com/xxx/xxx"
resource_type = "xxx"
label = "resource.xxx"
label = "resource.labels.xxx"
name = "xxx"
filter = "AND xxx = xxx"
reducer = "REDUCE_NONE"
aligner = "ALIGN_DELTA"
alert = {
"error" = {
channel = "#warn"
channel = "error"
window = "300s"
value = 0.65
value = 0.95
}
"warn" = {
channel = "warn"
window = "300s"
value = 0.8
}
}
}
Expand All @@ -179,6 +220,7 @@ run "invalid_label" {
command = plan

expect_failures = [
var.target.label,
var.target.alert["error"].channel,
var.target.alert["warn"].channel,
]
}
4 changes: 4 additions & 0 deletions modules/monitoring-tools/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ variable "target" {
condition = var.target.filter == "" ? true : startswith(var.target.filter, "AND ")
error_message = "`var.target.filter` must start with `AND `."
}
validation {
condition = alltrue([for alert in var.target.alert : startswith(alert.channel, "#")])
error_message = "`var.target.alert['*'].channel` must start with `#`."
}
}

variable "secrets" {
Expand Down

0 comments on commit 30d2ac2

Please sign in to comment.