weldr: Update projects/source/info to support API v1

This commit changes the store.GetAllSources to distinguish between
getting the source by the Name field, or by the ID (the key to the map)
using GetAllSourcesByName and ...ByID.

SourceConfig.RepoConfig() now takes an id parameter because SourceConfig
only stores the Name, not the ID.

In weldr I split the sourceInfoHandler into 2 separate functions for v0
and v1 behavior, with the core of the old function refactored as
getSourceConfigs and used by both of them.

This also adds new structs for the SourceResponseV0 and SourceResponseV1
as well as helper functions for converting to/from store.SourceConfig
This commit is contained in:
Brian C. Lane 2020-04-30 13:58:51 -07:00 committed by Tom Gundersen
parent ddd2010815
commit 982d292a96
5 changed files with 193 additions and 27 deletions

View file

@ -319,7 +319,7 @@ func TestListSourcesV1(t *testing.T) {
require.Contains(t, list, "package-repo-2")
}
// Get the source info
// Get the source info using the v0 API
func TestGetSourceInfoV0(t *testing.T) {
source := `
name = "package-repo-info-v0"
@ -348,6 +348,37 @@ func TestGetSourceInfoV0(t *testing.T) {
require.True(t, resp.Status, "DELETE source failed: %#v", resp)
}
// Get the source info using the v1 API
func TestGetSourceInfoV1(t *testing.T) {
source := `
id = "package-repo-info-v1"
name = "repo for info test v1"
url = "file://REPO-PATH"
type = "yum-baseurl"
proxy = "https://proxy-url/"
check_ssl = true
check_gpg = true
gpgkey_urls = ["https://url/path/to/gpg-key"]
`
source = strings.Replace(source, "REPO-PATH", testState.repoDir, 1)
resp, err := PostTOMLSourceV1(testState.socket, source)
require.NoError(t, err, "POST source failed with a client error")
require.True(t, resp.Status, "POST source failed: %#v", resp)
info, resp, err := GetSourceInfoV1(testState.socket, "package-repo-info-v1")
require.NoError(t, err, "GET source failed with a client error")
require.Nil(t, resp, "GET source failed: %#v", resp)
require.Contains(t, info, "package-repo-info-v1", "No source info returned")
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")
require.NoError(t, err, "DELETE source failed with a client error")
require.True(t, resp.Status, "DELETE source failed: %#v", resp)
}
func UploadUserDefinedSourcesV0(t *testing.T, sources []string) {
for i := range sources {
source := strings.Replace(sources[i], "REPO-PATH", testState.repoDir, 1)