feat: use goreleaser

This commit is contained in:
2025-05-31 17:50:38 +02:00
parent 4e23b5f299
commit 23da9d9aea
12 changed files with 228 additions and 269 deletions

View File

@ -3,13 +3,11 @@ package hub
import "errors"
var (
errorFailedToCreateRequest = errors.New("Failed to create http request")
errorFailedToParseJSON = errors.New("Failed to parse json")
errorFailedToParseURL = errors.New("Failed to parse url")
errorFailedToSendRequest = errors.New("Failed to send http request")
errorNoUserDefined = errors.New("No User defined")
errorNoPasswordDefined = errors.New("No Password defined")
errorNoNamespaceDefined = errors.New("No Namespace defined")
errorNoRepositoryDefined = errors.New("No Repository defined")
errorUnexpectedHTTPStatuscode = errors.New("Unexpected HTTP-Statuscode")
errorFailedToCreateRequest = errors.New("failed to create http request")
errorFailedToParseJSON = errors.New("failed to parse json")
errorFailedToParseURL = errors.New("failed to parse url")
errorFailedToSendRequest = errors.New("failed to send http request")
errorNoNamespaceDefined = errors.New("no Namespace defined")
errorNoRepositoryDefined = errors.New("no Repository defined")
errorUnexpectedHTTPStatuscode = errors.New("unexpected HTTP-Statuscode")
)

View File

@ -56,7 +56,7 @@ func (h *Hub) GetRepository(namespace string, name string) (*types.Repository, e
if err != nil {
return nil, fmt.Errorf("%v: %v", errorFailedToSendRequest, err)
}
defer resp.Body.Close()
defer func() { _ = resp.Body.Close() }()
if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("%v: expect %v, received %v", errorUnexpectedHTTPStatuscode, http.StatusOK, resp.StatusCode)
@ -89,7 +89,7 @@ func (h *Hub) getToken() (*types.Token, error) {
if err != nil {
return nil, fmt.Errorf("%v: %v", errorFailedToCreateRequest, err)
}
defer resp.Body.Close()
defer func() { _ = resp.Body.Close() }()
if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("%v: expect %v, received %v", errorUnexpectedHTTPStatuscode, http.StatusOK, resp.StatusCode)
@ -144,7 +144,7 @@ func (h *Hub) PatchRepository(repository *types.Repository) (*types.Repository,
if err != nil {
return nil, fmt.Errorf("%v: %v", errorFailedToCreateRequest, err)
}
defer resp.Body.Close()
defer func() { _ = resp.Body.Close() }()
if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("%v: expect %v, received %v", errorUnexpectedHTTPStatuscode, http.StatusOK, resp.StatusCode)

View File

@ -1,54 +0,0 @@
package hub
import (
"os"
"testing"
"github.com/stretchr/testify/require"
"github.com/volker-raschek/docker-hub-description-updater/pkg/types"
)
func TestPatchRepository(t *testing.T) {
dockerHubUser := os.Getenv("REGISTRY_USER")
if len(dockerHubUser) <= 0 {
t.Fatalf("Environment variable REGISTRY_USER is empty")
}
dockerHubPassword := os.Getenv("REGISTRY_PASSWORD")
if len(dockerHubPassword) <= 0 {
t.Fatalf("Environment variable REGISTRY_PASSWORD is empty")
}
dockerHubNamespace := os.Getenv("REGISTRY_NAMESPACE")
if len(dockerHubNamespace) <= 0 {
t.Fatalf("Environment variable REGISTRY_NAMESPACE is empty")
}
dockerHubRepository := os.Getenv("CONTAINER_IMAGE_NAME")
if len(dockerHubRepository) <= 0 {
t.Fatalf("Environment variable CONTAINER_IMAGE_NAME is empty")
}
loginCredentials := &types.LoginCredentials{
User: dockerHubUser,
Password: dockerHubPassword,
}
h := New(loginCredentials)
require := require.New(t)
readme, err := Asset("README.md")
require.NoError(err)
currentRepository, err := h.GetRepository(dockerHubNamespace, dockerHubRepository)
require.NoError(err)
expectedRepository := *currentRepository
expectedRepository.FullDescription = string(readme)
actualRepository, err := h.PatchRepository(&expectedRepository)
require.NoError(err)
require.EqualValues(&expectedRepository.FullDescription, actualRepository.FullDescription, "Full description not equal")
}