api: add error message for package without name RHEL-16006
This commit is contained in:
parent
80f49a526c
commit
99e84abc66
2 changed files with 65 additions and 0 deletions
|
|
@ -101,6 +101,18 @@ func (b *Blueprint) Initialize() error {
|
|||
return fmt.Errorf("Error hashing passwords: %s", err.Error())
|
||||
}
|
||||
|
||||
for i, p := range b.Packages {
|
||||
if len(p.Name) == 0 {
|
||||
var errMsg string
|
||||
if len(p.Version) == 0 {
|
||||
errMsg = fmt.Sprintf("Entry #%d has neither version nor name.", i+1)
|
||||
} else {
|
||||
errMsg = fmt.Sprintf("Entry #%d has version '%v' but no name.", i+1, p.Version)
|
||||
}
|
||||
return fmt.Errorf("All package entries need to contain the name of the package. %s", errMsg)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1229,3 +1229,56 @@ func TestBlueprintChangeV1(t *testing.T) {
|
|||
require.NotNil(t, bp, "GET blueprint change failed: missing blueprint")
|
||||
assert.Equal(t, bp.Version, "0.0.1")
|
||||
}
|
||||
|
||||
func TestEmptyPackageNameBlueprintJsonV0(t *testing.T) {
|
||||
bp := `{
|
||||
"name": "test-emptypackage-blueprint-v0",
|
||||
"description": "TestEmptyPackageNameBlueprintV0",
|
||||
"version": "0.0.1",
|
||||
"packages": [{"name": "", "version": "1.32.1"}]
|
||||
}`
|
||||
|
||||
// Push a blueprint
|
||||
resp, err := PostJSONBlueprintV0(testState.socket, bp)
|
||||
require.NoError(t, err, "failed with a client error")
|
||||
require.False(t, resp.Status, "Negative status expected.")
|
||||
require.Equal(t, len(resp.Errors), 1, "There should be exactly one error")
|
||||
assert.True(t, strings.HasPrefix(resp.Errors[0].String(), "BlueprintsError"), "I expect a BlueprintsError")
|
||||
}
|
||||
|
||||
func TestEmptyPackageNameBlueprintV0(t *testing.T) {
|
||||
bp := `name = "EMPTY-PACKAGE-NAME"
|
||||
description = "empty package name"
|
||||
version = "0.0.1"
|
||||
modules = []
|
||||
groups = []
|
||||
distro = "test-distro"
|
||||
|
||||
[[packages]]
|
||||
version = "*"
|
||||
`
|
||||
|
||||
resp, err := PostTOMLBlueprintV0(testState.socket, bp)
|
||||
require.NoError(t, err, "failed with a client error")
|
||||
require.False(t, resp.Status, "Negative status expected.")
|
||||
require.Equal(t, len(resp.Errors), 1, "There should be exactly one error")
|
||||
assert.True(t, strings.HasPrefix(resp.Errors[0].String(), "BlueprintsError"), "I expect a BlueprintsError")
|
||||
}
|
||||
|
||||
func TestEmptyPackageNameAndVersionBlueprintV0(t *testing.T) {
|
||||
bp := `name = "EMPTY-PACKAGE-NAME"
|
||||
description = "empty package name"
|
||||
version = "0.0.1"
|
||||
modules = []
|
||||
groups = []
|
||||
distro = "test-distro"
|
||||
|
||||
[[packages]]
|
||||
`
|
||||
|
||||
resp, err := PostTOMLBlueprintV0(testState.socket, bp)
|
||||
require.NoError(t, err, "failed with a client error")
|
||||
require.False(t, resp.Status, "Negative status expected.")
|
||||
require.Equal(t, len(resp.Errors), 1, "There should be exactly one error")
|
||||
assert.True(t, strings.HasPrefix(resp.Errors[0].String(), "BlueprintsError"), "I expect a BlueprintsError")
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue