Skip to content

Commit

Permalink
Merge pull request #8843 from heww/fix-chart-builder
Browse files Browse the repository at this point in the history
fix(chart,quota): fix path regexp of chart creation and deletion
  • Loading branch information
ywk253100 committed Sep 2, 2019
2 parents f12a45b + 1d8eac8 commit d762e07
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/core/middlewares/chart/builder.go
Expand Up @@ -29,8 +29,8 @@ import (
)

var (
deleteChartVersionRe = regexp.MustCompile(`^/api/chartrepo/(?P<namespace>\w+)/charts/(?P<name>\w+)/(?P<version>[\w\d\.]+)/?$`)
createChartVersionRe = regexp.MustCompile(`^/api/chartrepo/(?P<namespace>\w+)/charts/?$`)
deleteChartVersionRe = regexp.MustCompile(`^/api/chartrepo/(?P<namespace>[^?#]+)/charts/(?P<name>[^?#]+)/(?P<version>[^?#]+)/?$`)
createChartVersionRe = regexp.MustCompile(`^/api/chartrepo/(?P<namespace>[^?#]+)/charts/?$`)
)

var (
Expand Down
39 changes: 39 additions & 0 deletions src/core/middlewares/chart/handler_test.go
Expand Up @@ -120,6 +120,21 @@ func (suite *HandlerSuite) TestUpload() {
uploadChartVersion(projectID, projectName, "harbor", "0.2.0")
suite.AssertResourceUsage(1, types.ResourceCount, projectID)
}, "repo1")

suite.WithProject(func(projectID int64, projectName string) {
uploadChartVersion(projectID, projectName, "harbor-ha", "dev")
suite.AssertResourceUsage(1, types.ResourceCount, projectID)
}, "harbor-contrib")

suite.WithProject(func(projectID int64, projectName string) {
uploadChartVersion(projectID, projectName, "acs-engine-autoscaler", "1.0.0")
suite.AssertResourceUsage(1, types.ResourceCount, projectID)
}, "cluster-autoscaler")

suite.WithProject(func(projectID int64, projectName string) {
uploadChartVersion(projectID, projectName, "123456", "1-0")
suite.AssertResourceUsage(1, types.ResourceCount, projectID)
}, "123456")
}

func (suite *HandlerSuite) TestDelete() {
Expand All @@ -130,6 +145,30 @@ func (suite *HandlerSuite) TestDelete() {
deleteChartVersion(projectName, "harbor", "0.2.1")
suite.AssertResourceUsage(0, types.ResourceCount, projectID)
}, "repo1")

suite.WithProject(func(projectID int64, projectName string) {
uploadChartVersion(projectID, projectName, "harbor-ha", "dev")
suite.AssertResourceUsage(1, types.ResourceCount, projectID)

deleteChartVersion(projectName, "harbor-ha", "dev")
suite.AssertResourceUsage(0, types.ResourceCount, projectID)
}, "harbor-contrib")

suite.WithProject(func(projectID int64, projectName string) {
uploadChartVersion(projectID, projectName, "acs-engine-autoscaler", "1.0.0")
suite.AssertResourceUsage(1, types.ResourceCount, projectID)

deleteChartVersion(projectName, "acs-engine-autoscaler", "1.0.0")
suite.AssertResourceUsage(0, types.ResourceCount, projectID)
}, "cluster-autoscaler")

suite.WithProject(func(projectID int64, projectName string) {
uploadChartVersion(projectID, projectName, "123456", "1-0")
suite.AssertResourceUsage(1, types.ResourceCount, projectID)

deleteChartVersion(projectName, "123456", "1-0")
suite.AssertResourceUsage(0, types.ResourceCount, projectID)
}, "123456")
}

func TestRunHandlerSuite(t *testing.T) {
Expand Down

0 comments on commit d762e07

Please sign in to comment.