mirror of
https://github.com/goharbor/harbor.git
synced 2024-12-18 22:57:38 +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"
|
"fmt"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
adp "github.com/goharbor/harbor/src/replication/adapter"
|
adp "github.com/goharbor/harbor/src/replication/adapter"
|
||||||
"github.com/goharbor/harbor/src/replication/model"
|
"github.com/goharbor/harbor/src/replication/model"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
// TODO add more unit test
|
|
||||||
|
|
||||||
const (
|
const (
|
||||||
testUser = ""
|
testUser = ""
|
||||||
testPassword = ""
|
testPassword = ""
|
||||||
@ -35,6 +35,21 @@ func getAdapter(t *testing.T) adp.Adapter {
|
|||||||
return 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) {
|
func TestListNamespaces(t *testing.T) {
|
||||||
if testUser == "" {
|
if testUser == "" {
|
||||||
return
|
return
|
||||||
@ -50,3 +65,15 @@ func TestListNamespaces(t *testing.T) {
|
|||||||
fmt.Println(ns)
|
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/common/utils/log"
|
||||||
"github.com/goharbor/harbor/src/replication/model"
|
"github.com/goharbor/harbor/src/replication/model"
|
||||||
|
"github.com/goharbor/harbor/src/replication/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Client is a client to interact with DockerHub
|
// Client is a client to interact with DockerHub
|
||||||
@ -23,8 +24,10 @@ type Client struct {
|
|||||||
// NewClient creates a new DockerHub client.
|
// NewClient creates a new DockerHub client.
|
||||||
func NewClient(registry *model.Registry) (*Client, error) {
|
func NewClient(registry *model.Registry) (*Client, error) {
|
||||||
client := &Client{
|
client := &Client{
|
||||||
host: registry.URL,
|
host: registry.URL,
|
||||||
client: http.DefaultClient,
|
client: &http.Client{
|
||||||
|
Transport: util.GetHTTPTransport(false),
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
// For anonymous access, no need to refresh token.
|
// For anonymous access, no need to refresh token.
|
||||||
|
Loading…
Reference in New Issue
Block a user