2019-02-21 14:54:50 +00:00
|
|
|
// Copyright 2019 Sorint.lab
|
|
|
|
//
|
|
|
|
// 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 runconfig
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"reflect"
|
|
|
|
"testing"
|
|
|
|
|
2019-07-01 09:40:20 +00:00
|
|
|
"agola.io/agola/internal/config"
|
|
|
|
"agola.io/agola/internal/util"
|
2019-07-31 13:39:07 +00:00
|
|
|
rstypes "agola.io/agola/services/runservice/types"
|
2019-09-05 07:29:20 +00:00
|
|
|
"agola.io/agola/services/types"
|
2019-10-08 13:52:35 +00:00
|
|
|
"k8s.io/apimachinery/pkg/api/resource"
|
2019-06-08 14:07:15 +00:00
|
|
|
|
|
|
|
"github.com/google/go-cmp/cmp"
|
2019-05-23 09:23:14 +00:00
|
|
|
errors "golang.org/x/xerrors"
|
2019-02-21 14:54:50 +00:00
|
|
|
)
|
|
|
|
|
2019-03-18 14:02:32 +00:00
|
|
|
var uuid = &util.TestUUIDGenerator{}
|
|
|
|
|
2019-02-21 14:54:50 +00:00
|
|
|
func TestGenTasksLevels(t *testing.T) {
|
|
|
|
type task struct {
|
|
|
|
ID string
|
|
|
|
Level int
|
2019-04-12 15:04:07 +00:00
|
|
|
Depends map[string]*rstypes.RunConfigTaskDepend
|
2019-02-21 14:54:50 +00:00
|
|
|
}
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
in []task
|
|
|
|
out []task
|
|
|
|
err error
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "test single task",
|
|
|
|
in: []task{
|
|
|
|
{
|
|
|
|
ID: "1",
|
|
|
|
Level: -1,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
out: []task{
|
|
|
|
{
|
|
|
|
ID: "1",
|
|
|
|
Level: 0,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "test multiple root tasks",
|
|
|
|
in: []task{
|
|
|
|
{
|
|
|
|
ID: "1",
|
|
|
|
Level: -1,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ID: "2",
|
|
|
|
Level: -1,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
out: []task{
|
|
|
|
{
|
|
|
|
ID: "1",
|
|
|
|
Level: 0,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ID: "2",
|
|
|
|
Level: 0,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "test dependency between two tasks",
|
|
|
|
in: []task{
|
|
|
|
{
|
|
|
|
ID: "1",
|
|
|
|
Level: -1,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ID: "2",
|
|
|
|
Level: -1,
|
2019-04-12 15:04:07 +00:00
|
|
|
Depends: map[string]*rstypes.RunConfigTaskDepend{
|
|
|
|
"1": &rstypes.RunConfigTaskDepend{TaskID: "1"},
|
2019-02-21 14:54:50 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
out: []task{
|
|
|
|
{
|
|
|
|
ID: "1",
|
|
|
|
Level: 0,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ID: "2",
|
|
|
|
Level: 1,
|
2019-04-12 15:04:07 +00:00
|
|
|
Depends: map[string]*rstypes.RunConfigTaskDepend{
|
|
|
|
"1": &rstypes.RunConfigTaskDepend{TaskID: "1"},
|
2019-02-21 14:54:50 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "Test circular dependency between two tasks: a -> b -> a",
|
|
|
|
in: []task{
|
|
|
|
{
|
|
|
|
ID: "1",
|
|
|
|
Level: -1,
|
2019-04-12 15:04:07 +00:00
|
|
|
Depends: map[string]*rstypes.RunConfigTaskDepend{
|
|
|
|
"2": &rstypes.RunConfigTaskDepend{TaskID: "2"},
|
2019-02-21 14:54:50 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ID: "2",
|
|
|
|
Level: -1,
|
2019-04-12 15:04:07 +00:00
|
|
|
Depends: map[string]*rstypes.RunConfigTaskDepend{
|
|
|
|
"1": &rstypes.RunConfigTaskDepend{TaskID: "1"},
|
2019-02-21 14:54:50 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
err: fmt.Errorf("circular dependency detected"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "Test circular dependency between 3 tasks: a -> b -> c -> a",
|
|
|
|
in: []task{
|
|
|
|
{
|
|
|
|
ID: "1",
|
|
|
|
Level: -1,
|
2019-04-12 15:04:07 +00:00
|
|
|
Depends: map[string]*rstypes.RunConfigTaskDepend{
|
|
|
|
"2": &rstypes.RunConfigTaskDepend{TaskID: "2"},
|
2019-02-21 14:54:50 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ID: "2",
|
|
|
|
Level: -1,
|
2019-04-12 15:04:07 +00:00
|
|
|
Depends: map[string]*rstypes.RunConfigTaskDepend{
|
|
|
|
"3": &rstypes.RunConfigTaskDepend{TaskID: "3"},
|
2019-02-21 14:54:50 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ID: "3",
|
|
|
|
Level: -1,
|
2019-04-12 15:04:07 +00:00
|
|
|
Depends: map[string]*rstypes.RunConfigTaskDepend{
|
|
|
|
"1": &rstypes.RunConfigTaskDepend{TaskID: "1"},
|
2019-02-21 14:54:50 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
err: fmt.Errorf("circular dependency detected"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "Test circular dependency between 3 tasks: a -> b -> c -> b",
|
|
|
|
in: []task{
|
|
|
|
{
|
|
|
|
ID: "1",
|
|
|
|
Level: -1,
|
2019-04-12 15:04:07 +00:00
|
|
|
Depends: map[string]*rstypes.RunConfigTaskDepend{
|
|
|
|
"2": &rstypes.RunConfigTaskDepend{TaskID: "2"},
|
2019-02-21 14:54:50 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ID: "2",
|
|
|
|
Level: -1,
|
2019-04-12 15:04:07 +00:00
|
|
|
Depends: map[string]*rstypes.RunConfigTaskDepend{
|
|
|
|
"3": &rstypes.RunConfigTaskDepend{TaskID: "3"},
|
2019-02-21 14:54:50 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ID: "3",
|
|
|
|
Level: -1,
|
2019-04-12 15:04:07 +00:00
|
|
|
Depends: map[string]*rstypes.RunConfigTaskDepend{
|
|
|
|
"2": &rstypes.RunConfigTaskDepend{TaskID: "2"},
|
2019-02-21 14:54:50 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
err: fmt.Errorf("circular dependency detected"),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
2019-04-09 16:11:00 +00:00
|
|
|
inRcts := map[string]*rstypes.RunConfigTask{}
|
2019-02-21 14:54:50 +00:00
|
|
|
for _, t := range tt.in {
|
2019-04-09 16:11:00 +00:00
|
|
|
inRcts[t.ID] = &rstypes.RunConfigTask{
|
2019-02-21 14:54:50 +00:00
|
|
|
ID: t.ID,
|
|
|
|
Level: t.Level,
|
|
|
|
Depends: t.Depends,
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2019-04-09 16:11:00 +00:00
|
|
|
outRcts := map[string]*rstypes.RunConfigTask{}
|
2019-02-21 14:54:50 +00:00
|
|
|
for _, t := range tt.out {
|
2019-04-09 16:11:00 +00:00
|
|
|
outRcts[t.ID] = &rstypes.RunConfigTask{
|
2019-02-21 14:54:50 +00:00
|
|
|
ID: t.ID,
|
|
|
|
Level: t.Level,
|
|
|
|
Depends: t.Depends,
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2019-04-09 16:11:00 +00:00
|
|
|
if err := GenTasksLevels(inRcts); err != nil {
|
2019-02-21 14:54:50 +00:00
|
|
|
if err.Error() != tt.err.Error() {
|
|
|
|
t.Fatalf("got error: %v, want error: %v", err, tt.err)
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if tt.err != nil {
|
|
|
|
t.Fatalf("got nil error, want error: %v", tt.err)
|
|
|
|
}
|
2019-04-09 16:11:00 +00:00
|
|
|
if !reflect.DeepEqual(inRcts, outRcts) {
|
|
|
|
t.Fatalf("got %s, expected %s", util.Dump(inRcts), util.Dump(outRcts))
|
2019-02-21 14:54:50 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestGetAllParents(t *testing.T) {
|
|
|
|
type task struct {
|
|
|
|
ID string
|
|
|
|
Level int
|
2019-04-12 15:04:07 +00:00
|
|
|
Depends map[string]*rstypes.RunConfigTaskDepend
|
2019-02-21 14:54:50 +00:00
|
|
|
}
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
in []task
|
|
|
|
out map[string][]string
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "test single task",
|
|
|
|
in: []task{
|
|
|
|
{
|
|
|
|
ID: "1",
|
|
|
|
Level: -1,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
out: map[string][]string{
|
|
|
|
"1": []string{},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "test multiple root tasks",
|
|
|
|
in: []task{
|
|
|
|
{
|
|
|
|
ID: "1",
|
|
|
|
Level: -1,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ID: "2",
|
|
|
|
Level: -1,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
out: map[string][]string{
|
|
|
|
"1": []string{},
|
|
|
|
"2": []string{},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "test dependency from a task to itself",
|
|
|
|
in: []task{
|
|
|
|
{
|
|
|
|
ID: "1",
|
|
|
|
Level: -1,
|
2019-04-12 15:04:07 +00:00
|
|
|
Depends: map[string]*rstypes.RunConfigTaskDepend{
|
|
|
|
"1": &rstypes.RunConfigTaskDepend{TaskID: "1"},
|
2019-02-21 14:54:50 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
out: map[string][]string{
|
|
|
|
"1": []string{"1"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "test dependency between two tasks",
|
|
|
|
in: []task{
|
|
|
|
{
|
|
|
|
ID: "1",
|
|
|
|
Level: -1,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ID: "2",
|
|
|
|
Level: -1,
|
2019-04-12 15:04:07 +00:00
|
|
|
Depends: map[string]*rstypes.RunConfigTaskDepend{
|
|
|
|
"1": &rstypes.RunConfigTaskDepend{TaskID: "1"},
|
2019-02-21 14:54:50 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
out: map[string][]string{
|
|
|
|
"1": []string{},
|
|
|
|
"2": []string{"1"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "Test dependency between 5 tasks: a -> (b, c) -> (d, e)",
|
|
|
|
in: []task{
|
|
|
|
{
|
|
|
|
ID: "1",
|
|
|
|
Level: -1,
|
2019-04-12 15:04:07 +00:00
|
|
|
Depends: map[string]*rstypes.RunConfigTaskDepend{
|
|
|
|
"2": &rstypes.RunConfigTaskDepend{TaskID: "2"},
|
|
|
|
"3": &rstypes.RunConfigTaskDepend{TaskID: "3"},
|
2019-02-21 14:54:50 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ID: "2",
|
|
|
|
Level: -1,
|
2019-04-12 15:04:07 +00:00
|
|
|
Depends: map[string]*rstypes.RunConfigTaskDepend{
|
|
|
|
"4": &rstypes.RunConfigTaskDepend{TaskID: "4"},
|
2019-02-21 14:54:50 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ID: "3",
|
|
|
|
Level: -1,
|
2019-04-12 15:04:07 +00:00
|
|
|
Depends: map[string]*rstypes.RunConfigTaskDepend{
|
|
|
|
"5": &rstypes.RunConfigTaskDepend{TaskID: "5"},
|
2019-02-21 14:54:50 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ID: "4",
|
|
|
|
Level: -1,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ID: "5",
|
|
|
|
Level: -1,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
out: map[string][]string{
|
|
|
|
"1": []string{"2", "3", "4", "5"},
|
|
|
|
"2": []string{"4"},
|
|
|
|
"3": []string{"5"},
|
|
|
|
"4": []string{},
|
|
|
|
"5": []string{},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "Test circular dependency between two tasks: a -> b -> a",
|
|
|
|
in: []task{
|
|
|
|
{
|
|
|
|
ID: "1",
|
|
|
|
Level: -1,
|
2019-04-12 15:04:07 +00:00
|
|
|
Depends: map[string]*rstypes.RunConfigTaskDepend{
|
|
|
|
"2": &rstypes.RunConfigTaskDepend{TaskID: "2"},
|
2019-02-21 14:54:50 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ID: "2",
|
|
|
|
Level: -1,
|
2019-04-12 15:04:07 +00:00
|
|
|
Depends: map[string]*rstypes.RunConfigTaskDepend{
|
|
|
|
"1": &rstypes.RunConfigTaskDepend{TaskID: "1"},
|
2019-02-21 14:54:50 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
out: map[string][]string{
|
|
|
|
"1": []string{"2", "1"},
|
|
|
|
"2": []string{"1", "2"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "Test circular dependency between 3 tasks: a -> b -> c -> a",
|
|
|
|
in: []task{
|
|
|
|
{
|
|
|
|
ID: "1",
|
|
|
|
Level: -1,
|
2019-04-12 15:04:07 +00:00
|
|
|
Depends: map[string]*rstypes.RunConfigTaskDepend{
|
|
|
|
"2": &rstypes.RunConfigTaskDepend{TaskID: "2"},
|
2019-02-21 14:54:50 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ID: "2",
|
|
|
|
Level: -1,
|
2019-04-12 15:04:07 +00:00
|
|
|
Depends: map[string]*rstypes.RunConfigTaskDepend{
|
|
|
|
"3": &rstypes.RunConfigTaskDepend{TaskID: "3"},
|
2019-02-21 14:54:50 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ID: "3",
|
|
|
|
Level: -1,
|
2019-04-12 15:04:07 +00:00
|
|
|
Depends: map[string]*rstypes.RunConfigTaskDepend{
|
|
|
|
"1": &rstypes.RunConfigTaskDepend{TaskID: "1"},
|
2019-02-21 14:54:50 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
out: map[string][]string{
|
|
|
|
"1": []string{"2", "3", "1"},
|
|
|
|
"2": []string{"3", "1", "2"},
|
|
|
|
"3": []string{"1", "2", "3"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "Test circular dependency between 3 tasks: a -> b -> c -> b",
|
|
|
|
in: []task{
|
|
|
|
{
|
|
|
|
ID: "1",
|
|
|
|
Level: -1,
|
2019-04-12 15:04:07 +00:00
|
|
|
Depends: map[string]*rstypes.RunConfigTaskDepend{
|
|
|
|
"2": &rstypes.RunConfigTaskDepend{TaskID: "2"},
|
2019-02-21 14:54:50 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ID: "2",
|
|
|
|
Level: -1,
|
2019-04-12 15:04:07 +00:00
|
|
|
Depends: map[string]*rstypes.RunConfigTaskDepend{
|
|
|
|
"3": &rstypes.RunConfigTaskDepend{TaskID: "3"},
|
2019-02-21 14:54:50 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ID: "3",
|
|
|
|
Level: -1,
|
2019-04-12 15:04:07 +00:00
|
|
|
Depends: map[string]*rstypes.RunConfigTaskDepend{
|
|
|
|
"2": &rstypes.RunConfigTaskDepend{TaskID: "2"},
|
2019-02-21 14:54:50 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
out: map[string][]string{
|
|
|
|
"1": []string{"2", "3"},
|
|
|
|
"2": []string{"3", "2"},
|
|
|
|
"3": []string{"2", "3"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
2019-04-09 16:11:00 +00:00
|
|
|
inRcts := map[string]*rstypes.RunConfigTask{}
|
2019-02-21 14:54:50 +00:00
|
|
|
for _, t := range tt.in {
|
2019-04-09 16:11:00 +00:00
|
|
|
inRcts[t.ID] = &rstypes.RunConfigTask{
|
2019-02-21 14:54:50 +00:00
|
|
|
ID: t.ID,
|
|
|
|
Level: t.Level,
|
|
|
|
Depends: t.Depends,
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-04-09 16:11:00 +00:00
|
|
|
for _, task := range inRcts {
|
|
|
|
allParents := GetAllParents(inRcts, task)
|
2019-02-21 14:54:50 +00:00
|
|
|
|
|
|
|
allParentsList := []string{}
|
|
|
|
for _, p := range allParents {
|
|
|
|
allParentsList = append(allParentsList, p.ID)
|
|
|
|
}
|
|
|
|
if !util.CompareStringSliceNoOrder(tt.out[task.ID], allParentsList) {
|
|
|
|
t.Fatalf("task: %s, got %s, expected %s", task.ID, util.Dump(allParentsList), util.Dump(tt.out[task.ID]))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCheckRunConfig(t *testing.T) {
|
|
|
|
type task struct {
|
|
|
|
ID string
|
|
|
|
Level int
|
2019-04-12 15:04:07 +00:00
|
|
|
Depends map[string]*rstypes.RunConfigTaskDepend
|
2019-02-21 14:54:50 +00:00
|
|
|
}
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
in []task
|
|
|
|
err error
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "test single task",
|
|
|
|
in: []task{
|
|
|
|
{
|
|
|
|
ID: "1",
|
|
|
|
Level: -1,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "test multiple root tasks",
|
|
|
|
in: []task{
|
|
|
|
{
|
|
|
|
ID: "1",
|
|
|
|
Level: -1,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ID: "2",
|
|
|
|
Level: -1,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "test dependency between two tasks",
|
|
|
|
in: []task{
|
|
|
|
{
|
|
|
|
ID: "1",
|
|
|
|
Level: -1,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ID: "2",
|
|
|
|
Level: -1,
|
2019-04-12 15:04:07 +00:00
|
|
|
Depends: map[string]*rstypes.RunConfigTaskDepend{
|
|
|
|
"1": &rstypes.RunConfigTaskDepend{TaskID: "1"},
|
2019-02-21 14:54:50 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "Test circular dependency between two tasks: a -> b -> a",
|
|
|
|
in: []task{
|
|
|
|
{
|
|
|
|
ID: "1",
|
|
|
|
Level: -1,
|
2019-04-12 15:04:07 +00:00
|
|
|
Depends: map[string]*rstypes.RunConfigTaskDepend{
|
|
|
|
"2": &rstypes.RunConfigTaskDepend{TaskID: "2"},
|
2019-02-21 14:54:50 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ID: "2",
|
|
|
|
Level: -1,
|
2019-04-12 15:04:07 +00:00
|
|
|
Depends: map[string]*rstypes.RunConfigTaskDepend{
|
|
|
|
"1": &rstypes.RunConfigTaskDepend{TaskID: "1"},
|
2019-02-21 14:54:50 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
err: &util.Errors{
|
|
|
|
Errs: []error{
|
|
|
|
errors.Errorf("circular dependency between task %q and tasks %q", "task1", "task2"),
|
|
|
|
errors.Errorf("circular dependency between task %q and tasks %q", "task2", "task1"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "Test circular dependency between 3 tasks: a -> b -> c -> a",
|
|
|
|
in: []task{
|
|
|
|
{
|
|
|
|
ID: "1",
|
|
|
|
Level: -1,
|
2019-04-12 15:04:07 +00:00
|
|
|
Depends: map[string]*rstypes.RunConfigTaskDepend{
|
|
|
|
"2": &rstypes.RunConfigTaskDepend{TaskID: "2"},
|
2019-02-21 14:54:50 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ID: "2",
|
|
|
|
Level: -1,
|
2019-04-12 15:04:07 +00:00
|
|
|
Depends: map[string]*rstypes.RunConfigTaskDepend{
|
|
|
|
"3": &rstypes.RunConfigTaskDepend{TaskID: "3"},
|
2019-02-21 14:54:50 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ID: "3",
|
|
|
|
Level: -1,
|
2019-04-12 15:04:07 +00:00
|
|
|
Depends: map[string]*rstypes.RunConfigTaskDepend{
|
|
|
|
"1": &rstypes.RunConfigTaskDepend{TaskID: "1"},
|
2019-02-21 14:54:50 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
err: &util.Errors{
|
|
|
|
Errs: []error{
|
|
|
|
errors.Errorf("circular dependency between task %q and tasks %q", "task1", "task3"),
|
|
|
|
errors.Errorf("circular dependency between task %q and tasks %q", "task2", "task1"),
|
|
|
|
errors.Errorf("circular dependency between task %q and tasks %q", "task3", "task2"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "Test circular dependency between 3 tasks: a -> b -> c -> b",
|
|
|
|
in: []task{
|
|
|
|
{
|
|
|
|
ID: "1",
|
|
|
|
Level: -1,
|
2019-04-12 15:04:07 +00:00
|
|
|
Depends: map[string]*rstypes.RunConfigTaskDepend{
|
|
|
|
"2": &rstypes.RunConfigTaskDepend{TaskID: "2"},
|
2019-02-21 14:54:50 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ID: "2",
|
|
|
|
Level: -1,
|
2019-04-12 15:04:07 +00:00
|
|
|
Depends: map[string]*rstypes.RunConfigTaskDepend{
|
|
|
|
"3": &rstypes.RunConfigTaskDepend{TaskID: "3"},
|
2019-02-21 14:54:50 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ID: "3",
|
|
|
|
Level: -1,
|
2019-04-12 15:04:07 +00:00
|
|
|
Depends: map[string]*rstypes.RunConfigTaskDepend{
|
|
|
|
"2": &rstypes.RunConfigTaskDepend{TaskID: "2"},
|
2019-02-21 14:54:50 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
err: &util.Errors{
|
|
|
|
Errs: []error{
|
|
|
|
errors.Errorf("circular dependency between task %q and tasks %q", "task2", "task3"),
|
|
|
|
errors.Errorf("circular dependency between task %q and tasks %q", "task3", "task2"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2019-08-12 21:11:19 +00:00
|
|
|
{
|
|
|
|
name: "test task parent same dep a -> b -> c, a -> c",
|
|
|
|
in: []task{
|
|
|
|
{
|
|
|
|
ID: "1",
|
|
|
|
Level: -1,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ID: "2",
|
|
|
|
Level: -1,
|
|
|
|
Depends: map[string]*rstypes.RunConfigTaskDepend{
|
|
|
|
"1": &rstypes.RunConfigTaskDepend{TaskID: "1"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ID: "3",
|
|
|
|
Level: -1,
|
|
|
|
Depends: map[string]*rstypes.RunConfigTaskDepend{
|
|
|
|
"2": &rstypes.RunConfigTaskDepend{TaskID: "2"},
|
|
|
|
"1": &rstypes.RunConfigTaskDepend{TaskID: "1"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
err: errors.Errorf("task %q and its parent %q have both a dependency on task %q", "task3", "task2", "task1"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "test task parent same dep a -> b -> c -> d, a -> d",
|
|
|
|
in: []task{
|
|
|
|
{
|
|
|
|
ID: "1",
|
|
|
|
Level: -1,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ID: "2",
|
|
|
|
Level: -1,
|
|
|
|
Depends: map[string]*rstypes.RunConfigTaskDepend{
|
|
|
|
"1": &rstypes.RunConfigTaskDepend{TaskID: "1"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ID: "3",
|
|
|
|
Level: -1,
|
|
|
|
Depends: map[string]*rstypes.RunConfigTaskDepend{
|
|
|
|
"2": &rstypes.RunConfigTaskDepend{TaskID: "2"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ID: "4",
|
|
|
|
Level: -1,
|
|
|
|
Depends: map[string]*rstypes.RunConfigTaskDepend{
|
|
|
|
"3": &rstypes.RunConfigTaskDepend{TaskID: "3"},
|
|
|
|
"1": &rstypes.RunConfigTaskDepend{TaskID: "1"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
err: errors.Errorf("task %q and its parent %q have both a dependency on task %q", "task4", "task3", "task1"),
|
|
|
|
},
|
2019-02-21 14:54:50 +00:00
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
2019-04-09 16:11:00 +00:00
|
|
|
inRcts := map[string]*rstypes.RunConfigTask{}
|
2019-02-21 14:54:50 +00:00
|
|
|
for _, t := range tt.in {
|
2019-04-09 16:11:00 +00:00
|
|
|
inRcts[t.ID] = &rstypes.RunConfigTask{
|
2019-02-21 14:54:50 +00:00
|
|
|
Name: fmt.Sprintf("task%s", t.ID),
|
|
|
|
ID: t.ID,
|
|
|
|
Level: t.Level,
|
|
|
|
Depends: t.Depends,
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-04-09 16:11:00 +00:00
|
|
|
if err := CheckRunConfigTasks(inRcts); err != nil {
|
2019-02-21 14:54:50 +00:00
|
|
|
if errs, ok := err.(*util.Errors); ok {
|
|
|
|
if !errs.Equal(tt.err) {
|
|
|
|
t.Fatalf("got error: %v, want error: %v", err, tt.err)
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if err.Error() != tt.err.Error() {
|
|
|
|
t.Fatalf("got error: %v, want error: %v", err, tt.err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if tt.err != nil {
|
|
|
|
t.Fatalf("got nil error, want error: %v", tt.err)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
2019-03-18 14:02:32 +00:00
|
|
|
|
|
|
|
func TestGenRunConfig(t *testing.T) {
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
in *config.Config
|
|
|
|
variables map[string]string
|
2019-04-09 16:11:00 +00:00
|
|
|
out map[string]*rstypes.RunConfigTask
|
2019-03-18 14:02:32 +00:00
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "test runconfig generation",
|
|
|
|
in: &config.Config{
|
2019-04-16 09:01:02 +00:00
|
|
|
Runs: []*config.Run{
|
|
|
|
&config.Run{
|
|
|
|
Name: "run01",
|
2019-04-22 12:38:25 +00:00
|
|
|
DockerRegistriesAuth: map[string]*config.DockerRegistryAuth{
|
|
|
|
"index.docker.io": {
|
|
|
|
Type: config.DockerRegistryAuthTypeBasic,
|
|
|
|
Username: config.Value{Type: config.ValueTypeString, Value: "username"},
|
|
|
|
Password: config.Value{Type: config.ValueTypeFromVariable, Value: "password"},
|
|
|
|
},
|
|
|
|
},
|
2019-04-16 09:01:02 +00:00
|
|
|
Tasks: []*config.Task{
|
|
|
|
&config.Task{
|
|
|
|
Name: "task01",
|
2019-04-22 12:38:25 +00:00
|
|
|
DockerRegistriesAuth: map[string]*config.DockerRegistryAuth{
|
|
|
|
"index.docker.io": {
|
|
|
|
Type: config.DockerRegistryAuthTypeBasic,
|
|
|
|
Username: config.Value{Type: config.ValueTypeFromVariable, Value: "registry_username"},
|
|
|
|
Password: config.Value{Type: config.ValueTypeString, Value: "password2"},
|
|
|
|
},
|
|
|
|
},
|
2019-04-16 09:01:02 +00:00
|
|
|
Runtime: &config.Runtime{
|
|
|
|
Type: "pod",
|
|
|
|
Arch: "",
|
|
|
|
Containers: []*config.Container{
|
|
|
|
&config.Container{
|
|
|
|
Image: "image01",
|
|
|
|
Environment: map[string]config.Value{
|
|
|
|
"ENV01": config.Value{Type: config.ValueTypeString, Value: "ENV01"},
|
|
|
|
"ENVFROMVARIABLE01": config.Value{Type: config.ValueTypeFromVariable, Value: "variable01"},
|
|
|
|
},
|
|
|
|
User: "",
|
2019-10-08 13:52:35 +00:00
|
|
|
Volumes: []config.Volume{
|
|
|
|
config.Volume{
|
|
|
|
Path: "/mnt/vol01",
|
|
|
|
TmpFS: &config.VolumeTmpFS{},
|
|
|
|
},
|
|
|
|
config.Volume{
|
|
|
|
Path: "/mnt/vol01",
|
|
|
|
TmpFS: &config.VolumeTmpFS{Size: resource.NewQuantity(1024*1024*1024, resource.BinarySI)},
|
|
|
|
},
|
|
|
|
},
|
2019-04-16 09:01:02 +00:00
|
|
|
},
|
|
|
|
},
|
2019-04-10 15:13:51 +00:00
|
|
|
},
|
|
|
|
Environment: map[string]config.Value{
|
|
|
|
"ENV01": config.Value{Type: config.ValueTypeString, Value: "ENV01"},
|
|
|
|
"ENVFROMVARIABLE01": config.Value{Type: config.ValueTypeFromVariable, Value: "variable01"},
|
2019-03-18 14:02:32 +00:00
|
|
|
},
|
2019-04-16 09:01:02 +00:00
|
|
|
WorkingDir: "",
|
|
|
|
Shell: "",
|
|
|
|
User: "",
|
2019-06-08 14:07:15 +00:00
|
|
|
Steps: config.Steps{
|
2019-04-16 09:01:02 +00:00
|
|
|
&config.RunStep{
|
2019-06-08 14:07:15 +00:00
|
|
|
BaseStep: config.BaseStep{
|
2019-04-16 09:01:02 +00:00
|
|
|
Type: "run",
|
|
|
|
Name: "command01",
|
|
|
|
},
|
|
|
|
Command: "command01",
|
|
|
|
},
|
|
|
|
&config.RunStep{
|
2019-06-08 14:07:15 +00:00
|
|
|
BaseStep: config.BaseStep{
|
2019-04-16 09:01:02 +00:00
|
|
|
Type: "run",
|
|
|
|
Name: "name different than command",
|
|
|
|
},
|
|
|
|
Command: "command02",
|
|
|
|
},
|
|
|
|
&config.RunStep{
|
2019-06-08 14:07:15 +00:00
|
|
|
BaseStep: config.BaseStep{
|
2019-04-16 09:01:02 +00:00
|
|
|
Type: "run",
|
|
|
|
Name: "command03",
|
|
|
|
},
|
|
|
|
Command: "command03",
|
|
|
|
Environment: map[string]config.Value{
|
|
|
|
"ENV01": config.Value{Type: config.ValueTypeString, Value: "ENV01"},
|
|
|
|
"ENVFROMVARIABLE01": config.Value{Type: config.ValueTypeFromVariable, Value: "variable01"},
|
|
|
|
},
|
|
|
|
},
|
2019-03-18 14:02:32 +00:00
|
|
|
},
|
2019-04-16 09:01:02 +00:00
|
|
|
|
2019-03-18 14:02:32 +00:00
|
|
|
Depends: []*config.Depend{},
|
|
|
|
IgnoreFailure: false,
|
|
|
|
Approval: false,
|
2019-06-08 14:07:15 +00:00
|
|
|
When: &config.When{
|
2019-09-05 07:29:20 +00:00
|
|
|
Branch: &types.WhenConditions{Include: []types.WhenCondition{{Match: "master"}}},
|
|
|
|
Tag: &types.WhenConditions{Include: []types.WhenCondition{{Match: "v1.x"}, {Match: "v2.x"}}},
|
|
|
|
Ref: &types.WhenConditions{
|
|
|
|
Include: []types.WhenCondition{{Match: "master"}},
|
|
|
|
Exclude: []types.WhenCondition{{Match: "branch01", Type: types.WhenConditionTypeRegExp}, {Match: "branch02"}},
|
2019-03-18 14:02:32 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
variables: map[string]string{
|
2019-04-10 15:13:51 +00:00
|
|
|
"variable01": "VARVALUE01",
|
|
|
|
"registry_username": "yourregistryusername",
|
2019-03-18 14:02:32 +00:00
|
|
|
},
|
2019-04-09 16:11:00 +00:00
|
|
|
out: map[string]*rstypes.RunConfigTask{
|
2019-04-16 09:01:02 +00:00
|
|
|
uuid.New("task01").String(): &rstypes.RunConfigTask{
|
|
|
|
ID: uuid.New("task01").String(),
|
|
|
|
Name: "task01", Depends: map[string]*rstypes.RunConfigTaskDepend{},
|
2019-04-22 12:38:25 +00:00
|
|
|
DockerRegistriesAuth: map[string]rstypes.DockerRegistryAuth{
|
|
|
|
"index.docker.io": {
|
|
|
|
Type: rstypes.DockerRegistryAuthTypeBasic,
|
|
|
|
Username: "yourregistryusername",
|
|
|
|
Password: "password2",
|
|
|
|
},
|
|
|
|
},
|
2019-04-09 16:11:00 +00:00
|
|
|
Runtime: &rstypes.Runtime{Type: rstypes.RuntimeType("pod"),
|
|
|
|
Containers: []*rstypes.Container{
|
|
|
|
{
|
|
|
|
Image: "image01",
|
|
|
|
Environment: map[string]string{
|
|
|
|
"ENV01": "ENV01",
|
|
|
|
"ENVFROMVARIABLE01": "VARVALUE01",
|
2019-03-18 14:02:32 +00:00
|
|
|
},
|
2019-10-08 13:52:35 +00:00
|
|
|
Volumes: []rstypes.Volume{
|
|
|
|
rstypes.Volume{
|
|
|
|
Path: "/mnt/vol01",
|
|
|
|
TmpFS: &rstypes.VolumeTmpFS{},
|
|
|
|
},
|
|
|
|
rstypes.Volume{
|
|
|
|
Path: "/mnt/vol01",
|
|
|
|
TmpFS: &rstypes.VolumeTmpFS{Size: 1024 * 1024 * 1024},
|
|
|
|
},
|
|
|
|
},
|
2019-03-18 14:02:32 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2019-09-11 13:17:38 +00:00
|
|
|
Shell: "/bin/sh -e",
|
2019-04-09 16:11:00 +00:00
|
|
|
Environment: map[string]string{
|
|
|
|
"ENV01": "ENV01",
|
|
|
|
"ENVFROMVARIABLE01": "VARVALUE01",
|
|
|
|
},
|
2019-06-08 14:30:36 +00:00
|
|
|
Steps: rstypes.Steps{
|
|
|
|
&rstypes.RunStep{BaseStep: rstypes.BaseStep{Type: "run", Name: "command01"}, Command: "command01", Environment: map[string]string{}},
|
|
|
|
&rstypes.RunStep{BaseStep: rstypes.BaseStep{Type: "run", Name: "name different than command"}, Command: "command02", Environment: map[string]string{}},
|
|
|
|
&rstypes.RunStep{BaseStep: rstypes.BaseStep{Type: "run", Name: "command03"}, Command: "command03", Environment: map[string]string{"ENV01": "ENV01", "ENVFROMVARIABLE01": "VARVALUE01"}},
|
2019-04-09 16:11:00 +00:00
|
|
|
},
|
|
|
|
Skip: true,
|
2019-03-18 14:02:32 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2019-04-10 15:13:51 +00:00
|
|
|
{
|
2019-04-22 12:38:25 +00:00
|
|
|
name: "test run auth used for task undefined auth",
|
2019-04-10 15:13:51 +00:00
|
|
|
in: &config.Config{
|
2019-04-16 09:01:02 +00:00
|
|
|
Runs: []*config.Run{
|
|
|
|
&config.Run{
|
2019-04-15 21:42:10 +00:00
|
|
|
Name: "run01",
|
2019-04-22 12:38:25 +00:00
|
|
|
DockerRegistriesAuth: map[string]*config.DockerRegistryAuth{
|
|
|
|
"index.docker.io": {
|
|
|
|
Type: config.DockerRegistryAuthTypeBasic,
|
|
|
|
Username: config.Value{Type: config.ValueTypeString, Value: "username"},
|
|
|
|
Password: config.Value{Type: config.ValueTypeFromVariable, Value: "password"},
|
|
|
|
},
|
|
|
|
},
|
2019-04-16 09:01:02 +00:00
|
|
|
Tasks: []*config.Task{
|
|
|
|
&config.Task{
|
|
|
|
Name: "task01",
|
|
|
|
Runtime: &config.Runtime{
|
|
|
|
Type: "pod",
|
|
|
|
Arch: "",
|
|
|
|
Containers: []*config.Container{
|
|
|
|
&config.Container{
|
|
|
|
Image: "image01",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2019-06-08 14:07:15 +00:00
|
|
|
Steps: config.Steps{
|
2019-04-16 09:01:02 +00:00
|
|
|
&config.RunStep{
|
2019-06-08 14:07:15 +00:00
|
|
|
BaseStep: config.BaseStep{
|
2019-04-16 09:01:02 +00:00
|
|
|
Type: "run",
|
|
|
|
Name: "command01",
|
|
|
|
},
|
|
|
|
Command: "command01",
|
|
|
|
},
|
|
|
|
},
|
2019-04-10 15:13:51 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
variables: map[string]string{
|
|
|
|
"variable01": "VARVALUE01",
|
|
|
|
"password": "yourregistrypassword",
|
|
|
|
},
|
|
|
|
out: map[string]*rstypes.RunConfigTask{
|
2019-04-16 09:01:02 +00:00
|
|
|
uuid.New("task01").String(): &rstypes.RunConfigTask{
|
|
|
|
ID: uuid.New("task01").String(),
|
|
|
|
Name: "task01", Depends: map[string]*rstypes.RunConfigTaskDepend{},
|
2019-04-22 12:38:25 +00:00
|
|
|
DockerRegistriesAuth: map[string]rstypes.DockerRegistryAuth{
|
|
|
|
"index.docker.io": {
|
|
|
|
Type: rstypes.DockerRegistryAuthTypeBasic,
|
|
|
|
Username: "username",
|
|
|
|
Password: "yourregistrypassword",
|
|
|
|
},
|
|
|
|
},
|
2019-04-10 15:13:51 +00:00
|
|
|
Runtime: &rstypes.Runtime{Type: rstypes.RuntimeType("pod"),
|
|
|
|
Containers: []*rstypes.Container{
|
|
|
|
{
|
2019-04-22 12:38:25 +00:00
|
|
|
Image: "image01",
|
2019-04-10 15:13:51 +00:00
|
|
|
Environment: map[string]string{},
|
2019-10-08 13:52:35 +00:00
|
|
|
Volumes: []rstypes.Volume{},
|
2019-04-10 15:13:51 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2019-09-11 13:17:38 +00:00
|
|
|
Shell: "/bin/sh -e",
|
2019-04-10 15:13:51 +00:00
|
|
|
Environment: map[string]string{},
|
2019-06-08 14:30:36 +00:00
|
|
|
Steps: rstypes.Steps{
|
|
|
|
&rstypes.RunStep{BaseStep: rstypes.BaseStep{Type: "run", Name: "command01"}, Command: "command01", Environment: map[string]string{}},
|
2019-04-10 15:13:51 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2019-04-22 12:38:25 +00:00
|
|
|
name: "test run auth override by task auth",
|
2019-04-10 15:13:51 +00:00
|
|
|
in: &config.Config{
|
2019-04-16 09:01:02 +00:00
|
|
|
Runs: []*config.Run{
|
|
|
|
&config.Run{
|
|
|
|
Name: "run01",
|
2019-04-22 12:38:25 +00:00
|
|
|
DockerRegistriesAuth: map[string]*config.DockerRegistryAuth{
|
|
|
|
"index.docker.io": {
|
|
|
|
Type: config.DockerRegistryAuthTypeBasic,
|
|
|
|
Username: config.Value{Type: config.ValueTypeString, Value: "username"},
|
|
|
|
Password: config.Value{Type: config.ValueTypeFromVariable, Value: "password"},
|
|
|
|
},
|
|
|
|
"https://myregistry.example.com": {
|
|
|
|
Type: config.DockerRegistryAuthTypeBasic,
|
|
|
|
Username: config.Value{Type: config.ValueTypeString, Value: "username"},
|
|
|
|
Password: config.Value{Type: config.ValueTypeFromVariable, Value: "password"},
|
|
|
|
},
|
|
|
|
},
|
2019-04-16 09:01:02 +00:00
|
|
|
Tasks: []*config.Task{
|
|
|
|
&config.Task{
|
|
|
|
Name: "task01",
|
2019-04-22 12:38:25 +00:00
|
|
|
DockerRegistriesAuth: map[string]*config.DockerRegistryAuth{
|
|
|
|
"index.docker.io": {
|
|
|
|
Type: config.DockerRegistryAuthTypeBasic,
|
|
|
|
Username: config.Value{Type: config.ValueTypeFromVariable, Value: "registry_username"},
|
|
|
|
Password: config.Value{Type: config.ValueTypeString, Value: "password2"},
|
|
|
|
},
|
|
|
|
"https://anotherregistry.example.com": {
|
|
|
|
Type: config.DockerRegistryAuthTypeBasic,
|
|
|
|
Username: config.Value{Type: config.ValueTypeFromVariable, Value: "registry_username"},
|
|
|
|
Password: config.Value{Type: config.ValueTypeString, Value: "password2"},
|
|
|
|
},
|
|
|
|
},
|
2019-04-16 09:01:02 +00:00
|
|
|
Runtime: &config.Runtime{
|
|
|
|
Type: "pod",
|
|
|
|
Arch: "",
|
|
|
|
Containers: []*config.Container{
|
|
|
|
&config.Container{
|
|
|
|
Image: "image01",
|
|
|
|
},
|
|
|
|
},
|
2019-04-10 15:13:51 +00:00
|
|
|
},
|
2019-06-08 14:07:15 +00:00
|
|
|
Steps: config.Steps{
|
2019-04-16 09:01:02 +00:00
|
|
|
&config.RunStep{
|
2019-06-08 14:07:15 +00:00
|
|
|
BaseStep: config.BaseStep{
|
2019-04-16 09:01:02 +00:00
|
|
|
Type: "run",
|
|
|
|
Name: "command01",
|
|
|
|
},
|
|
|
|
Command: "command01",
|
|
|
|
},
|
2019-04-10 15:13:51 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
variables: map[string]string{
|
|
|
|
"variable01": "VARVALUE01",
|
|
|
|
"registry_username": "yourregistryusername",
|
2019-04-22 12:38:25 +00:00
|
|
|
"password": "myregistrypassword",
|
2019-04-10 15:13:51 +00:00
|
|
|
},
|
|
|
|
out: map[string]*rstypes.RunConfigTask{
|
2019-04-16 09:01:02 +00:00
|
|
|
uuid.New("task01").String(): &rstypes.RunConfigTask{
|
|
|
|
ID: uuid.New("task01").String(),
|
|
|
|
Name: "task01", Depends: map[string]*rstypes.RunConfigTaskDepend{},
|
2019-04-22 12:38:25 +00:00
|
|
|
DockerRegistriesAuth: map[string]rstypes.DockerRegistryAuth{
|
|
|
|
"index.docker.io": {
|
|
|
|
Type: rstypes.DockerRegistryAuthTypeBasic,
|
|
|
|
Username: "yourregistryusername",
|
|
|
|
Password: "password2",
|
|
|
|
},
|
|
|
|
"https://myregistry.example.com": {
|
|
|
|
Type: rstypes.DockerRegistryAuthTypeBasic,
|
|
|
|
Username: "username",
|
|
|
|
Password: "myregistrypassword",
|
|
|
|
},
|
|
|
|
"https://anotherregistry.example.com": {
|
|
|
|
Type: rstypes.DockerRegistryAuthTypeBasic,
|
|
|
|
Username: "yourregistryusername",
|
|
|
|
Password: "password2",
|
|
|
|
},
|
|
|
|
},
|
2019-04-10 15:13:51 +00:00
|
|
|
Runtime: &rstypes.Runtime{Type: rstypes.RuntimeType("pod"),
|
|
|
|
Containers: []*rstypes.Container{
|
|
|
|
{
|
2019-04-22 12:38:25 +00:00
|
|
|
Image: "image01",
|
2019-04-10 15:13:51 +00:00
|
|
|
Environment: map[string]string{},
|
2019-10-08 13:52:35 +00:00
|
|
|
Volumes: []rstypes.Volume{},
|
2019-04-10 15:13:51 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2019-09-11 13:17:38 +00:00
|
|
|
Shell: "/bin/sh -e",
|
2019-04-10 15:13:51 +00:00
|
|
|
Environment: map[string]string{},
|
2019-06-08 14:30:36 +00:00
|
|
|
Steps: rstypes.Steps{
|
|
|
|
&rstypes.RunStep{BaseStep: rstypes.BaseStep{Type: "run", Name: "command01"}, Command: "command01", Environment: map[string]string{}},
|
2019-04-10 15:13:51 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2019-03-18 14:02:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
2019-10-14 14:51:54 +00:00
|
|
|
out := GenRunConfigTasks(uuid, tt.in, "run01", tt.variables, "", "", "", "")
|
2019-03-18 14:02:32 +00:00
|
|
|
|
|
|
|
if diff := cmp.Diff(tt.out, out); diff != "" {
|
|
|
|
t.Error(diff)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|