Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expected error messages for ostree.deploy.container test #283

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading