osbuild: add bindings for org.osbuild.containers.storage.conf stage
Add support for the `containers.storage.conf` stage with helper constructors that should make it easy to use. Add a small test for it.
This commit is contained in:
parent
f3c166c3fd
commit
8a06b9ddf3
2 changed files with 89 additions and 0 deletions
58
internal/osbuild/containers_storage_conf_stage.go
Normal file
58
internal/osbuild/containers_storage_conf_stage.go
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
package osbuild
|
||||
|
||||
import "fmt"
|
||||
|
||||
type CSCStorageOptions struct {
|
||||
AdditionalImageStores []string `json:"additionalimagestores,omitempty"`
|
||||
}
|
||||
|
||||
// CSCStorage is short for ContainersStorageConfigStorage
|
||||
type CSCStorage struct {
|
||||
Options *CSCStorageOptions `json:"options,omitempty"`
|
||||
}
|
||||
|
||||
type ContainersStorageConfig struct {
|
||||
Storage CSCStorage `json:"storage,omitempty"`
|
||||
}
|
||||
|
||||
type ContainersStorageConfStageOptions struct {
|
||||
Filename string `json:"filename,omitempty"`
|
||||
Config ContainersStorageConfig `json:"config"`
|
||||
Comment []string `json:"comment,omitempty"`
|
||||
}
|
||||
|
||||
func (ContainersStorageConfStageOptions) isStageOptions() {}
|
||||
|
||||
func NewContainerStorageOptions(filename string, additionalImageStores ...string) *ContainersStorageConfStageOptions {
|
||||
options := ContainersStorageConfStageOptions{
|
||||
Filename: filename,
|
||||
}
|
||||
|
||||
if len(additionalImageStores) > 0 {
|
||||
options.Config.Storage.Options = &CSCStorageOptions{
|
||||
AdditionalImageStores: additionalImageStores,
|
||||
}
|
||||
}
|
||||
|
||||
return &options
|
||||
}
|
||||
|
||||
func (o *ContainersStorageConfStageOptions) validate() error {
|
||||
if o.Filename == "" {
|
||||
return fmt.Errorf("`Filename` must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func NewContainersStorageConfStage(options *ContainersStorageConfStageOptions) *Stage {
|
||||
|
||||
if err := options.validate(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return &Stage{
|
||||
Type: "org.osbuild.containers.storage.conf",
|
||||
Options: options,
|
||||
}
|
||||
}
|
||||
31
internal/osbuild/containers_storage_conf_stage_test.go
Normal file
31
internal/osbuild/containers_storage_conf_stage_test.go
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
package osbuild
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestContainersStorageConfStage(t *testing.T) {
|
||||
expectedStage := &Stage{
|
||||
Type: "org.osbuild.containers.storage.conf",
|
||||
Options: &ContainersStorageConfStageOptions{
|
||||
Filename: "/usr/share/containers/storage.conf",
|
||||
Config: ContainersStorageConfig{
|
||||
Storage: CSCStorage{
|
||||
Options: &CSCStorageOptions{
|
||||
AdditionalImageStores: []string{
|
||||
"/usr/share/containers/storage/",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
actualStage := NewContainersStorageConfStage(
|
||||
NewContainerStorageOptions("/usr/share/containers/storage.conf",
|
||||
"/usr/share/containers/storage/"),
|
||||
)
|
||||
assert.Equal(t, expectedStage, actualStage)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue