tests: verify system-wide sources can't be deleted. Closes #315

make sure this test can be run both as a unit test and as an
integration test on a running system
This commit is contained in:
Alexander Todorov 2020-04-06 09:58:52 -04:00 committed by Tom Gundersen
parent a1eb6b4cd5
commit bd4793eb58
2 changed files with 45 additions and 6 deletions

View file

@ -206,7 +206,7 @@ func TestGetSourceInfoV0(t *testing.T) {
func UploadUserDefinedSources(t *testing.T, sources []string) {
for i := range sources {
source := strings.Replace(sources[i], "REPO-PATH", testState.repoDir, 1)
resp, err := client.PostJSONSourceV0(testState.socket, source)
resp, err := PostJSONSourceV0(testState.socket, source)
require.NoError(t, err, "POST source failed with a client error")
require.True(t, resp.Status, "POST source failed: %#v", resp)
}
@ -214,11 +214,11 @@ func UploadUserDefinedSources(t *testing.T, sources []string) {
// verify user defined sources are not present
func VerifyNoUserDefinedSources(t *testing.T, source_names []string) {
list, api, err := client.ListSourcesV0(testState.socket)
list, api, err := ListSourcesV0(testState.socket)
require.NoError(t, err, "GET source failed with a client error")
require.Nil(t, api, "ListSources failed: %#v", api)
require.GreaterOrEqual(t, len(list), 1, "Not enough sources returned")
for i := range(source_names) {
for i := range source_names {
require.NotContains(t, list, source_names[i])
}
}
@ -253,8 +253,8 @@ func TestDeleteUserDefinedSourcesV0(t *testing.T) {
// operation of PostJSONSourceV0 is validated in the test functions above
// Remove the test sources
for _, n := range(source_names) {
resp, err := client.DeleteSourceV0(testState.socket, n)
for _, n := range source_names {
resp, err := DeleteSourceV0(testState.socket, n)
require.NoError(t, err, "DELETE source failed with a client error")
require.True(t, resp.Status, "DELETE source failed: %#v", resp)
}
@ -262,3 +262,42 @@ func TestDeleteUserDefinedSourcesV0(t *testing.T) {
// verify removed sources are not present after removal
VerifyNoUserDefinedSources(t, source_names)
}
func Index(vs []string, t string) int {
for i, v := range vs {
if v == t {
return i
}
}
return -1
}
func Include(vs []string, t string) bool {
return Index(vs, t) >= 0
}
func TestDeleteSystemSourcesV0(t *testing.T) {
sources_list, api, err := ListSourcesV0(testState.socket)
require.NoError(t, err, "GET source failed with a client error")
require.Nil(t, api, "ListSources failed: %#v", api)
for _, repo_name := range []string{"test-system-repo", "fedora", "baseos"} {
// skip repository names which are not present b/c this test can be
// executed both as a unit test and as an integration test
if !Include(sources_list, repo_name) {
continue
}
// try removing system source
resp, err := DeleteSourceV0(testState.socket, repo_name)
require.NoError(t, err, "DELETE source failed with a client error")
require.True(t, resp.Status, "DELETE source failed: %#v", resp)
// verify that system sources are still there
list, api, err := ListSourcesV0(testState.socket)
require.NoError(t, err, "GET source failed with a client error")
require.Nil(t, api, "ListSources failed: %#v", api)
require.GreaterOrEqual(t, len(list), 1, "Not enough sources returned")
require.Contains(t, list, repo_name)
}
}

View file

@ -45,7 +45,7 @@ func TestMain(m *testing.M) {
if err != nil {
panic(err)
}
repos := []rpmmd.RepoConfig{{Id: "test-id", BaseURL: "http://example.com/test/os/test_arch"}}
repos := []rpmmd.RepoConfig{{Id: "test-system-repo", BaseURL: "http://example.com/test/os/test_arch"}}
logger := log.New(os.Stdout, "", 0)
api := weldr.New(rpm, arch, distro, repos, logger, fixture.Store)
server := http.Server{Handler: api}