-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidation.tftest.hcl
More file actions
112 lines (83 loc) · 2.4 KB
/
Copy pathvalidation.tftest.hcl
File metadata and controls
112 lines (83 loc) · 2.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# Negative tests: every input validation in variables.tf must reject bad
# input at plan time, not surface it as a libvirt apply error.
#
# The libvirt provider is mocked (mock_provider) so these run with
# `command = plan` and need no libvirtd. Each run sets one bad value and
# asserts the matching variable's validation fails via expect_failures.
mock_provider "libvirt" {}
# Baseline valid inputs; each run overrides exactly the field under test.
variables {
vm_name = "valid-host-01"
base_image = "/var/lib/libvirt/images/noble.img"
ssh_public_key = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIValidKeyMaterialBase64xxxxxxxxxxxxxxxxxxxx tester@host"
}
run "vm_name_rejects_uppercase" {
command = plan
variables {
vm_name = "Invalid-Host"
}
expect_failures = [var.vm_name]
}
run "vm_name_rejects_leading_hyphen" {
command = plan
variables {
vm_name = "-leading-hyphen"
}
expect_failures = [var.vm_name]
}
run "vm_name_rejects_trailing_hyphen" {
command = plan
variables {
vm_name = "trailing-hyphen-"
}
expect_failures = [var.vm_name]
}
run "vm_name_rejects_over_63_chars" {
command = plan
variables {
# 65 characters: past the 63-character RFC 1123 label limit.
vm_name = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
}
expect_failures = [var.vm_name]
}
run "ssh_public_key_rejects_empty" {
command = plan
variables {
ssh_public_key = ""
}
expect_failures = [var.ssh_public_key]
}
run "ssh_public_key_rejects_garbage" {
command = plan
variables {
ssh_public_key = "not-a-real-ssh-key"
}
expect_failures = [var.ssh_public_key]
}
run "memory_mib_rejects_below_floor" {
command = plan
variables {
# Documented floor is 512 MiB; 256 must be rejected.
memory_mib = 256
}
expect_failures = [var.memory_mib]
}
run "additional_disks_rejects_duplicate_names" {
command = plan
variables {
additional_disks = [
{ name = "data", size_gib = 10 },
{ name = "data", size_gib = 20 },
]
}
expect_failures = [var.additional_disks]
}
run "additional_disks_rejects_more_than_25" {
command = plan
variables {
# 26 disks: past the vdb-vdz device-letter range, which would otherwise
# derive an invalid device name (vd) instead of failing at plan.
additional_disks = [for i in range(26) : { name = "disk-${i}", size_gib = 1 }]
}
expect_failures = [var.additional_disks]
}