Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

autotest plan action filter archived #2663

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
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,10 @@ func testPlanRun(ctx context.Context, c *apistructs.Component, scenario apistruc

// get testplan
testPlanRequest := apistructs.TestPlanV2PagingRequest{
ProjectID: uint64(projectId),
PageNo: 1,
PageSize: 999,
ProjectID: uint64(projectId),
PageNo: 1,
PageSize: 999,
IsArchived: &[]bool{false}[0],
}
testPlanRequest.UserID = bdl.Identity.UserID
plans, err := bdl.Bdl.PagingTestPlansV2(testPlanRequest)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,16 @@
package action

import (
"context"
"fmt"
"reflect"
"testing"

"bou.ke/monkey"

"github.com/erda-project/erda/apistructs"
"github.com/erda-project/erda/bundle"
protocol "github.com/erda-project/erda/modules/openapi/component-protocol"
)

func Test_fillTestPlanFields(t *testing.T) {
Expand Down Expand Up @@ -139,3 +144,59 @@ func Test_fillTestPlanFields(t *testing.T) {
})
}
}

func Test_testPlanRun(t *testing.T) {
type args struct {
ctx context.Context
c *apistructs.Component
scenario apistructs.ComponentProtocolScenario
event apistructs.ComponentEvent
globalStateData *apistructs.GlobalStateData
}
tests := []struct {
name string
args args
wantErr bool
}{
{
name: "test empty plan",
wantErr: false,
args: args{
c: &apistructs.Component{
Props: map[string]interface{}{
"fields": []apistructs.FormPropItem{},
},
},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
var contextBundle = protocol.ContextBundle{}
var bdl = &bundle.Bundle{}
patch1 := monkey.PatchInstanceMethod(reflect.TypeOf(bdl), "PagingTestPlansV2", func(bdl *bundle.Bundle, req apistructs.TestPlanV2PagingRequest) (*apistructs.TestPlanV2PagingResponseData, error) {
return &apistructs.TestPlanV2PagingResponseData{
Total: 0,
List: []*apistructs.TestPlanV2{},
}, nil
})
defer patch1.Unpatch()

patch2 := monkey.PatchInstanceMethod(reflect.TypeOf(bdl), "ListAutoTestGlobalConfig", func(bdl *bundle.Bundle, req apistructs.AutoTestGlobalConfigListRequest) ([]apistructs.AutoTestGlobalConfig, error) {
return []apistructs.AutoTestGlobalConfig{}, nil
})
defer patch2.Unpatch()

contextBundle.Bdl = bdl
contextBundle.InParams = map[string]interface{}{
"projectId": "1",
}

tt.args.ctx = context.WithValue(context.Background(), protocol.GlobalInnerKeyCtxBundle.String(), contextBundle)

if err := testPlanRun(tt.args.ctx, tt.args.c, tt.args.scenario, tt.args.event, tt.args.globalStateData); (err != nil) != tt.wantErr {
t.Errorf("testPlanRun() error = %v, wantErr %v", err, tt.wantErr)
}
})
}
}