mirror of
https://github.com/goharbor/harbor.git
synced 2024-12-18 06:38:19 +01:00
Add more unit test cases for docker hub adapter
Add more unit test cases for docker hub adapter Signed-off-by: Wenkai Yin <yinw@vmware.com>
This commit is contained in:
parent
09c5f9cfc8
commit
4f7fe1452f
@ -4,13 +4,13 @@ import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
adp "github.com/goharbor/harbor/src/replication/adapter"
|
||||
"github.com/goharbor/harbor/src/replication/model"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
// TODO add more unit test
|
||||
|
||||
const (
|
||||
testUser = ""
|
||||
testPassword = ""
|
||||
@ -35,6 +35,21 @@ func getAdapter(t *testing.T) adp.Adapter {
|
||||
return adapter
|
||||
}
|
||||
|
||||
func TestInfo(t *testing.T) {
|
||||
adapter := &adapter{}
|
||||
info, err := adapter.Info()
|
||||
require.Nil(t, err)
|
||||
require.Equal(t, 1, len(info.SupportedResourceTypes))
|
||||
assert.Equal(t, model.ResourceTypeImage, info.SupportedResourceTypes[0])
|
||||
}
|
||||
|
||||
func TestListCandidateNamespaces(t *testing.T) {
|
||||
adapter := &adapter{}
|
||||
namespaces, err := adapter.listCandidateNamespaces("library/*")
|
||||
require.Nil(t, err)
|
||||
require.Equal(t, 1, len(namespaces))
|
||||
assert.Equal(t, "library", namespaces[0])
|
||||
}
|
||||
func TestListNamespaces(t *testing.T) {
|
||||
if testUser == "" {
|
||||
return
|
||||
@ -50,3 +65,15 @@ func TestListNamespaces(t *testing.T) {
|
||||
fmt.Println(ns)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFetchImages(t *testing.T) {
|
||||
ad := getAdapter(t)
|
||||
adapter := ad.(*adapter)
|
||||
_, err := adapter.FetchImages([]*model.Filter{
|
||||
{
|
||||
Type: model.FilterTypeName,
|
||||
Value: "goharbor/harbor-core",
|
||||
},
|
||||
})
|
||||
require.Nil(t, err)
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ import (
|
||||
|
||||
"github.com/goharbor/harbor/src/common/utils/log"
|
||||
"github.com/goharbor/harbor/src/replication/model"
|
||||
"github.com/goharbor/harbor/src/replication/util"
|
||||
)
|
||||
|
||||
// Client is a client to interact with DockerHub
|
||||
@ -23,8 +24,10 @@ type Client struct {
|
||||
// NewClient creates a new DockerHub client.
|
||||
func NewClient(registry *model.Registry) (*Client, error) {
|
||||
client := &Client{
|
||||
host: registry.URL,
|
||||
client: http.DefaultClient,
|
||||
host: registry.URL,
|
||||
client: &http.Client{
|
||||
Transport: util.GetHTTPTransport(false),
|
||||
},
|
||||
}
|
||||
|
||||
// For anonymous access, no need to refresh token.
|
||||
|
Loading…
Reference in New Issue
Block a user