Skip to content

Commit

Permalink
cmd/otk-gen-partition-table: fix to be wrapped in a "tree" json
Browse files Browse the repository at this point in the history
This is similar to osbuild#827 but
this time for the `otk-gen-partition-table` which was forgoten
in this other PR :(
  • Loading branch information
mvo5 committed Sep 2, 2024
1 parent e734c0c commit 8e89114
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 27 deletions.
11 changes: 8 additions & 3 deletions cmd/otk-gen-partition-table/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ import (
"github.com/osbuild/images/pkg/osbuild"
)

// Tree is the wrapper aroudn the "real" input
type Tree struct {
Tree Input `json:"tree"`
}

// Input represents the user provided inputs that will be used
// to generate the partition table
type Input struct {
Expand Down Expand Up @@ -239,14 +244,14 @@ func run(r io.Reader, w io.Writer) error {
/* #nosec G404 */
rng := rand.New(rand.NewSource(rngSeed))

var genPartInput Input
if err := json.NewDecoder(r).Decode(&genPartInput); err != nil {
var genPartInputTree Tree
if err := json.NewDecoder(r).Decode(&genPartInputTree); err != nil {
return err
}
// XXX: validate inputs, right now an empty "type" is not an error
// but it should either be an error or we should set a default

output, err := genPartitionTable(&genPartInput, rng)
output, err := genPartitionTable(&genPartInputTree.Tree, rng)
if err != nil {
return fmt.Errorf("cannot generate partition table: %w", err)
}
Expand Down
50 changes: 26 additions & 24 deletions cmd/otk-gen-partition-table/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,31 +173,33 @@ func TestUnmarshalOutput(t *testing.T) {

var partInputsSimple = `
{
"properties": {
"create": {
"bios_boot_partition": true,
"esp_partition": true,
"esp_partition_size": "2 GiB"
},
"type": "gpt",
"default_size": "10 GiB"
},
"partitions": [
{
"name": "root",
"mountpoint": "/",
"label": "root",
"size": "7 GiB",
"type": "ext4"
"tree": {
"properties": {
"create": {
"bios_boot_partition": true,
"esp_partition": true,
"esp_partition_size": "2 GiB"
},
"type": "gpt",
"default_size": "10 GiB"
},
{
"name": "home",
"mountpoint": "/home",
"label": "home",
"size": "2 GiB",
"type": "ext4"
}
]
"partitions": [
{
"name": "root",
"mountpoint": "/",
"label": "root",
"size": "7 GiB",
"type": "ext4"
},
{
"name": "home",
"mountpoint": "/home",
"label": "home",
"size": "2 GiB",
"type": "ext4"
}
]
}
}`

// XXX: anything under "internal" we don't actually need to test
Expand Down

0 comments on commit 8e89114

Please sign in to comment.