Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion cmd/harbor/root/registry/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,12 @@ func DeleteRegistryCommand() *cobra.Command {
errChan := make(chan error, len(args))
if len(args) > 0 {
for _, arg := range args {
registryID, _ := api.GetRegistryIdByName(arg)
registryID, err := api.GetRegistryIdByName(arg)
if err != nil {
errChan <- fmt.Errorf("failed to get registry id for %q: %w", arg, err)
continue
}

wg.Add(1)
go func(registryID int64) {
defer wg.Done()
Expand Down
30 changes: 30 additions & 0 deletions cmd/harbor/root/registry/delete_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright Project Harbor Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package registry

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestDeleteRegistryCommand(t *testing.T) {
cmd := DeleteRegistryCommand()
Comment thread
PrasunaEnumarthy marked this conversation as resolved.

assert.Equal(t, "delete", cmd.Use)
assert.Equal(t, "delete registry by name or id", cmd.Short)
assert.Equal(t, "harbor registry delete [registryname]", cmd.Example)
assert.NotNil(t, cmd.RunE)
assert.NotNil(t, cmd.Args)
}
4 changes: 2 additions & 2 deletions pkg/api/registry_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ func GetRegistryProviders() ([]string, error) {
}

Comment thread
PrasunaEnumarthy marked this conversation as resolved.
func GetRegistryIdByName(registryName string) (int64, error) {
var opts ListFlags
opts := ListFlags{Name: registryName}

r, err := ListRegistries(opts)
if err != nil {
Expand All @@ -188,5 +188,5 @@ func GetRegistryIdByName(registryName string) (int64, error) {
}
}

return 0, err
return 0, fmt.Errorf("registry '%s' not found", registryName)
}
Loading