Skip to content
Merged
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
3 changes: 3 additions & 0 deletions cmd/harbor/root/artifact/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ Supports pagination, search queries, and sorting using flags.`,

Args: cobra.MaximumNArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
if opts.Page < 1 {
return fmt.Errorf("page number must be greater than or equal to 1")
}
if opts.PageSize < 0 {
return fmt.Errorf("page size must be greater than or equal to 0")
}
Expand Down
34 changes: 34 additions & 0 deletions cmd/harbor/root/artifact/list_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// 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 artifact

import (
"bytes"
"testing"

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

func TestListArtifactCommand_InvalidPage(t *testing.T) {
cmd := ListArtifactCommand()

var buf bytes.Buffer
cmd.SetOut(&buf)
cmd.SetErr(&buf)
cmd.SetArgs([]string{"--page", "0"})

err := cmd.Execute()
assert.Error(t, err)
assert.Contains(t, err.Error(), "page number must be greater than or equal to 1")
}
3 changes: 3 additions & 0 deletions cmd/harbor/root/instance/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ This command provides an easy way to view all instances along with their details
Example: ` harbor-cli instance list --page 1 --page-size 10
harbor-cli instance list --query "name=my-instance" --sort "asc"`,
RunE: func(cmd *cobra.Command, args []string) error {
if opts.Page < 1 {
return fmt.Errorf("page number must be greater than or equal to 1")
}
if opts.PageSize < 0 {
return fmt.Errorf("page size must be greater than or equal to 0")
}
Expand Down
34 changes: 34 additions & 0 deletions cmd/harbor/root/instance/list_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// 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 instance

import (
"bytes"
"testing"

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

func TestListInstanceCommand_InvalidPage(t *testing.T) {
cmd := ListInstanceCommand()

var buf bytes.Buffer
cmd.SetOut(&buf)
cmd.SetErr(&buf)
cmd.SetArgs([]string{"--page", "0"})

err := cmd.Execute()
assert.Error(t, err)
assert.Contains(t, err.Error(), "page number must be greater than or equal to 1")
}
13 changes: 13 additions & 0 deletions cmd/harbor/root/labels/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,3 +248,16 @@ func TestCreateLabelCommand_FlagDescriptions(t *testing.T) {
descFlag := flags.Lookup("description")
assert.Contains(t, descFlag.Usage, "Description of the label")
}

func TestListLabelCommand_InvalidPage(t *testing.T) {
cmd := ListLabelCommand()

var buf bytes.Buffer
cmd.SetOut(&buf)
cmd.SetErr(&buf)
cmd.SetArgs([]string{"--page", "0"})

err := cmd.Execute()
assert.Error(t, err)
assert.Contains(t, err.Error(), "page number must be greater than or equal to 1")
}
3 changes: 3 additions & 0 deletions cmd/harbor/root/labels/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ func ListLabelCommand() *cobra.Command {
Short: "list labels",
Args: cobra.ExactArgs(0),
RunE: func(cmd *cobra.Command, args []string) error {
if opts.Page < 1 {
return fmt.Errorf("page number must be greater than or equal to 1")
}
if opts.PageSize < 0 {
return fmt.Errorf("page size must be greater than or equal to 0")
}
Expand Down
3 changes: 3 additions & 0 deletions cmd/harbor/root/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ harbor-cli logs --follow --refresh-interval 2s

harbor-cli logs --output-format json`,
RunE: func(cmd *cobra.Command, args []string) error {
if opts.Page < 1 {
return fmt.Errorf("page number must be greater than or equal to 1")
}
if opts.PageSize < 0 {
return fmt.Errorf("page size must be greater than or equal to 0")
}
Expand Down
3 changes: 3 additions & 0 deletions cmd/harbor/root/project/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ func ListProjectCommand() *cobra.Command {
Args: cobra.ExactArgs(0),
RunE: func(cmd *cobra.Command, args []string) error {
log.Debug("Starting project list command")
if opts.Page < 1 {
return fmt.Errorf("page number must be greater than or equal to 1")
}

if opts.PageSize < 0 {
return fmt.Errorf("page size must be greater than or equal to 0")
Expand Down
34 changes: 34 additions & 0 deletions cmd/harbor/root/project/list_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// 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 project

import (
"bytes"
"testing"

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

func TestListProjectCommand_InvalidPage(t *testing.T) {
cmd := ListProjectCommand()

var buf bytes.Buffer
cmd.SetOut(&buf)
cmd.SetErr(&buf)
cmd.SetArgs([]string{"--page", "0"})

err := cmd.Execute()
assert.Error(t, err)
assert.Contains(t, err.Error(), "page number must be greater than or equal to 1")
}
3 changes: 3 additions & 0 deletions cmd/harbor/root/project/member/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ func ListMemberCommand() *cobra.Command {
Example: " harbor project member list my-project",
Args: cobra.MaximumNArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
if opts.Page < 1 {
return fmt.Errorf("page number must be greater than or equal to 1")
}
if opts.PageSize < 0 {
return fmt.Errorf("page size must be greater than or equal to 0")
}
Expand Down
3 changes: 3 additions & 0 deletions cmd/harbor/root/project/robot/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ Examples:
harbor-cli project robot list`,
Args: cobra.MaximumNArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
if opts.Page < 1 {
return fmt.Errorf("page number must be greater than or equal to 1")
}
if opts.PageSize < 0 {
return fmt.Errorf("page size must be greater than or equal to 0")
}
Expand Down
3 changes: 3 additions & 0 deletions cmd/harbor/root/quota/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ func ListQuotaCommand() *cobra.Command {
Short: "list quotas",
Long: "list quotas specified for each project",
RunE: func(cmd *cobra.Command, args []string) error {
if opts.Page < 1 {
return fmt.Errorf("page number must be greater than or equal to 1")
}
if opts.PageSize < 0 {
return fmt.Errorf("page size must be greater than or equal to 0")
}
Expand Down
34 changes: 34 additions & 0 deletions cmd/harbor/root/quota/list_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// 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 quota

import (
"bytes"
"testing"

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

func TestListQuotaCommand_InvalidPage(t *testing.T) {
cmd := ListQuotaCommand()

var buf bytes.Buffer
cmd.SetOut(&buf)
cmd.SetErr(&buf)
cmd.SetArgs([]string{"--page", "0"})

err := cmd.Execute()
assert.Error(t, err)
assert.Contains(t, err.Error(), "page number must be greater than or equal to 1")
}
3 changes: 3 additions & 0 deletions cmd/harbor/root/registry/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ func ListRegistryCommand() *cobra.Command {
Short: "list registry",
Args: cobra.ExactArgs(0),
RunE: func(cmd *cobra.Command, args []string) error {
if opts.Page < 1 {
return fmt.Errorf("page number must be greater than or equal to 1")
}
if opts.PageSize < 0 {
return fmt.Errorf("page size must be greater than or equal to 0")
}
Expand Down
34 changes: 34 additions & 0 deletions cmd/harbor/root/registry/list_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// 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 (
"bytes"
"testing"

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

func TestListRegistryCommand_InvalidPage(t *testing.T) {
cmd := ListRegistryCommand()

var buf bytes.Buffer
cmd.SetOut(&buf)
cmd.SetErr(&buf)
cmd.SetArgs([]string{"--page", "0"})

err := cmd.Execute()
assert.Error(t, err)
assert.Contains(t, err.Error(), "page number must be greater than or equal to 1")
}
18 changes: 10 additions & 8 deletions cmd/harbor/root/replication/executions/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,17 @@ func ListCommand() *cobra.Command {
Args: cobra.MaximumNArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
log.Debug("Starting replication executions list command")
if opts.Page < 1 {
return fmt.Errorf("page number must be greater than or equal to 1")
}

if opts.PageSize < 0 {
return fmt.Errorf("page size must be greater than or equal to 0")
}

if opts.PageSize > 100 {
return fmt.Errorf("page size should be less than or equal to 100")
}
var rpolicyID int64
if len(args) > 0 {
var err error
Expand All @@ -50,14 +60,6 @@ func ListCommand() *cobra.Command {
rpolicyID = prompt.GetReplicationPolicyFromUser()
}

if opts.PageSize < 0 {
return fmt.Errorf("page size must be greater than or equal to 0")
}

if opts.PageSize > 100 {
return fmt.Errorf("page size should be less than or equal to 100")
}

log.Debug("Fetching executions...")
executions, err := api.ListReplicationExecutions(rpolicyID, opts)
if err != nil {
Expand Down
3 changes: 3 additions & 0 deletions cmd/harbor/root/replication/policies/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ func ListCommand() *cobra.Command {
Args: cobra.ExactArgs(0),
RunE: func(cmd *cobra.Command, args []string) error {
log.Debug("Starting replications list command")
if opts.Page < 1 {
return fmt.Errorf("page number must be greater than or equal to 1")
}

if opts.PageSize < 0 {
return fmt.Errorf("page size must be greater than or equal to 0")
Expand Down
4 changes: 4 additions & 0 deletions cmd/harbor/root/repository/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ func ListRepositoryCommand() *cobra.Command {
Long: `Get information of all repositories in a project`,
Args: cobra.MaximumNArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
if opts.Page < 1 {
return fmt.Errorf("page number must be greater than or equal to 1")
}

if opts.PageSize < 0 {
return fmt.Errorf("page size must be greater than or equal to 0")
}
Expand Down
4 changes: 4 additions & 0 deletions cmd/harbor/root/robot/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ Examples:
harbor-cli robot list --output-format json`,
Args: cobra.MaximumNArgs(0),
RunE: func(cmd *cobra.Command, args []string) error {
if opts.Page < 1 {
return fmt.Errorf("page number must be greater than or equal to 1")
}

if opts.PageSize < 0 {
return fmt.Errorf("page size must be greater than or equal to 0")
}
Expand Down
4 changes: 4 additions & 0 deletions cmd/harbor/root/schedule/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ func ListScheduleCommand() *cobra.Command {
Use: "list",
Short: "show all schedule jobs in Harbor",
RunE: func(cmd *cobra.Command, args []string) error {
if opts.Page < 1 {
return fmt.Errorf("page number must be greater than or equal to 1")
}

if opts.PageSize < 0 {
return fmt.Errorf("page size must be greater than or equal to 0")
}
Expand Down
34 changes: 34 additions & 0 deletions cmd/harbor/root/schedule/list_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// 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 schedule

import (
"bytes"
"testing"

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

func TestListScheduleCommand_InvalidPage(t *testing.T) {
cmd := ListScheduleCommand()

var buf bytes.Buffer
cmd.SetOut(&buf)
cmd.SetErr(&buf)
cmd.SetArgs([]string{"--page", "0"})

err := cmd.Execute()
assert.Error(t, err)
assert.Contains(t, err.Error(), "page number must be greater than or equal to 1")
}
Loading
Loading