Skip to content

Commit

Permalink
fix: ut & lint
Browse files Browse the repository at this point in the history
Signed-off-by: xu.zhu <[email protected]>
  • Loading branch information
xuzhu-591 committed Jun 1, 2023
1 parent 1e64e7a commit 3e095d3
Show file tree
Hide file tree
Showing 13 changed files with 660 additions and 34 deletions.
2 changes: 1 addition & 1 deletion core/controller/application/v2models.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type GetApplicationResponseV2 struct {
Priority string `json:"priority"`
Tags tagmodels.TagsBasic `json:"tags,omitempty"`
Git *codemodels.Git `json:"git"`
Image string `json:"image"`
Image string `json:"image"`

BuildConfig map[string]interface{} `json:"buildConfig"`
TemplateInfo *codemodels.TemplateInfo `json:"templateInfo"`
Expand Down
3 changes: 1 addition & 2 deletions core/controller/cluster/controller_internal_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,8 @@ func (c *controller) InternalDeployV2(ctx context.Context, clusterID uint,
EventType: func() string {
if pr.Action == prmodels.ActionBuildDeploy {
return eventmodels.ClusterBuildDeployed
} else {
return eventmodels.ClusterDeployed
}
return eventmodels.ClusterDeployed
}(),
ResourceID: cluster.ID,
},
Expand Down
3 changes: 2 additions & 1 deletion core/controller/cluster/controller_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ const (
_notFound = "NotFound"
)

func (c *controller) GetClusterPipelinerunStatus(ctx context.Context, clusterID uint) (*PipelinerunStatusResponse, error) {
func (c *controller) GetClusterPipelinerunStatus(ctx context.Context,
clusterID uint) (*PipelinerunStatusResponse, error) {
resp := &PipelinerunStatusResponse{}

// get latest pipelinerun
Expand Down
12 changes: 7 additions & 5 deletions core/controller/cluster/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -844,7 +844,7 @@ func test(t *testing.T) {

tekton := tektonmock.NewMockInterface(mockCtl)
tektonFty.EXPECT().GetTekton(gomock.Any()).Return(tekton, nil).AnyTimes()
tekton.EXPECT().CreatePipelineRun(ctx, gomock.Any()).Return("abc", nil)
tekton.EXPECT().CreatePipelineRun(ctx, gomock.Any()).Return("abc", nil).Times(2)
tekton.EXPECT().GetPipelineRunByID(ctx, gomock.Any()).Return(pr, nil).AnyTimes()
tektonCollector := tektoncollectormock.NewMockInterface(mockCtl)

Expand Down Expand Up @@ -972,7 +972,10 @@ func test(t *testing.T) {

// test deploy
clusterGitRepo.EXPECT().GetPipelineOutput(ctx, gomock.Any(), gomock.Any(), gomock.Any()).Return(nil, herrors.ErrPipelineOutputEmpty).Times(1)

commitGetter.EXPECT().GetCommit(ctx, gomock.Any(), gomock.Any(), gomock.Any()).Return(&git.Commit{
ID: commitID,
Message: commitMsg,
}, nil).AnyTimes()
deployResp, err := c.Deploy(ctx, resp.ID, &DeployRequest{
Title: "deploy-title",
Description: "deploy-description",
Expand Down Expand Up @@ -1009,8 +1012,7 @@ func test(t *testing.T) {

pr, err = manager.PipelinerunMgr.GetByID(ctx, deployResp.PipelinerunID)
assert.Nil(t, err)
assert.Equal(t, string(prmodels.StatusOK), pr.Status)
assert.NotNil(t, pr.FinishedAt)
assert.Equal(t, string(prmodels.StatusCreated), pr.Status)

// test next
k8sutil.EXPECT().ExecuteAction(ctx, gomock.Any()).Return(nil)
Expand Down Expand Up @@ -1429,7 +1431,7 @@ func testV2(t *testing.T) {
resp, err := c.CreateClusterV2(ctx, &CreateClusterParamsV2{
CreateClusterRequestV2: createReq,
ApplicationID: application.ID,
Environment: "test",
Environment: "test2",
Region: "hz",
MergePatch: false,
InheritConfig: true,
Expand Down
2 changes: 1 addition & 1 deletion core/controller/cluster/models_basic_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ type CreateClusterRequestV2 struct {
Priority string `json:"priority"`
ExpireTime string `json:"expireTime"`
Git *codemodels.Git `json:"git"`
Image *string `json:"image"`
Image *string `json:"image"`
Tags tagmodels.TagsBasic `json:"tags"`

BuildConfig map[string]interface{} `json:"buildConfig"`
Expand Down
2 changes: 0 additions & 2 deletions core/controller/pipelinerun/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,13 @@ func (c *controller) GetPipelinerunLog(ctx context.Context, pipelinerunID uint)
}

// only builddeploy and deploy have logs
// TODO(zhuxu): 如何后向兼容没有日志的deploy类型流水线
if pr.Action != prmodels.ActionBuildDeploy && pr.Action != prmodels.ActionDeploy {
return nil, errors.E(op, fmt.Errorf("%v action has no log", pr.Action))
}

return c.getPipelinerunLog(ctx, pr, cluster.EnvironmentName)
}

// TODO(zhuxu): 后向兼容没有日志的deploy类型流水线
func (c *controller) GetClusterLatestLog(ctx context.Context, clusterID uint) (_ *collector.Log, err error) {
const op = "pipelinerun controller: get cluster latest log"
defer wlog.Start(ctx, op).StopPrint()
Expand Down
2 changes: 0 additions & 2 deletions core/http/api/v2/cluster/apis_basic.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,6 @@ func (a *API) Create(c *gin.Context) {
request.ExtraMembers[extraOwner] = role.Owner
}

// resp, err := a.clusterCtl.CreateClusterV2(c, uint(applicationID), environment,
// region, request, mergePatch)
resp, err := a.clusterCtl.CreateClusterV2(c, &cluster.CreateClusterParamsV2{
CreateClusterRequestV2: request,
ApplicationID: uint(applicationID),
Expand Down
619 changes: 619 additions & 0 deletions db/20230515.sql

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions db/migrations/20230515_add_image_to_app.sql
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
-- limitations under the License.

ALTER TABLE tb_application
ADD COLUMN `image` varchar(256) DEFAULT NULL COMMENT 'artifact image url'
ADD COLUMN `image` varchar(256) DEFAULT NULL
COMMENT 'artifact image url for the application';

ALTER TABLE tb_cluster
ADD COLUMN `image` varchar(256) DEFAULT NULL COMMENT 'artifact image url'
ADD COLUMN `image` varchar(256) DEFAULT NULL
COMMENT 'artifact image url for the cluster';
29 changes: 17 additions & 12 deletions mock/pkg/pipelinerun/manager/mock_manager.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion mock/pkg/tag/manager/manager.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions openapi/v2/restful/cluster.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1210,6 +1210,8 @@ components:
$ref: "#/components/schemas/Commit"
Image:
type: string
ImageTag:
type: string
GitResponse:
type: object
properties:
Expand Down Expand Up @@ -1462,6 +1464,8 @@ components:
$ref: "#/components/schemas/Title"
description:
$ref: "#/components/schemas/Description"
imageTag:
$ref: "#/components/schemas/ImageTag"

RollbackRequest:
type: object
Expand Down
10 changes: 5 additions & 5 deletions pkg/common/db_scripts.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,11 +203,11 @@ const (

/* sql about pipelinerun */
const (
PipelinerunGetByID = "select * from tb_pipelinerun where id = ?"
PipelinerunGetByCIEventID = "select * from tb_pipelinerun where ci_event_id = ?"
PipelinerunDeleteByID = "delete from tb_pipelinerun where id = ?"
PipelinerunDeleteByClusterID = "delete from tb_pipelinerun where cluster_id = ?"
PipelinerunUpdateConfigCommitByID = "update tb_pipelinerun set config_commit = ? where id = ?"
PipelinerunGetByID = "select * from tb_pipelinerun where id = ?"
PipelinerunGetByCIEventID = "select * from tb_pipelinerun where ci_event_id = ?"
PipelinerunDeleteByID = "delete from tb_pipelinerun where id = ?"
PipelinerunDeleteByClusterID = "delete from tb_pipelinerun where cluster_id = ?"
PipelinerunUpdateConfigCommitByID = "update tb_pipelinerun set config_commit = ? where id = ?"
PipelinerunGetLatestByClusterIDAndActions = "select * from tb_pipelinerun where cluster_id = ? " +
"and action in ? order by id desc limit 1"
PipelinerunGetLatestByClusterIDAndActionAndStatus = "select * from tb_pipelinerun where cluster_id = ? " +
Expand Down

0 comments on commit 3e095d3

Please sign in to comment.