-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
v1: fix getting baseurl for content sources upload repos
These repositories don't have the `Url` set, only the `LatestSnapshotUrl` is set.
- Loading branch information
1 parent
725c4d6
commit 4c5f95c
Showing
5 changed files
with
112 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package content_sources | ||
|
||
import ( | ||
"fmt" | ||
) | ||
|
||
func GetBaseURL(repo ApiRepositoryResponse) (string, error) { | ||
if repo.Origin == nil { | ||
return "", fmt.Errorf("unable to read origin from repository %s", *repo.Uuid) | ||
} | ||
switch *repo.Origin { | ||
case "upload": | ||
return *repo.LatestSnapshotUrl, nil | ||
case "external", "red_hat": | ||
return *repo.Url, nil | ||
} | ||
return "", fmt.Errorf("unknown origin on content sources repository %s, origin: %s", *repo.Uuid, *repo.Origin) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package content_sources_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/osbuild/image-builder/internal/clients/content_sources" | ||
"github.com/osbuild/image-builder/internal/common" | ||
) | ||
|
||
func TestGetBaseURL(t *testing.T) { | ||
url, err := content_sources.GetBaseURL(content_sources.ApiRepositoryResponse{ | ||
Url: common.ToPtr("someurl"), | ||
Origin: common.ToPtr("external"), | ||
}) | ||
require.NoError(t, err) | ||
require.Equal(t, "someurl", url) | ||
|
||
url, err = content_sources.GetBaseURL(content_sources.ApiRepositoryResponse{ | ||
Url: common.ToPtr("someurl"), | ||
Origin: common.ToPtr("red_hat"), | ||
}) | ||
require.NoError(t, err) | ||
require.Equal(t, "someurl", url) | ||
|
||
url, err = content_sources.GetBaseURL(content_sources.ApiRepositoryResponse{ | ||
Url: common.ToPtr("someurl"), | ||
LatestSnapshotUrl: common.ToPtr("realurl"), | ||
Origin: common.ToPtr("upload"), | ||
}) | ||
require.NoError(t, err) | ||
require.Equal(t, "realurl", url) | ||
|
||
_, err = content_sources.GetBaseURL(content_sources.ApiRepositoryResponse{ | ||
Uuid: common.ToPtr("d15a0c50-1549-4d04-bcb8-b3553576acd4"), | ||
}) | ||
require.Error(t, err) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters