blueprints_test: change to more readable table driven tests

This commit is contained in:
Florian Schüller 2024-02-20 17:00:08 +01:00 committed by Ondřej Budai
parent 42da3cb143
commit 7bfd3ea464

View file

@ -1231,59 +1231,46 @@ func TestBlueprintChangeV1(t *testing.T) {
}
func TestEmptyPackageNameBlueprintJsonV0(t *testing.T) {
bp := `{
for _, packageSnippet := range []string{
`"packages": [{"name": "", "version": "*"}]`,
`"packages": [{"name": ""}]`,
} {
bp := `{
"name": "test-emptypackage-blueprint-v0",
"description": "TestEmptyPackageNameBlueprintV0",
"version": "0.0.1",
"packages": [{"name": "", "version": "1.32.1"}]
}`
` + packageSnippet + `}`
expectedErrorPrefix := "BlueprintsError: All package entries need to contain the name of the package."
expectedErrorPrefix := "BlueprintsError: All package entries need to contain the name of the package."
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")
reasoning := "I expected an error message starting with\n" + expectedErrorPrefix +
"\nnot\n" + resp.Errors[0].String()
assert.True(t, strings.HasPrefix(resp.Errors[0].String(), expectedErrorPrefix), reasoning)
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")
reasoning := "I expected an error message starting with\n" + expectedErrorPrefix +
"\nnot\n" + resp.Errors[0].String()
assert.True(t, strings.HasPrefix(resp.Errors[0].String(), expectedErrorPrefix), reasoning)
}
}
func TestEmptyPackageNameBlueprintV0(t *testing.T) {
bp := `name = "EMPTY-PACKAGE-NAME"
func TestEmptyPackageNameBlueprintTOMLV0(t *testing.T) {
for _, packageSnippet := range []string{
"[[packages]]\nversion = \"*\"\n",
"[[packages]]\n",
} {
bp := `name = "EMPTY-PACKAGE-NAME"
description = "empty package name"
version = "0.0.1"
` + packageSnippet
[[packages]]
version = "*"
`
expectedErrorPrefix := "BlueprintsError: All package entries need to contain the name of the package."
expectedErrorPrefix := "BlueprintsError: All package entries need to contain the name of the package."
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")
reasoning := "I expected an error message starting with\n" + expectedErrorPrefix +
"\nnot\n" + resp.Errors[0].String()
assert.True(t, strings.HasPrefix(resp.Errors[0].String(), expectedErrorPrefix), reasoning)
}
func TestEmptyPackageNameAndVersionBlueprintV0(t *testing.T) {
bp := `name = "EMPTY-PACKAGE-NAME"
description = "empty package name"
version = "0.0.1"
[[packages]]
`
expectedErrorPrefix := "BlueprintsError: All package entries need to contain the name of the package."
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")
reasoning := "I expected an error message starting with\n" + expectedErrorPrefix +
"\nnot\n" + resp.Errors[0].String()
assert.True(t, strings.HasPrefix(resp.Errors[0].String(), expectedErrorPrefix), reasoning)
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")
reasoning := "I expected an error message starting with\n" + expectedErrorPrefix +
"\nnot\n" + resp.Errors[0].String()
assert.True(t, strings.HasPrefix(resp.Errors[0].String(), expectedErrorPrefix), reasoning)
}
}