This is an automated email from the ASF dual-hosted git repository.

abeizn pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git


The following commit(s) were added to refs/heads/main by this push:
     new 7654fa9fa test(gitextractor): add missing gitextractor plugins in 
github/gitlab's pipeline when there is no scope config (#7914)
7654fa9fa is described below

commit 7654fa9fa4421e3ac0f11906af088a8a6c9299d3
Author: Lynwee <[email protected]>
AuthorDate: Mon Aug 19 15:56:39 2024 +0800

    test(gitextractor): add missing gitextractor plugins in github/gitlab's 
pipeline when there is no scope config (#7914)
---
 backend/plugins/github/api/blueprint_v200_test.go | 95 +++++++++++++++++++++++
 backend/plugins/gitlab/api/blueprint_V200_test.go | 62 +++++++++++++++
 2 files changed, 157 insertions(+)

diff --git a/backend/plugins/github/api/blueprint_v200_test.go 
b/backend/plugins/github/api/blueprint_v200_test.go
new file mode 100644
index 000000000..ad56aea62
--- /dev/null
+++ b/backend/plugins/github/api/blueprint_v200_test.go
@@ -0,0 +1,95 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You 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 api
+
+import (
+       "github.com/apache/incubator-devlake/core/models/common"
+       "github.com/apache/incubator-devlake/core/plugin"
+       "github.com/apache/incubator-devlake/helpers/pluginhelper/api"
+       "github.com/apache/incubator-devlake/helpers/srvhelper"
+       mockplugin "github.com/apache/incubator-devlake/mocks/core/plugin"
+       "github.com/apache/incubator-devlake/plugins/github/models"
+       "github.com/stretchr/testify/assert"
+       "testing"
+)
+
+func Test_makeDataSourcePipelinePlanV200_with_empty_scope_config(t *testing.T) 
{
+
+       mockMeta := mockplugin.NewPluginMeta(t)
+       
mockMeta.On("RootPkgPath").Return("github.com/apache/incubator-devlake/plugins/github")
+       mockMeta.On("Name").Return("github").Maybe()
+       err := plugin.RegisterPlugin("github", mockMeta)
+       assert.Nil(t, err)
+
+       type args struct {
+               subtaskMetas []plugin.SubTaskMeta
+               scopeDetails []*srvhelper.ScopeDetail[models.GithubRepo, 
models.GithubScopeConfig]
+               connection   *models.GithubConnection
+       }
+       tests := []struct {
+               name                      string
+               args                      args
+               makeSureGitExtractorExist bool
+               wantError                 bool
+       }{
+               {
+                       name: "without-empty-scope-config",
+                       args: args{
+                               subtaskMetas: []plugin.SubTaskMeta{},
+                               scopeDetails: 
[]*srvhelper.ScopeDetail[models.GithubRepo, models.GithubScopeConfig]{
+                                       
&srvhelper.ScopeDetail[models.GithubRepo, models.GithubScopeConfig]{
+                                               Scope:       
models.GithubRepo{},
+                                               ScopeConfig: 
&models.GithubScopeConfig{},
+                                       },
+                               },
+                               connection: &models.GithubConnection{
+                                       BaseConnection: api.BaseConnection{
+                                               Model: common.Model{
+                                                       ID: 1,
+                                               },
+                                       },
+                                       GithubConn:    models.GithubConn{},
+                                       EnableGraphql: false,
+                               },
+                       },
+                       makeSureGitExtractorExist: true,
+                       wantError:                 false,
+               },
+       }
+       for _, tt := range tests {
+               t.Run(tt.name, func(t *testing.T) {
+                       got, got1 := 
makeDataSourcePipelinePlanV200(tt.args.subtaskMetas, tt.args.scopeDetails, 
tt.args.connection)
+                       if tt.wantError {
+                               assert.Equalf(t, nil, got1, 
"makeDataSourcePipelinePlanV200 want error(%v, %v, %v)", tt.args.subtaskMetas, 
tt.args.scopeDetails, tt.args.connection)
+                       }
+                       if tt.makeSureGitExtractorExist {
+                               var existGitExtractor bool
+                               for _, g := range got {
+                                       for _, v := range g {
+                                               if v.Plugin == "gitextractor" {
+                                                       existGitExtractor = true
+                                               }
+                                       }
+                               }
+                               if !existGitExtractor {
+                                       t.Fatal("gitextractor not found")
+                               }
+                       }
+               })
+       }
+}
diff --git a/backend/plugins/gitlab/api/blueprint_V200_test.go 
b/backend/plugins/gitlab/api/blueprint_V200_test.go
index 36b628e5d..b4a345fa4 100644
--- a/backend/plugins/gitlab/api/blueprint_V200_test.go
+++ b/backend/plugins/gitlab/api/blueprint_V200_test.go
@@ -183,3 +183,65 @@ func TestMakeDataSourcePipelinePlanV200(t *testing.T) {
 
        assert.Equal(t, expectPlans, actualPlans)
 }
+
+func Test_makePipelinePlanV200_with_empty_scope_config(t *testing.T) {
+
+       mockGitlabPlugin(t)
+
+       type args struct {
+               subtaskMetas []plugin.SubTaskMeta
+               connection   *models.GitlabConnection
+               scopeDetails []*srvhelper.ScopeDetail[models.GitlabProject, 
models.GitlabScopeConfig]
+       }
+
+       tests := []struct {
+               name                      string
+               args                      args
+               makeSureGitExtractorExist bool
+               wantError                 bool
+       }{
+               {
+                       name: "without-empty-scope-config",
+                       args: args{
+                               subtaskMetas: []plugin.SubTaskMeta{},
+                               scopeDetails: 
[]*srvhelper.ScopeDetail[models.GitlabProject, models.GitlabScopeConfig]{
+                                       
&srvhelper.ScopeDetail[models.GitlabProject, models.GitlabScopeConfig]{
+                                               Scope:       
models.GitlabProject{},
+                                               ScopeConfig: 
&models.GitlabScopeConfig{},
+                                       },
+                               },
+                               connection: &models.GitlabConnection{
+                                       BaseConnection: api.BaseConnection{
+                                               Model: common.Model{
+                                                       ID: 1,
+                                               },
+                                       },
+                                       GitlabConn: models.GitlabConn{},
+                               },
+                       },
+                       makeSureGitExtractorExist: true,
+                       wantError:                 false,
+               },
+       }
+       for _, tt := range tests {
+               t.Run(tt.name, func(t *testing.T) {
+                       got, got1 := makePipelinePlanV200(tt.args.subtaskMetas, 
tt.args.connection, tt.args.scopeDetails)
+                       if tt.wantError {
+                               assert.Equalf(t, nil, got1, 
"makePipelinePlanV200 want error(%v, %v, %v)", tt.args.subtaskMetas, 
tt.args.scopeDetails, tt.args.connection)
+                       }
+                       if tt.makeSureGitExtractorExist {
+                               var existGitExtractor bool
+                               for _, g := range got {
+                                       for _, v := range g {
+                                               if v.Plugin == "gitextractor" {
+                                                       existGitExtractor = true
+                                               }
+                                       }
+                               }
+                               if !existGitExtractor {
+                                       t.Fatal("gitextractor not found")
+                               }
+                       }
+               })
+       }
+}

Reply via email to