2019-03-07 13:42:32 +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 config
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
|
2019-07-01 09:40:20 +00:00
|
|
|
"agola.io/agola/internal/util"
|
2019-09-05 07:29:20 +00:00
|
|
|
"agola.io/agola/services/types"
|
2019-03-07 17:01:34 +00:00
|
|
|
|
|
|
|
"github.com/google/go-cmp/cmp"
|
2019-05-23 09:23:14 +00:00
|
|
|
errors "golang.org/x/xerrors"
|
2019-10-08 13:52:35 +00:00
|
|
|
"k8s.io/apimachinery/pkg/api/resource"
|
2019-03-07 13:42:32 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestParseConfig(t *testing.T) {
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
in string
|
|
|
|
err error
|
|
|
|
}{
|
|
|
|
{
|
2019-04-15 21:42:10 +00:00
|
|
|
name: "test no runs 1",
|
2019-03-07 13:42:32 +00:00
|
|
|
in: ``,
|
2019-04-15 21:42:10 +00:00
|
|
|
err: fmt.Errorf(`no runs defined`),
|
2019-03-07 13:42:32 +00:00
|
|
|
},
|
|
|
|
{
|
2019-04-15 21:42:10 +00:00
|
|
|
name: "test no runs 2",
|
2019-03-07 13:42:32 +00:00
|
|
|
in: `
|
2019-04-15 21:42:10 +00:00
|
|
|
runs:
|
2019-03-07 13:42:32 +00:00
|
|
|
`,
|
2019-04-15 21:42:10 +00:00
|
|
|
err: fmt.Errorf(`no runs defined`),
|
2019-03-07 13:42:32 +00:00
|
|
|
},
|
|
|
|
{
|
2019-04-15 21:42:10 +00:00
|
|
|
name: "test empty run",
|
2019-03-07 13:42:32 +00:00
|
|
|
in: `
|
2019-04-15 21:42:10 +00:00
|
|
|
runs:
|
2019-04-16 09:01:02 +00:00
|
|
|
-
|
2019-03-07 13:42:32 +00:00
|
|
|
`,
|
2019-04-16 09:01:02 +00:00
|
|
|
err: fmt.Errorf(`run at index 0 is empty`),
|
2019-03-07 13:42:32 +00:00
|
|
|
},
|
|
|
|
{
|
2019-04-16 09:01:02 +00:00
|
|
|
name: "test empty task",
|
|
|
|
in: `
|
|
|
|
runs:
|
|
|
|
- name: run01
|
|
|
|
tasks:
|
|
|
|
-
|
|
|
|
`,
|
|
|
|
err: fmt.Errorf(`run "run01": task at index 0 is empty`),
|
|
|
|
},
|
2019-04-17 13:24:37 +00:00
|
|
|
{
|
|
|
|
name: "test empty runtime arch",
|
|
|
|
in: `
|
|
|
|
runs:
|
|
|
|
- name: run01
|
|
|
|
tasks:
|
|
|
|
- name: task01
|
|
|
|
runtime:
|
|
|
|
type: pod
|
|
|
|
containers:
|
|
|
|
- image: busybox
|
|
|
|
`,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "test invalid runtime arch",
|
|
|
|
in: `
|
|
|
|
runs:
|
|
|
|
- name: run01
|
|
|
|
tasks:
|
|
|
|
- name: task01
|
|
|
|
runtime:
|
|
|
|
type: pod
|
|
|
|
arch: invalidarch
|
|
|
|
containers:
|
|
|
|
- image: busybox
|
|
|
|
`,
|
|
|
|
err: fmt.Errorf(`task "task01" runtime: invalid arch "invalidarch"`),
|
|
|
|
},
|
2019-04-16 09:01:02 +00:00
|
|
|
{
|
|
|
|
name: "test missing task dependency",
|
2019-03-07 13:42:32 +00:00
|
|
|
in: `
|
2019-04-15 21:42:10 +00:00
|
|
|
runs:
|
2019-04-16 09:01:02 +00:00
|
|
|
- name: run01
|
|
|
|
tasks:
|
|
|
|
- name: task01
|
|
|
|
runtime:
|
|
|
|
type: pod
|
|
|
|
containers:
|
|
|
|
- image: busybox
|
2019-03-07 13:42:32 +00:00
|
|
|
depends:
|
2019-04-16 09:01:02 +00:00
|
|
|
- task02
|
2019-03-07 13:42:32 +00:00
|
|
|
`,
|
2019-04-16 09:01:02 +00:00
|
|
|
err: fmt.Errorf(`run task "task02" needed by task "task01" doesn't exist`),
|
2019-03-07 13:42:32 +00:00
|
|
|
},
|
|
|
|
{
|
2019-04-16 09:01:02 +00:00
|
|
|
name: "test circular dependency between 2 tasks a -> b -> a",
|
2019-03-07 13:42:32 +00:00
|
|
|
in: `
|
2019-04-15 21:42:10 +00:00
|
|
|
runs:
|
2019-04-16 09:01:02 +00:00
|
|
|
- name: run01
|
|
|
|
tasks:
|
|
|
|
- name: task01
|
|
|
|
runtime:
|
|
|
|
type: pod
|
|
|
|
containers:
|
|
|
|
- image: busybox
|
2019-03-07 13:42:32 +00:00
|
|
|
depends:
|
2019-04-16 09:01:02 +00:00
|
|
|
- task02
|
|
|
|
- name: task02
|
|
|
|
runtime:
|
|
|
|
type: pod
|
|
|
|
containers:
|
|
|
|
- image: busybox
|
2019-03-07 13:42:32 +00:00
|
|
|
depends:
|
2019-04-16 09:01:02 +00:00
|
|
|
- task01
|
2019-03-07 13:42:32 +00:00
|
|
|
`,
|
|
|
|
err: &util.Errors{
|
|
|
|
Errs: []error{
|
2019-04-16 09:01:02 +00:00
|
|
|
errors.Errorf("circular dependency between task %q and tasks %q", "task01", "task02"),
|
|
|
|
errors.Errorf("circular dependency between task %q and tasks %q", "task02", "task01"),
|
2019-03-07 13:42:32 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2019-08-12 21:11:19 +00:00
|
|
|
{
|
|
|
|
name: "test task parent same dep a -> b -> c, a -> c",
|
|
|
|
in: `
|
|
|
|
runs:
|
|
|
|
- name: run01
|
|
|
|
tasks:
|
|
|
|
- name: task01
|
|
|
|
runtime:
|
|
|
|
type: pod
|
|
|
|
containers:
|
|
|
|
- image: busybox
|
|
|
|
- name: task02
|
|
|
|
runtime:
|
|
|
|
type: pod
|
|
|
|
containers:
|
|
|
|
- image: busybox
|
|
|
|
depends:
|
|
|
|
- task01
|
|
|
|
- name: task03
|
|
|
|
runtime:
|
|
|
|
type: pod
|
|
|
|
containers:
|
|
|
|
- image: busybox
|
|
|
|
depends:
|
|
|
|
- task02
|
|
|
|
- task01
|
|
|
|
`,
|
|
|
|
err: errors.Errorf("task %q and its dependency %q have both a dependency on task %q", "task03", "task02", "task01"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "test task parent same dep a -> b -> c -> d, a -> d",
|
|
|
|
in: `
|
|
|
|
runs:
|
|
|
|
- name: run01
|
|
|
|
tasks:
|
|
|
|
- name: task01
|
|
|
|
runtime:
|
|
|
|
type: pod
|
|
|
|
containers:
|
|
|
|
- image: busybox
|
|
|
|
- name: task02
|
|
|
|
runtime:
|
|
|
|
type: pod
|
|
|
|
containers:
|
|
|
|
- image: busybox
|
|
|
|
depends:
|
|
|
|
- task01
|
|
|
|
- name: task03
|
|
|
|
runtime:
|
|
|
|
type: pod
|
|
|
|
containers:
|
|
|
|
- image: busybox
|
|
|
|
depends:
|
|
|
|
- task02
|
|
|
|
- name: task04
|
|
|
|
runtime:
|
|
|
|
type: pod
|
|
|
|
containers:
|
|
|
|
- image: busybox
|
|
|
|
depends:
|
|
|
|
- task03
|
|
|
|
- task01
|
|
|
|
`,
|
|
|
|
err: errors.Errorf("task %q and its dependency %q have both a dependency on task %q", "task04", "task03", "task01"),
|
|
|
|
},
|
2019-03-07 13:42:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
2019-04-16 13:00:37 +00:00
|
|
|
if _, err := ParseConfig([]byte(tt.in), ConfigFormatJSON); err != nil {
|
2019-03-07 13:42:32 +00:00
|
|
|
if tt.err == nil {
|
|
|
|
t.Fatalf("got error: %v, expected no error", err)
|
|
|
|
}
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|
2019-03-07 17:01:34 +00:00
|
|
|
} else {
|
|
|
|
if tt.err != nil {
|
|
|
|
t.Fatalf("got nil error, want error: %v", tt.err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestParseOutput(t *testing.T) {
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
in string
|
|
|
|
out *Config
|
|
|
|
}{
|
|
|
|
{
|
2019-04-16 09:01:02 +00:00
|
|
|
name: "test task all options",
|
2019-03-07 17:01:34 +00:00
|
|
|
in: `
|
2019-04-16 09:01:02 +00:00
|
|
|
runs:
|
|
|
|
- name: run01
|
2019-04-22 12:38:25 +00:00
|
|
|
docker_registries_auth:
|
|
|
|
index.docker.io:
|
|
|
|
username: username
|
|
|
|
password:
|
|
|
|
from_variable: password
|
2019-04-16 09:01:02 +00:00
|
|
|
tasks:
|
|
|
|
- name: task01
|
2019-04-22 12:38:25 +00:00
|
|
|
docker_registries_auth:
|
|
|
|
index.docker.io:
|
2019-04-16 09:01:02 +00:00
|
|
|
username: username
|
|
|
|
password:
|
|
|
|
from_variable: password
|
2019-04-22 12:38:25 +00:00
|
|
|
runtime:
|
|
|
|
type: pod
|
2019-04-16 09:01:02 +00:00
|
|
|
containers:
|
|
|
|
- image: image01
|
|
|
|
auth:
|
|
|
|
username:
|
|
|
|
from_variable: username2
|
|
|
|
password: password2
|
|
|
|
environment:
|
|
|
|
ENV01: ENV01
|
|
|
|
ENVFROMVARIABLE01:
|
|
|
|
from_variable: variable01
|
2019-03-18 14:02:32 +00:00
|
|
|
environment:
|
|
|
|
ENV01: ENV01
|
|
|
|
ENVFROMVARIABLE01:
|
|
|
|
from_variable: variable01
|
2019-04-16 09:01:02 +00:00
|
|
|
steps:
|
|
|
|
# normal step definition
|
|
|
|
- type: clone
|
|
|
|
- type: run
|
|
|
|
command: command01
|
|
|
|
- type: run
|
|
|
|
name: name different than command
|
|
|
|
command: command02
|
|
|
|
- type: run
|
|
|
|
command: command03
|
|
|
|
environment:
|
|
|
|
ENV01: ENV01
|
|
|
|
ENVFROMVARIABLE01:
|
|
|
|
from_variable: variable01
|
|
|
|
- type: save_cache
|
|
|
|
key: cache-{{ arch }}
|
|
|
|
contents:
|
|
|
|
- source_dir: /go/pkg/mod/cache
|
2019-03-07 17:01:34 +00:00
|
|
|
|
2019-04-16 09:01:02 +00:00
|
|
|
# simpler (for yaml not for json) steps definition
|
|
|
|
- clone:
|
|
|
|
- run: command01
|
|
|
|
- run:
|
|
|
|
name: name different than command
|
|
|
|
command: command02
|
|
|
|
- run:
|
|
|
|
command: command03
|
|
|
|
environment:
|
|
|
|
ENV01: ENV01
|
|
|
|
ENVFROMVARIABLE01:
|
|
|
|
from_variable: variable01
|
|
|
|
- save_cache:
|
|
|
|
key: cache-{{ arch }}
|
|
|
|
contents:
|
|
|
|
- source_dir: /go/pkg/mod/cache
|
2019-03-07 17:01:34 +00:00
|
|
|
when:
|
|
|
|
branch: master
|
|
|
|
tag:
|
|
|
|
- v1.x
|
|
|
|
- v2.x
|
|
|
|
ref:
|
|
|
|
include: master
|
|
|
|
exclude: [ /branch01/ , branch02 ]
|
2019-04-16 09:01:02 +00:00
|
|
|
depends:
|
|
|
|
- task: task02
|
|
|
|
conditions:
|
|
|
|
- on_success
|
|
|
|
- on_failure
|
|
|
|
- task03
|
|
|
|
- task04:
|
|
|
|
- on_success
|
|
|
|
- name: task02
|
|
|
|
runtime:
|
|
|
|
type: pod
|
|
|
|
containers:
|
|
|
|
- image: image01
|
|
|
|
- name: task03
|
|
|
|
runtime:
|
|
|
|
type: pod
|
|
|
|
containers:
|
|
|
|
- image: image01
|
2019-10-08 13:52:35 +00:00
|
|
|
volumes:
|
|
|
|
- path: /mnt/tmpfs
|
|
|
|
tmpfs:
|
|
|
|
size: 1Gi
|
2019-04-16 09:01:02 +00:00
|
|
|
- name: task04
|
|
|
|
runtime:
|
|
|
|
type: pod
|
|
|
|
containers:
|
|
|
|
- image: image01
|
2019-10-08 13:52:35 +00:00
|
|
|
volumes:
|
|
|
|
- path: /mnt/tmpfs
|
|
|
|
tmpfs: {}
|
2019-03-07 17:01:34 +00:00
|
|
|
`,
|
|
|
|
out: &Config{
|
2019-04-16 09:01:02 +00:00
|
|
|
Runs: []*Run{
|
|
|
|
&Run{
|
|
|
|
Name: "run01",
|
2019-04-22 12:38:25 +00:00
|
|
|
DockerRegistriesAuth: map[string]*DockerRegistryAuth{
|
|
|
|
"index.docker.io": {
|
|
|
|
Type: DockerRegistryAuthTypeBasic,
|
|
|
|
Username: Value{Type: ValueTypeString, Value: "username"},
|
|
|
|
Password: Value{Type: ValueTypeFromVariable, Value: "password"},
|
|
|
|
},
|
|
|
|
},
|
2019-04-16 09:01:02 +00:00
|
|
|
Tasks: []*Task{
|
|
|
|
&Task{
|
|
|
|
Name: "task01",
|
2019-04-22 12:38:25 +00:00
|
|
|
DockerRegistriesAuth: map[string]*DockerRegistryAuth{
|
|
|
|
"index.docker.io": {
|
|
|
|
Type: DockerRegistryAuthTypeBasic,
|
2019-04-16 09:01:02 +00:00
|
|
|
Username: Value{Type: ValueTypeString, Value: "username"},
|
|
|
|
Password: Value{Type: ValueTypeFromVariable, Value: "password"},
|
|
|
|
},
|
2019-04-22 12:38:25 +00:00
|
|
|
},
|
|
|
|
Runtime: &Runtime{
|
|
|
|
Type: "pod",
|
2019-04-16 09:01:02 +00:00
|
|
|
Arch: "",
|
|
|
|
Containers: []*Container{
|
|
|
|
&Container{
|
|
|
|
Image: "image01",
|
|
|
|
Environment: map[string]Value{
|
|
|
|
"ENV01": Value{Type: ValueTypeString, Value: "ENV01"},
|
|
|
|
"ENVFROMVARIABLE01": Value{Type: ValueTypeFromVariable, Value: "variable01"},
|
|
|
|
},
|
|
|
|
User: "",
|
|
|
|
},
|
|
|
|
},
|
2019-04-10 15:13:51 +00:00
|
|
|
},
|
2019-04-10 15:12:39 +00:00
|
|
|
Environment: map[string]Value{
|
|
|
|
"ENV01": Value{Type: ValueTypeString, Value: "ENV01"},
|
|
|
|
"ENVFROMVARIABLE01": Value{Type: ValueTypeFromVariable, Value: "variable01"},
|
2019-03-18 14:02:32 +00:00
|
|
|
},
|
2019-04-16 13:20:45 +00:00
|
|
|
WorkingDir: defaultWorkingDir,
|
2019-04-16 09:01:02 +00:00
|
|
|
Shell: "",
|
|
|
|
User: "",
|
2019-06-08 14:07:15 +00:00
|
|
|
Steps: Steps{
|
|
|
|
&CloneStep{BaseStep: BaseStep{Type: "clone"}},
|
2019-04-16 09:01:02 +00:00
|
|
|
&RunStep{
|
2019-06-08 14:07:15 +00:00
|
|
|
BaseStep: BaseStep{
|
2019-04-16 09:01:02 +00:00
|
|
|
Type: "run",
|
|
|
|
Name: "command01",
|
|
|
|
},
|
|
|
|
Command: "command01",
|
|
|
|
},
|
|
|
|
&RunStep{
|
2019-06-08 14:07:15 +00:00
|
|
|
BaseStep: BaseStep{
|
2019-04-16 09:01:02 +00:00
|
|
|
Type: "run",
|
|
|
|
Name: "name different than command",
|
|
|
|
},
|
|
|
|
Command: "command02",
|
|
|
|
},
|
|
|
|
&RunStep{
|
2019-06-08 14:07:15 +00:00
|
|
|
BaseStep: BaseStep{
|
2019-04-16 09:01:02 +00:00
|
|
|
Type: "run",
|
|
|
|
Name: "command03",
|
|
|
|
},
|
|
|
|
Command: "command03",
|
|
|
|
Environment: map[string]Value{
|
|
|
|
"ENV01": Value{Type: ValueTypeString, Value: "ENV01"},
|
|
|
|
"ENVFROMVARIABLE01": Value{Type: ValueTypeFromVariable, Value: "variable01"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
&SaveCacheStep{
|
2019-06-08 14:07:15 +00:00
|
|
|
BaseStep: BaseStep{Type: "save_cache"},
|
2019-04-16 09:01:02 +00:00
|
|
|
Key: "cache-{{ arch }}",
|
|
|
|
Contents: []*SaveContent{&SaveContent{SourceDir: "/go/pkg/mod/cache", Paths: []string{"**"}}},
|
|
|
|
},
|
2019-06-08 14:07:15 +00:00
|
|
|
&CloneStep{BaseStep: BaseStep{Type: "clone"}},
|
2019-04-16 09:01:02 +00:00
|
|
|
&RunStep{
|
2019-06-08 14:07:15 +00:00
|
|
|
BaseStep: BaseStep{
|
2019-04-16 09:01:02 +00:00
|
|
|
Type: "run",
|
|
|
|
Name: "command01",
|
|
|
|
},
|
|
|
|
Command: "command01",
|
|
|
|
},
|
|
|
|
&RunStep{
|
2019-06-08 14:07:15 +00:00
|
|
|
BaseStep: BaseStep{
|
2019-04-16 09:01:02 +00:00
|
|
|
Type: "run",
|
|
|
|
Name: "name different than command",
|
|
|
|
},
|
|
|
|
Command: "command02",
|
|
|
|
},
|
|
|
|
&RunStep{
|
2019-06-08 14:07:15 +00:00
|
|
|
BaseStep: BaseStep{
|
2019-04-16 09:01:02 +00:00
|
|
|
Type: "run",
|
|
|
|
Name: "command03",
|
|
|
|
},
|
|
|
|
Command: "command03",
|
|
|
|
Environment: map[string]Value{
|
|
|
|
"ENV01": Value{Type: ValueTypeString, Value: "ENV01"},
|
|
|
|
"ENVFROMVARIABLE01": Value{Type: ValueTypeFromVariable, Value: "variable01"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
&SaveCacheStep{
|
2019-06-08 14:07:15 +00:00
|
|
|
BaseStep: BaseStep{Type: "save_cache"},
|
2019-04-16 09:01:02 +00:00
|
|
|
Key: "cache-{{ arch }}",
|
|
|
|
Contents: []*SaveContent{&SaveContent{SourceDir: "/go/pkg/mod/cache", Paths: []string{"**"}}},
|
|
|
|
},
|
2019-03-18 14:02:32 +00:00
|
|
|
},
|
2019-03-07 17:01:34 +00:00
|
|
|
IgnoreFailure: false,
|
|
|
|
Approval: false,
|
2019-06-08 14:07:15 +00:00
|
|
|
When: &When{
|
2019-03-07 17:01:34 +00:00
|
|
|
Branch: &types.WhenConditions{
|
|
|
|
Include: []types.WhenCondition{
|
|
|
|
{Type: types.WhenConditionTypeSimple, Match: "master"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Tag: &types.WhenConditions{
|
|
|
|
Include: []types.WhenCondition{
|
|
|
|
{Type: types.WhenConditionTypeSimple, Match: "v1.x"},
|
|
|
|
{Type: types.WhenConditionTypeSimple, Match: "v2.x"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Ref: &types.WhenConditions{
|
|
|
|
Include: []types.WhenCondition{
|
|
|
|
{Type: types.WhenConditionTypeSimple, Match: "master"},
|
|
|
|
},
|
|
|
|
Exclude: []types.WhenCondition{
|
|
|
|
{Type: types.WhenConditionTypeRegExp, Match: "branch01"},
|
|
|
|
{Type: types.WhenConditionTypeSimple, Match: "branch02"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2019-04-16 09:01:02 +00:00
|
|
|
Depends: []*Depend{
|
|
|
|
&Depend{TaskName: "task02", Conditions: []DependCondition{DependConditionOnSuccess, DependConditionOnFailure}},
|
|
|
|
&Depend{TaskName: "task03", Conditions: nil},
|
|
|
|
&Depend{TaskName: "task04", Conditions: []DependCondition{DependConditionOnSuccess}},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
&Task{
|
|
|
|
Name: "task02",
|
|
|
|
Runtime: &Runtime{
|
|
|
|
Type: "pod",
|
|
|
|
Arch: "",
|
|
|
|
Containers: []*Container{
|
|
|
|
&Container{
|
|
|
|
Image: "image01",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2019-04-16 13:20:45 +00:00
|
|
|
WorkingDir: defaultWorkingDir,
|
2019-06-08 14:07:15 +00:00
|
|
|
Steps: nil,
|
|
|
|
Depends: nil,
|
2019-04-16 09:01:02 +00:00
|
|
|
},
|
|
|
|
&Task{
|
|
|
|
Name: "task03",
|
|
|
|
Runtime: &Runtime{
|
|
|
|
Type: "pod",
|
|
|
|
Arch: "",
|
|
|
|
Containers: []*Container{
|
|
|
|
&Container{
|
2019-10-08 13:52:35 +00:00
|
|
|
Image: "image01",
|
|
|
|
Volumes: []Volume{{Path: "/mnt/tmpfs", TmpFS: &VolumeTmpFS{Size: resource.NewQuantity(1024*1024*1024, resource.BinarySI)}}},
|
2019-04-16 09:01:02 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2019-04-16 13:20:45 +00:00
|
|
|
WorkingDir: defaultWorkingDir,
|
2019-06-08 14:07:15 +00:00
|
|
|
Steps: nil,
|
|
|
|
Depends: nil,
|
2019-04-16 09:01:02 +00:00
|
|
|
},
|
|
|
|
&Task{
|
|
|
|
Name: "task04",
|
|
|
|
Runtime: &Runtime{
|
|
|
|
Type: "pod",
|
|
|
|
Arch: "",
|
|
|
|
Containers: []*Container{
|
|
|
|
&Container{
|
2019-10-08 13:52:35 +00:00
|
|
|
Image: "image01",
|
|
|
|
Volumes: []Volume{{Path: "/mnt/tmpfs", TmpFS: &VolumeTmpFS{}}},
|
2019-04-16 09:01:02 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2019-04-16 13:20:45 +00:00
|
|
|
WorkingDir: defaultWorkingDir,
|
2019-06-08 14:07:15 +00:00
|
|
|
Steps: nil,
|
|
|
|
Depends: nil,
|
2019-03-07 17:01:34 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
2019-04-16 13:00:37 +00:00
|
|
|
out, err := ParseConfig([]byte(tt.in), ConfigFormatJSON)
|
2019-03-07 17:01:34 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("unexpected error: %v", err)
|
2019-03-07 13:42:32 +00:00
|
|
|
}
|
2019-10-08 13:52:35 +00:00
|
|
|
if diff := cmp.Diff(tt.out, out, cmp.Comparer(func(x, y *resource.Quantity) bool {
|
|
|
|
if x == nil && y == nil {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
if x != nil && y != nil {
|
|
|
|
return x.Cmp(*y) == 0
|
|
|
|
}
|
|
|
|
|
|
|
|
return false
|
|
|
|
})); diff != "" {
|
2019-03-07 17:01:34 +00:00
|
|
|
t.Error(diff)
|
2019-03-07 13:42:32 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|