|
| 1 | +run "parses_variables" { |
| 2 | + variables { |
| 3 | + primary = "www.example.com" |
| 4 | + domains = [ |
| 5 | + "www.example.com", |
| 6 | + "foo.example.com", |
| 7 | + "bar.example.com", |
| 8 | + "example.com", |
| 9 | + "www.example.org", |
| 10 | + "example.net" |
| 11 | + ] |
| 12 | + } |
| 13 | + |
| 14 | + assert { |
| 15 | + condition = output.mapped_zones == { |
| 16 | + "example.com" = { |
| 17 | + a = ["example.com"] |
| 18 | + cname = [ |
| 19 | + "www.example.com", |
| 20 | + "foo.example.com", |
| 21 | + "bar.example.com", |
| 22 | + ] |
| 23 | + } |
| 24 | + "example.net" = { |
| 25 | + a = ["example.net"] |
| 26 | + cname = [] |
| 27 | + } |
| 28 | + "example.org" = { |
| 29 | + a = [], |
| 30 | + cname = ["www.example.org"] |
| 31 | + } |
| 32 | + } |
| 33 | + error_message = "Mapped zones output should split input domains by top-level domain, then by CNAME and A records" |
| 34 | + } |
| 35 | + |
| 36 | + assert { |
| 37 | + condition = output.zones == [ |
| 38 | + { |
| 39 | + record = "example.com" |
| 40 | + record_type = "a" |
| 41 | + zone = "example.com" |
| 42 | + }, |
| 43 | + { |
| 44 | + record = "www.example.com" |
| 45 | + record_type = "cname" |
| 46 | + zone = "example.com" |
| 47 | + }, |
| 48 | + { |
| 49 | + record = "foo.example.com" |
| 50 | + record_type = "cname" |
| 51 | + zone = "example.com" |
| 52 | + }, |
| 53 | + { |
| 54 | + record = "bar.example.com" |
| 55 | + record_type = "cname" |
| 56 | + zone = "example.com" |
| 57 | + }, |
| 58 | + { |
| 59 | + record = "example.net" |
| 60 | + record_type = "a" |
| 61 | + zone = "example.net" |
| 62 | + }, |
| 63 | + { |
| 64 | + record = "www.example.org" |
| 65 | + record_type = "cname" |
| 66 | + zone = "example.org" |
| 67 | + } |
| 68 | + ] |
| 69 | + error_message = "Zones output should be flat list of { zone, record_type, record } objects" |
| 70 | + } |
| 71 | + |
| 72 | + assert { |
| 73 | + condition = output.domains == var.domains |
| 74 | + error_message = "Domains output should pass domains input directly" |
| 75 | + } |
| 76 | + |
| 77 | + assert { |
| 78 | + condition = !contains(output.redirects, var.primary) |
| 79 | + error_message = "Redirects output should exclude primary input" |
| 80 | + } |
| 81 | +} |
| 82 | + |
| 83 | +run "empty_output_is_ok" { |
| 84 | + variables { |
| 85 | + primary = "www.example.com" |
| 86 | + domains = ["www.example.com"] |
| 87 | + } |
| 88 | + |
| 89 | + assert { |
| 90 | + condition = output.mapped_zones == { |
| 91 | + "example.com" = { |
| 92 | + cname = ["www.example.com"], |
| 93 | + a = [] |
| 94 | + } |
| 95 | + } |
| 96 | + error_message = "Mapped zones output should split input domains by top-level domain, then by CNAME and A records" |
| 97 | + } |
| 98 | + |
| 99 | + assert { |
| 100 | + condition = output.zones == [ |
| 101 | + { |
| 102 | + zone = "example.com", |
| 103 | + record_type = "cname", |
| 104 | + record = "www.example.com" |
| 105 | + } |
| 106 | + ] |
| 107 | + error_message = "Zones output should be flat list of { zone, record_type, record } objects" |
| 108 | + } |
| 109 | + |
| 110 | + assert { |
| 111 | + condition = length(output.redirects) == 0 |
| 112 | + error_message = "Redirects output should be empty if only one domain is provided" |
| 113 | + } |
| 114 | +} |
0 commit comments