weldr: Add support for the v1 API to /projects/source/delete
This changes store.DeleteSource to DeleteSourceByName for v0 use and DeleteSourceByID for v1 usage. It includes a new client function DeleteSourceV1, adds a new test, and converts the tests for the previous Source V1 API commits to use DeleteSourceV1.
This commit is contained in:
parent
982d292a96
commit
37258803b4
4 changed files with 61 additions and 12 deletions
|
|
@ -115,3 +115,12 @@ func DeleteSourceV0(socket *http.Client, sourceName string) (*APIResponse, error
|
|||
}
|
||||
return NewAPIResponse(body)
|
||||
}
|
||||
|
||||
// DeleteSourceV1 deletes the named source and returns an APIResponse
|
||||
func DeleteSourceV1(socket *http.Client, sourceName string) (*APIResponse, error) {
|
||||
body, resp, err := DeleteRaw(socket, "/api/v1/projects/source/delete/"+sourceName)
|
||||
if resp != nil || err != nil {
|
||||
return resp, err
|
||||
}
|
||||
return NewAPIResponse(body)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -128,8 +128,7 @@ func TestPOSTTOMLSourceV1(t *testing.T) {
|
|||
require.NoError(t, err, "POST source failed with a client error")
|
||||
require.True(t, resp.Status, "POST source failed: %#v", resp)
|
||||
|
||||
// TODO update for DeleteJSONSourceV1
|
||||
resp, err = DeleteSourceV0(testState.socket, "package-repo-toml-v0")
|
||||
resp, err = DeleteSourceV1(testState.socket, "package-repo-toml-v1")
|
||||
require.NoError(t, err, "DELETE source failed with a client error")
|
||||
require.True(t, resp.Status, "DELETE source failed: %#v", resp)
|
||||
}
|
||||
|
|
@ -300,11 +299,10 @@ func TestListSourcesV1(t *testing.T) {
|
|||
require.True(t, resp.Status, "POST source failed: %#v", resp)
|
||||
}
|
||||
|
||||
// TODO update for DeleteJSONSourceV1
|
||||
// Remove the test sources, ignoring any errors
|
||||
defer func() {
|
||||
for _, n := range []string{"package-repo-1", "package-repo-2"} {
|
||||
resp, err := DeleteSourceV0(testState.socket, n)
|
||||
resp, err := DeleteSourceV1(testState.socket, n)
|
||||
require.NoError(t, err, "DELETE source failed with a client error")
|
||||
require.True(t, resp.Status, "DELETE source failed: %#v", resp)
|
||||
}
|
||||
|
|
@ -373,8 +371,7 @@ func TestGetSourceInfoV1(t *testing.T) {
|
|||
require.Equal(t, "repo for info test v1", info["package-repo-info-v1"].Name)
|
||||
require.Equal(t, "file://"+testState.repoDir, info["package-repo-info-v1"].URL)
|
||||
|
||||
// TODO update for DeleteJSONSourceV1
|
||||
resp, err = DeleteSourceV0(testState.socket, "package-repo-info-v1")
|
||||
resp, err = DeleteSourceV1(testState.socket, "package-repo-info-v1")
|
||||
require.NoError(t, err, "DELETE source failed with a client error")
|
||||
require.True(t, resp.Status, "DELETE source failed: %#v", resp)
|
||||
}
|
||||
|
|
@ -490,10 +487,9 @@ func TestDeleteUserDefinedSourcesV1(t *testing.T) {
|
|||
// note: not verifying user defined sources have been pushed b/c correct
|
||||
// operation of PostJSONSourceV0 is validated in the test functions above
|
||||
|
||||
// TODO update for DeleteJSONSourceV1
|
||||
// Remove the test sources
|
||||
for _, n := range source_names {
|
||||
resp, err := DeleteSourceV0(testState.socket, n)
|
||||
resp, err := DeleteSourceV1(testState.socket, n)
|
||||
require.NoError(t, err, "DELETE source failed with a client error")
|
||||
require.True(t, resp.Status, "DELETE source failed: %#v", resp)
|
||||
}
|
||||
|
|
@ -540,3 +536,29 @@ func TestDeleteSystemSourcesV0(t *testing.T) {
|
|||
require.Contains(t, list, repo_name)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDeleteSystemSourcesV1(t *testing.T) {
|
||||
sources_list, api, err := ListSourcesV1(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 := DeleteSourceV1(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 := ListSourcesV1(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)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -416,8 +416,22 @@ func (s *Store) PushSource(key string, source SourceConfig) {
|
|||
})
|
||||
}
|
||||
|
||||
// DeleteSource removes a SourceConfig from store.Sources
|
||||
func (s *Store) DeleteSource(key string) {
|
||||
// DeleteSourceByName removes a SourceConfig from store.Sources using the .Name field
|
||||
func (s *Store) DeleteSourceByName(name string) {
|
||||
// FIXME: handle or comment this possible error
|
||||
_ = s.change(func() error {
|
||||
for key := range s.sources {
|
||||
if s.sources[key].Name == name {
|
||||
delete(s.sources, key)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
// DeleteSourceByID removes a SourceConfig from store.Sources using the ID
|
||||
func (s *Store) DeleteSourceByID(key string) {
|
||||
// FIXME: handle or comment this possible error
|
||||
_ = s.change(func() error {
|
||||
delete(s.sources, key)
|
||||
|
|
|
|||
|
|
@ -625,8 +625,12 @@ func (api *API) sourceDeleteHandler(writer http.ResponseWriter, request *http.Re
|
|||
return
|
||||
}
|
||||
|
||||
// remove leading / from first name
|
||||
api.store.DeleteSource(name[0][1:])
|
||||
// Only delete the first name, which will have a / at the start because of the /*source route
|
||||
if isRequestVersionAtLeast(params, 1) {
|
||||
api.store.DeleteSourceByID(name[0][1:])
|
||||
} else {
|
||||
api.store.DeleteSourceByName(name[0][1:])
|
||||
}
|
||||
|
||||
statusResponseOK(writer)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue