Skip to content

Commit

Permalink
osbuild: expected error messages for ostree.deploy.container test
Browse files Browse the repository at this point in the history
  • Loading branch information
achilleas-k committed Nov 28, 2023
1 parent 8f44d2e commit a39314a
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions pkg/osbuild/ostree_deploy_container_stage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@ func TestOSTreeDeployContainersStageOptionsValidate(t *testing.T) {
type testCase struct {
options OSTreeDeployContainerStageOptions
valid bool
err string
}

testCases := map[string]testCase{
"empty": {
options: OSTreeDeployContainerStageOptions{},
valid: false,
err: "osname is required",
},
"minimal": {
options: OSTreeDeployContainerStageOptions{
Expand All @@ -40,19 +42,22 @@ func TestOSTreeDeployContainersStageOptionsValidate(t *testing.T) {
OsName: "os",
},
valid: false,
err: "doesn't conform to schema",
},
"no-os": {
options: OSTreeDeployContainerStageOptions{
TargetImgref: "ostree-image-unverified-registry:example.org/registry/image",
},
valid: false,
err: "osname is required",
},
"bad-target": {
options: OSTreeDeployContainerStageOptions{
OsName: "os",
TargetImgref: "bad",
},
valid: false,
err: "doesn't conform to schema",
},
"full": {
options: OSTreeDeployContainerStageOptions{
Expand All @@ -78,7 +83,7 @@ func TestOSTreeDeployContainersStageOptionsValidate(t *testing.T) {
assert.NoError(tc.options.validate())
assert.NotPanics(func() { NewOSTreeDeployContainerStage(&tc.options, validInputs) })
} else {
assert.Error(tc.options.validate())
assert.ErrorContains(tc.options.validate(), tc.err)
assert.Panics(func() { NewOSTreeDeployContainerStage(&tc.options, validInputs) })
}
})
Expand All @@ -95,12 +100,14 @@ func TestOSTreeDeployContainersStageInputsValidate(t *testing.T) {
type testCase struct {
inputs OSTreeDeployContainerInputs
valid bool
err string
}

testCases := map[string]testCase{
"empty": {
inputs: OSTreeDeployContainerInputs{},
valid: false,
err: "stage requires exactly 1 input container (got nil References)",
},
"nil": {
inputs: OSTreeDeployContainerInputs{
Expand All @@ -109,12 +116,14 @@ func TestOSTreeDeployContainersStageInputsValidate(t *testing.T) {
},
},
valid: false,
err: "stage requires exactly 1 input container (got nil References)",
},
"zero": {
inputs: OSTreeDeployContainerInputs{
Images: NewContainersInputForSources([]container.Spec{}),
},
valid: false,
err: "stage requires exactly 1 input container (got 0)",
},
"one": {
inputs: OSTreeDeployContainerInputs{
Expand All @@ -141,6 +150,7 @@ func TestOSTreeDeployContainersStageInputsValidate(t *testing.T) {
}),
},
valid: false,
err: "stage requires exactly 1 input container (got 2)",
},
}
for name := range testCases {
Expand All @@ -151,7 +161,7 @@ func TestOSTreeDeployContainersStageInputsValidate(t *testing.T) {
assert.NoError(tc.inputs.validate())
assert.NotPanics(func() { NewOSTreeDeployContainerStage(validOptions, tc.inputs.Images) })
} else {
assert.Error(tc.inputs.validate())
assert.ErrorContains(tc.inputs.validate(), tc.err)
assert.Panics(func() { NewOSTreeDeployContainerStage(validOptions, tc.inputs.Images) })
}
})
Expand Down

0 comments on commit a39314a

Please sign in to comment.