harbor/src/replication/adapter/dockerhub/adapter_test.go
Wenkai Yin 5925e0862d Replicate tag deletion between Harbor instances
This commit introduces the tag deletion as a new capability for registry adapters, and currently only Harbor supports it

Signed-off-by: Wenkai Yin <yinw@vmware.com>
2020-03-17 09:27:02 +08:00

80 lines
1.7 KiB
Go

package dockerhub
import (
"fmt"
"testing"
adp "github.com/goharbor/harbor/src/replication/adapter"
"github.com/goharbor/harbor/src/replication/model"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
const (
testUser = ""
testPassword = ""
)
func getAdapter(t *testing.T) adp.Adapter {
assert := assert.New(t)
factory, err := adp.GetFactory(model.RegistryTypeDockerHub)
assert.Nil(err)
assert.NotNil(factory)
adapter, err := newAdapter(&model.Registry{
Type: model.RegistryTypeDockerHub,
URL: baseURL,
Credential: &model.Credential{
AccessKey: testUser,
AccessSecret: testPassword,
},
})
assert.Nil(err)
assert.NotNil(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
}
assert := assert.New(t)
ad := getAdapter(t)
adapter := ad.(*adapter)
namespaces, err := adapter.listNamespaces()
assert.Nil(err)
for _, ns := range namespaces {
fmt.Println(ns)
}
}
func TestFetchArtifacts(t *testing.T) {
ad := getAdapter(t)
adapter := ad.(*adapter)
_, err := adapter.FetchArtifacts([]*model.Filter{
{
Type: model.FilterTypeName,
Value: "goharbor/harbor-core",
},
})
require.Nil(t, err)
}