Skip to content

Commit

Permalink
bootstrap token is no longer set for automated testing
Browse files Browse the repository at this point in the history
  • Loading branch information
kakj-go committed Nov 10, 2021
1 parent d2121ba commit a2797b4
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 0 deletions.
3 changes: 3 additions & 0 deletions modules/pipeline/pipengine/reconciler/reconcile.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ func (r *Reconciler) reconcile(ctx context.Context, pipelineID uint64) error {
}
r.processingTasks.Delete(buildTaskDagName(p.ID, schedulableTasks[i].Name))
err = r.reconcile(ctx, pipelineID)
if err != nil {
logrus.Errorf("defer reconcile error %v", err)
}
wg.Done()
}()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,11 @@ func contextVolumes(context spec.PipelineTaskContext) []apistructs.MetadataField
}

func (pre *prepare) generateOpenapiTokenForPullBootstrapInfo(task *spec.PipelineTask) error {

if task.Type == apistructs.ActionTypeWait || task.Type == apistructs.ActionTypeAPITest || task.Type == apistructs.ActionTypeSnippet {
return nil
}

// 申请到的 token 只能请求 get-bootstrap-info api,并且保证 pipelineID 和 taskID 必须匹配
tokenInfo, err := pre.Bdl.GetOpenapiOAuth2Token(apistructs.OpenapiOAuth2TokenGetRequest{
ClientID: "pipeline",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// Copyright (c) 2021 Terminus, Inc.
//
// 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 taskop

import (
"testing"

"github.com/erda-project/erda/apistructs"
"github.com/erda-project/erda/modules/pipeline/spec"
)

func Test_prepare_generateOpenapiTokenForPullBootstrapInfo(t *testing.T) {
type args struct {
task *spec.PipelineTask
}
tests := []struct {
name string
pre prepare
args args
wantErr bool
}{
{
name: "test_api-test",
pre: prepare{},
args: args{
task: &spec.PipelineTask{
Type: apistructs.ActionTypeAPITest,
},
},
wantErr: false,
},
{
name: "test_wait",
pre: prepare{},
args: args{
task: &spec.PipelineTask{
Type: apistructs.ActionTypeWait,
},
},
wantErr: false,
},
{
name: "test_snippet",
pre: prepare{},
args: args{
task: &spec.PipelineTask{
Type: apistructs.ActionTypeSnippet,
},
},
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if err := tt.pre.generateOpenapiTokenForPullBootstrapInfo(tt.args.task); (err != nil) != tt.wantErr {
t.Errorf("generateOpenapiTokenForPullBootstrapInfo() error = %v, wantErr %v", err, tt.wantErr)
}
})
}
}

0 comments on commit a2797b4

Please sign in to comment.