|
| 1 | +variables { |
| 2 | + # Default IDE config, mirrored from main.tf for test assertions. |
| 3 | + # If main.tf defaults change, update this map to match. |
| 4 | + expected_ide_config = { |
| 5 | + "CL" = { name = "CLion", icon = "/icon/clion.svg", build = "251.26927.39" }, |
| 6 | + "GO" = { name = "GoLand", icon = "/icon/goland.svg", build = "251.26927.50" }, |
| 7 | + "IU" = { name = "IntelliJ IDEA", icon = "/icon/intellij.svg", build = "251.26927.53" }, |
| 8 | + "PS" = { name = "PhpStorm", icon = "/icon/phpstorm.svg", build = "251.26927.60" }, |
| 9 | + "PY" = { name = "PyCharm", icon = "/icon/pycharm.svg", build = "251.26927.74" }, |
| 10 | + "RD" = { name = "Rider", icon = "/icon/rider.svg", build = "251.26927.67" }, |
| 11 | + "RM" = { name = "RubyMine", icon = "/icon/rubymine.svg", build = "251.26927.47" }, |
| 12 | + "RR" = { name = "RustRover", icon = "/icon/rustrover.svg", build = "251.26927.79" }, |
| 13 | + "WS" = { name = "WebStorm", icon = "/icon/webstorm.svg", build = "251.26927.40" } |
| 14 | + } |
| 15 | +} |
| 16 | + |
| 17 | +run "validate_test_config_matches_defaults" { |
| 18 | + command = plan |
| 19 | + |
| 20 | + variables { |
| 21 | + # Provide minimal vars to allow plan to read module variables |
| 22 | + agent_id = "foo" |
| 23 | + folder = "/home/coder" |
| 24 | + } |
| 25 | + |
| 26 | + assert { |
| 27 | + condition = length(var.ide_config) == length(var.expected_ide_config) |
| 28 | + error_message = "Test configuration mismatch: 'var.ide_config' in main.tf has ${length(var.ide_config)} items, but 'var.expected_ide_config' in the test file has ${length(var.expected_ide_config)} items. Please update the test file's global variables block." |
| 29 | + } |
| 30 | + |
| 31 | + assert { |
| 32 | + # Check that all keys in the test local are present in the module's default |
| 33 | + condition = alltrue([ |
| 34 | + for key in keys(var.expected_ide_config) : |
| 35 | + can(var.ide_config[key]) |
| 36 | + ]) |
| 37 | + error_message = "Test configuration mismatch: Keys in 'var.expected_ide_config' are out of sync with 'var.ide_config' defaults. Please update the test file's global variables block." |
| 38 | + } |
| 39 | + |
| 40 | + assert { |
| 41 | + # Check if all build numbers in the test local match the module's defaults |
| 42 | + # This relies on the previous two assertions passing (same length, same keys) |
| 43 | + condition = alltrue([ |
| 44 | + for key, config in var.expected_ide_config : |
| 45 | + var.ide_config[key].build == config.build |
| 46 | + ]) |
| 47 | + error_message = "Test configuration mismatch: One or more build numbers in 'var.expected_ide_config' do not match the defaults in 'var.ide_config'. Please update the test file's global variables block." |
| 48 | + } |
| 49 | +} |
| 50 | + |
1 | 51 | run "requires_agent_and_folder" { |
2 | 52 | command = plan |
3 | 53 |
|
@@ -160,3 +210,87 @@ run "tooltip_null_when_not_provided" { |
160 | 210 | error_message = "Expected coder_app tooltip to be null when not provided" |
161 | 211 | } |
162 | 212 | } |
| 213 | + |
| 214 | +run "output_empty_when_default_empty" { |
| 215 | + command = plan |
| 216 | + |
| 217 | + variables { |
| 218 | + agent_id = "foo" |
| 219 | + folder = "/home/coder" |
| 220 | + # var.default is empty |
| 221 | + } |
| 222 | + |
| 223 | + assert { |
| 224 | + condition = length(output.ide_metadata) == 0 |
| 225 | + error_message = "Expected ide_metadata output to be empty when var.default is not set" |
| 226 | + } |
| 227 | +} |
| 228 | + |
| 229 | +run "output_single_ide_uses_fallback_build" { |
| 230 | + command = plan |
| 231 | + |
| 232 | + variables { |
| 233 | + agent_id = "foo" |
| 234 | + folder = "/home/coder" |
| 235 | + default = ["GO"] |
| 236 | + # Force HTTP data source to fail to test fallback logic |
| 237 | + releases_base_link = "https://coder.com" |
| 238 | + } |
| 239 | + |
| 240 | + assert { |
| 241 | + condition = length(output.ide_metadata) == 1 |
| 242 | + error_message = "Expected ide_metadata output to have 1 item" |
| 243 | + } |
| 244 | + |
| 245 | + assert { |
| 246 | + condition = can(output.ide_metadata["GO"]) |
| 247 | + error_message = "Expected ide_metadata output to have key 'GO'" |
| 248 | + } |
| 249 | + |
| 250 | + assert { |
| 251 | + condition = output.ide_metadata["GO"].name == var.expected_ide_config["GO"].name |
| 252 | + error_message = "Expected ide_metadata['GO'].name to be '${var.expected_ide_config["GO"].name}'" |
| 253 | + } |
| 254 | + |
| 255 | + assert { |
| 256 | + condition = output.ide_metadata["GO"].build == var.expected_ide_config["GO"].build |
| 257 | + error_message = "Expected ide_metadata['GO'].build to use the fallback '${var.expected_ide_config["GO"].build}'" |
| 258 | + } |
| 259 | + |
| 260 | + assert { |
| 261 | + condition = output.ide_metadata["GO"].icon == var.expected_ide_config["GO"].icon |
| 262 | + error_message = "Expected ide_metadata['GO'].icon to be '${var.expected_ide_config["GO"].icon}'" |
| 263 | + } |
| 264 | +} |
| 265 | + |
| 266 | +run "output_multiple_ides" { |
| 267 | + command = plan |
| 268 | + |
| 269 | + variables { |
| 270 | + agent_id = "foo" |
| 271 | + folder = "/home/coder" |
| 272 | + default = ["IU", "PY"] |
| 273 | + # Force HTTP data source to fail to test fallback logic |
| 274 | + releases_base_link = "https://coder.com" |
| 275 | + } |
| 276 | + |
| 277 | + assert { |
| 278 | + condition = length(output.ide_metadata) == 2 |
| 279 | + error_message = "Expected ide_metadata output to have 2 items" |
| 280 | + } |
| 281 | + |
| 282 | + assert { |
| 283 | + condition = can(output.ide_metadata["IU"]) && can(output.ide_metadata["PY"]) |
| 284 | + error_message = "Expected ide_metadata output to have keys 'IU' and 'PY'" |
| 285 | + } |
| 286 | + |
| 287 | + assert { |
| 288 | + condition = output.ide_metadata["PY"].name == var.expected_ide_config["PY"].name |
| 289 | + error_message = "Expected ide_metadata['PY'].name to be '${var.expected_ide_config["PY"].name}'" |
| 290 | + } |
| 291 | + |
| 292 | + assert { |
| 293 | + condition = output.ide_metadata["PY"].build == var.expected_ide_config["PY"].build |
| 294 | + error_message = "Expected ide_metadata['PY'].build to be the fallback '${var.expected_ide_config["PY"].build}'" |
| 295 | + } |
| 296 | +} |
0 commit comments