feat(replication) sort the adapters shown on UI

Signed-off-by: Ziming Zhang <zziming@vmware.com>
This commit is contained in:
Ziming Zhang 2020-03-11 15:11:46 +08:00
parent 7d53a61a92
commit d1d0601841
2 changed files with 16 additions and 1 deletions

View File

@ -113,7 +113,7 @@ func HasFactory(t model.RegistryType) bool {
// ListRegisteredAdapterTypes lists the registered Adapter type
func ListRegisteredAdapterTypes() []model.RegistryType {
types := []model.RegistryType{}
for t := range registryKeys {
for _, t := range registryKeys {
types = append(types, model.RegistryType(t))
}
return types

View File

@ -57,6 +57,7 @@ func TestGetFactory(t *testing.T) {
func TestListRegisteredAdapterTypes(t *testing.T) {
registry = map[model.RegistryType]Factory{}
registryKeys = []string{}
// not register, got nothing
types := ListRegisteredAdapterTypes()
assert.Equal(t, 0, len(types))
@ -68,3 +69,17 @@ func TestListRegisteredAdapterTypes(t *testing.T) {
require.Equal(t, 1, len(types))
assert.Equal(t, model.RegistryType("harbor"), types[0])
}
func TestListRegisteredAdapterTypesOrder(t *testing.T) {
registry = map[model.RegistryType]Factory{}
registryKeys = []string{}
require.Nil(t, RegisterFactory("a", new(fakedFactory)))
require.Nil(t, RegisterFactory("c", new(fakedFactory)))
require.Nil(t, RegisterFactory("b", new(fakedFactory)))
types := ListRegisteredAdapterTypes()
require.Equal(t, 3, len(types))
require.Equal(t, model.RegistryType("a"), types[0])
require.Equal(t, model.RegistryType("b"), types[1])
require.Equal(t, model.RegistryType("c"), types[2])
}