mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-15 01:53:51 -06:00
This commit is contained in:
parent
74cf9ac5e1
commit
b31ff955b6
@ -3,6 +3,7 @@ package ignition
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"regexp"
|
||||
"testing"
|
||||
|
||||
"github.com/coreos/ignition/config/types"
|
||||
@ -67,6 +68,18 @@ func TestIngnitionFileAppend(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func testIgnitionError(t *testing.T, input string, expectedErr *regexp.Regexp) {
|
||||
resource.Test(t, resource.TestCase{
|
||||
Providers: testProviders,
|
||||
Steps: []resource.TestStep{
|
||||
{
|
||||
Config: fmt.Sprintf(testTemplate, input),
|
||||
ExpectError: expectedErr,
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func testIgnition(t *testing.T, input string, assert func(*types.Config) error) {
|
||||
check := func(s *terraform.State) error {
|
||||
got := s.RootModule().Outputs["rendered"].Value.(string)
|
||||
|
@ -34,6 +34,11 @@ func resourceFilesystem() *schema.Resource {
|
||||
Required: true,
|
||||
ForceNew: true,
|
||||
},
|
||||
"create": &schema.Schema{
|
||||
Type: schema.TypeBool,
|
||||
Optional: true,
|
||||
ForceNew: true,
|
||||
},
|
||||
"force": &schema.Schema{
|
||||
Type: schema.TypeBool,
|
||||
Optional: true,
|
||||
@ -84,14 +89,19 @@ func buildFilesystem(d *schema.ResourceData, c *cache) (string, error) {
|
||||
Format: types.FilesystemFormat(d.Get("mount.0.format").(string)),
|
||||
}
|
||||
|
||||
create, hasCreate := d.GetOk("mount.0.create")
|
||||
force, hasForce := d.GetOk("mount.0.force")
|
||||
options, hasOptions := d.GetOk("mount.0.options")
|
||||
if hasOptions || hasForce {
|
||||
if hasCreate || hasOptions || hasForce {
|
||||
mount.Create = &types.FilesystemCreate{
|
||||
Force: force.(bool),
|
||||
Options: castSliceInterface(options.([]interface{})),
|
||||
}
|
||||
}
|
||||
|
||||
if !create.(bool) && (hasForce || hasOptions) {
|
||||
return "", fmt.Errorf("create should be true when force or options is used")
|
||||
}
|
||||
}
|
||||
|
||||
var path *types.Path
|
||||
|
@ -2,6 +2,7 @@ package ignition
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"regexp"
|
||||
"testing"
|
||||
|
||||
"github.com/coreos/ignition/config/types"
|
||||
@ -22,11 +23,21 @@ func TestIngnitionFilesystem(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
data "ignition_filesystem" "baz" {
|
||||
name = "baz"
|
||||
mount {
|
||||
device = "/baz"
|
||||
format = "ext4"
|
||||
create = true
|
||||
}
|
||||
}
|
||||
|
||||
data "ignition_filesystem" "bar" {
|
||||
name = "bar"
|
||||
mount {
|
||||
device = "/bar"
|
||||
format = "ext4"
|
||||
create = true
|
||||
force = true
|
||||
options = ["rw"]
|
||||
}
|
||||
@ -36,11 +47,12 @@ func TestIngnitionFilesystem(t *testing.T) {
|
||||
filesystems = [
|
||||
"${data.ignition_filesystem.foo.id}",
|
||||
"${data.ignition_filesystem.qux.id}",
|
||||
"${data.ignition_filesystem.baz.id}",
|
||||
"${data.ignition_filesystem.bar.id}",
|
||||
]
|
||||
}
|
||||
`, func(c *types.Config) error {
|
||||
if len(c.Storage.Filesystems) != 3 {
|
||||
if len(c.Storage.Filesystems) != 4 {
|
||||
return fmt.Errorf("disks, found %d", len(c.Storage.Filesystems))
|
||||
}
|
||||
|
||||
@ -75,6 +87,23 @@ func TestIngnitionFilesystem(t *testing.T) {
|
||||
}
|
||||
|
||||
f = c.Storage.Filesystems[2]
|
||||
if f.Name != "baz" {
|
||||
return fmt.Errorf("name, found %q", f.Name)
|
||||
}
|
||||
|
||||
if f.Mount.Device != "/baz" {
|
||||
return fmt.Errorf("mount.0.device, found %q", f.Mount.Device)
|
||||
}
|
||||
|
||||
if f.Mount.Format != "ext4" {
|
||||
return fmt.Errorf("mount.0.format, found %q", f.Mount.Format)
|
||||
}
|
||||
|
||||
if f.Mount.Create.Force != false {
|
||||
return fmt.Errorf("mount.0.force, found %t", f.Mount.Create.Force)
|
||||
}
|
||||
|
||||
f = c.Storage.Filesystems[3]
|
||||
if f.Name != "bar" {
|
||||
return fmt.Errorf("name, found %q", f.Name)
|
||||
}
|
||||
@ -98,3 +127,22 @@ func TestIngnitionFilesystem(t *testing.T) {
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
func TestIngnitionFilesystemMissingCreate(t *testing.T) {
|
||||
testIgnitionError(t, `
|
||||
data "ignition_filesystem" "bar" {
|
||||
name = "bar"
|
||||
mount {
|
||||
device = "/bar"
|
||||
format = "ext4"
|
||||
force = true
|
||||
}
|
||||
}
|
||||
|
||||
data "ignition_config" "test" {
|
||||
filesystems = [
|
||||
"${data.ignition_filesystem.bar.id}",
|
||||
]
|
||||
}
|
||||
`, regexp.MustCompile("create should be true when force or options is used"))
|
||||
}
|
||||
|
@ -18,7 +18,7 @@ data "ignition_filesystem" "foo" {
|
||||
mount {
|
||||
device = "/dev/disk/by-label/ROOT"
|
||||
format = "xfs"
|
||||
force = true
|
||||
create = true
|
||||
options = ["-L", "ROOT"]
|
||||
}
|
||||
}
|
||||
@ -36,14 +36,16 @@ The following arguments are supported:
|
||||
|
||||
|
||||
The `mount` block supports:
|
||||
|
||||
|
||||
* `device` - (Required) The absolute path to the device. Devices are typically referenced by the _/dev/disk/by-*_ symlinks.
|
||||
|
||||
* `format` - (Required) The filesystem format (ext4, btrfs, or xfs).
|
||||
|
||||
* `force` - (Optional) Whether or not the create operation shall overwrite an existing filesystem.
|
||||
* `create` - (Optional) Indicates if the filesystem shall be created.
|
||||
|
||||
* `options` - (Optional) Any additional options to be passed to the format-specific mkfs utility.
|
||||
* `force` - (Optional) Whether or not the create operation shall overwrite an existing filesystem. Only allowed if the filesystem is being created.
|
||||
|
||||
* `options` - (Optional) Any additional options to be passed to the format-specific mkfs utility. Only allowed if the filesystem is being created
|
||||
|
||||
## Attributes Reference
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user