2020-01-26 14:29:11 +00:00
|
|
|
package hub
|
2019-09-16 19:36:27 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
2019-09-24 12:42:46 +00:00
|
|
|
"github.com/volker-raschek/docker-hub-description-updater/pkg/types"
|
2019-09-16 19:36:27 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
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,
|
|
|
|
}
|
|
|
|
|
2020-01-26 14:29:11 +00:00
|
|
|
h := New(loginCredentials)
|
|
|
|
|
2019-09-16 19:36:27 +00:00
|
|
|
require := require.New(t)
|
|
|
|
|
|
|
|
readme, err := Asset("README.md")
|
|
|
|
require.NoError(err)
|
|
|
|
|
2020-01-26 14:29:11 +00:00
|
|
|
currentRepository, err := h.GetRepository(dockerHubNamespace, dockerHubRepository)
|
2019-09-16 19:36:27 +00:00
|
|
|
require.NoError(err)
|
|
|
|
|
|
|
|
expectedRepository := *currentRepository
|
|
|
|
expectedRepository.FullDescription = string(readme)
|
|
|
|
|
2020-01-26 14:29:11 +00:00
|
|
|
actualRepository, err := h.PatchRepository(&expectedRepository)
|
2019-09-16 19:36:27 +00:00
|
|
|
require.NoError(err)
|
2020-01-26 14:29:11 +00:00
|
|
|
require.EqualValues(&expectedRepository.FullDescription, actualRepository.FullDescription, "Full description not equal")
|
2019-09-16 19:36:27 +00:00
|
|
|
}
|