2020-12-14 06:34:35 +01:00
|
|
|
// 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 (
|
|
|
|
"context"
|
2022-01-05 04:13:40 +01:00
|
|
|
accessorymodel "github.com/goharbor/harbor/src/pkg/accessory/model"
|
2020-12-14 06:34:35 +01:00
|
|
|
"testing"
|
|
|
|
|
2021-02-23 05:23:36 +01:00
|
|
|
"github.com/goharbor/harbor/src/lib/q"
|
2020-12-14 06:34:35 +01:00
|
|
|
"github.com/goharbor/harbor/src/pkg/artifact"
|
2022-01-05 04:13:40 +01:00
|
|
|
"github.com/goharbor/harbor/src/testing/pkg/accessory"
|
|
|
|
accessorytesting "github.com/goharbor/harbor/src/testing/pkg/accessory"
|
2020-12-14 06:34:35 +01:00
|
|
|
artifacttesting "github.com/goharbor/harbor/src/testing/pkg/artifact"
|
2021-02-23 05:23:36 +01:00
|
|
|
"github.com/stretchr/testify/mock"
|
2020-12-14 06:34:35 +01:00
|
|
|
"github.com/stretchr/testify/suite"
|
|
|
|
)
|
|
|
|
|
|
|
|
type IteratorTestSuite struct {
|
|
|
|
suite.Suite
|
|
|
|
|
2021-02-23 05:23:36 +01:00
|
|
|
artMgr *artifacttesting.Manager
|
2022-01-05 04:13:40 +01:00
|
|
|
accMgr *accessory.Manager
|
2020-12-14 06:34:35 +01:00
|
|
|
|
|
|
|
ctl *controller
|
|
|
|
originalCtl Controller
|
|
|
|
}
|
|
|
|
|
|
|
|
func (suite *IteratorTestSuite) SetupSuite() {
|
2021-02-23 05:23:36 +01:00
|
|
|
suite.artMgr = &artifacttesting.Manager{}
|
2022-01-05 04:13:40 +01:00
|
|
|
suite.accMgr = &accessorytesting.Manager{}
|
2020-12-14 06:34:35 +01:00
|
|
|
|
|
|
|
suite.originalCtl = Ctl
|
2022-01-05 04:13:40 +01:00
|
|
|
suite.ctl = &controller{
|
|
|
|
artMgr: suite.artMgr,
|
|
|
|
accessoryMgr: suite.accMgr,
|
|
|
|
}
|
2020-12-14 06:34:35 +01:00
|
|
|
Ctl = suite.ctl
|
|
|
|
}
|
|
|
|
|
|
|
|
func (suite *IteratorTestSuite) TeardownSuite() {
|
|
|
|
Ctl = suite.originalCtl
|
|
|
|
}
|
|
|
|
|
|
|
|
func (suite *IteratorTestSuite) TestIterator() {
|
2022-01-05 04:13:40 +01:00
|
|
|
suite.accMgr.On("List", mock.Anything, mock.Anything).Return([]accessorymodel.Accessory{}, nil)
|
2021-02-23 05:23:36 +01:00
|
|
|
q1 := &q.Query{PageNumber: 1, PageSize: 5, Keywords: map[string]interface{}{}}
|
|
|
|
suite.artMgr.On("List", mock.Anything, q1).Return([]*artifact.Artifact{
|
2020-12-14 06:34:35 +01:00
|
|
|
{ID: 1},
|
|
|
|
{ID: 2},
|
|
|
|
{ID: 3},
|
2021-02-23 05:23:36 +01:00
|
|
|
{ID: 4},
|
|
|
|
{ID: 5},
|
|
|
|
}, nil)
|
|
|
|
|
|
|
|
q2 := &q.Query{PageNumber: 2, PageSize: 5, Keywords: map[string]interface{}{}}
|
|
|
|
suite.artMgr.On("List", mock.Anything, q2).Return([]*artifact.Artifact{
|
|
|
|
{ID: 6},
|
|
|
|
{ID: 7},
|
|
|
|
{ID: 8},
|
2020-12-14 06:34:35 +01:00
|
|
|
}, nil)
|
|
|
|
|
|
|
|
var artifacts []*Artifact
|
|
|
|
for art := range Iterator(context.TODO(), 5, nil, nil) {
|
|
|
|
artifacts = append(artifacts, art)
|
|
|
|
}
|
|
|
|
|
2021-02-23 05:23:36 +01:00
|
|
|
suite.Len(artifacts, 8)
|
2020-12-14 06:34:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestIteratorTestSuite(t *testing.T) {
|
|
|
|
suite.Run(t, &IteratorTestSuite{})
|
|
|
|
}
|