|
| 1 | +/* |
| 2 | +Licensed to the Apache Software Foundation (ASF) under one or more |
| 3 | +contributor license agreements. See the NOTICE file distributed with |
| 4 | +this work for additional information regarding copyright ownership. |
| 5 | +The ASF licenses this file to You under the Apache License, Version 2.0 |
| 6 | +(the "License"); you may not use this file except in compliance with |
| 7 | +the License. You may obtain a copy of the License at |
| 8 | +
|
| 9 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +
|
| 11 | +Unless required by applicable law or agreed to in writing, software |
| 12 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | +See the License for the specific language governing permissions and |
| 15 | +limitations under the License. |
| 16 | +*/ |
| 17 | + |
| 18 | +package impl |
| 19 | + |
| 20 | +import ( |
| 21 | + "encoding/json" |
| 22 | + "testing" |
| 23 | + |
| 24 | + coreModels "github.com/apache/incubator-devlake/core/models" |
| 25 | + "github.com/stretchr/testify/assert" |
| 26 | +) |
| 27 | + |
| 28 | +func TestMakeMetricPluginPipelinePlanV200SkipsEmptyRegexp(t *testing.T) { |
| 29 | + var linker Linker |
| 30 | + |
| 31 | + plan, err := linker.MakeMetricPluginPipelinePlanV200("project", json.RawMessage(`{}`)) |
| 32 | + |
| 33 | + assert.Nil(t, err) |
| 34 | + assert.Nil(t, plan) |
| 35 | +} |
| 36 | + |
| 37 | +func TestMakeMetricPluginPipelinePlanV200BuildsPlan(t *testing.T) { |
| 38 | + var linker Linker |
| 39 | + options, err := json.Marshal(map[string]string{ |
| 40 | + "prToIssueRegexp": `#(\d+)`, |
| 41 | + }) |
| 42 | + assert.Nil(t, err) |
| 43 | + |
| 44 | + plan, err := linker.MakeMetricPluginPipelinePlanV200("project", options) |
| 45 | + |
| 46 | + assert.Nil(t, err) |
| 47 | + assert.Equal(t, coreModels.PipelinePlan{ |
| 48 | + { |
| 49 | + { |
| 50 | + Plugin: "linker", |
| 51 | + Options: map[string]interface{}{ |
| 52 | + "projectName": "project", |
| 53 | + "prToIssueRegexp": `#(\d+)`, |
| 54 | + }, |
| 55 | + Subtasks: []string{ |
| 56 | + "LinkPrToIssue", |
| 57 | + }, |
| 58 | + }, |
| 59 | + }, |
| 60 | + }, plan) |
| 61 | +} |
| 62 | + |
| 63 | +func TestPrepareTaskDataRejectsEmptyRegexp(t *testing.T) { |
| 64 | + var linker Linker |
| 65 | + |
| 66 | + taskData, err := linker.PrepareTaskData(nil, map[string]interface{}{ |
| 67 | + "projectName": "project", |
| 68 | + "prToIssueRegexp": "", |
| 69 | + }) |
| 70 | + |
| 71 | + assert.NotNil(t, err) |
| 72 | + assert.Nil(t, taskData) |
| 73 | +} |
0 commit comments