From 61936065f86dc5300b9826af7b0b4d1c9bb9f6cd Mon Sep 17 00:00:00 2001 From: Simone Gotti Date: Thu, 9 Mar 2023 13:45:18 +0100 Subject: [PATCH] tests: cleanups * Remove redundant type declarations * Fix t.Fatal calls: remove wrong %w and use t.Fatalf --- internal/runconfig/runconfig_test.go | 234 +++++++++--------- .../services/runservice/scheduler_test.go | 52 ++-- tests/setup_test.go | 14 +- 3 files changed, 150 insertions(+), 150 deletions(-) diff --git a/internal/runconfig/runconfig_test.go b/internal/runconfig/runconfig_test.go index 9d51ffc36..ddb6f78f3 100644 --- a/internal/runconfig/runconfig_test.go +++ b/internal/runconfig/runconfig_test.go @@ -93,7 +93,7 @@ func TestGenTasksLevels(t *testing.T) { ID: "2", Level: -1, Depends: map[string]*rstypes.RunConfigTaskDepend{ - "1": &rstypes.RunConfigTaskDepend{TaskID: "1"}, + "1": {TaskID: "1"}, }, }, }, @@ -106,7 +106,7 @@ func TestGenTasksLevels(t *testing.T) { ID: "2", Level: 1, Depends: map[string]*rstypes.RunConfigTaskDepend{ - "1": &rstypes.RunConfigTaskDepend{TaskID: "1"}, + "1": {TaskID: "1"}, }, }, }, @@ -118,14 +118,14 @@ func TestGenTasksLevels(t *testing.T) { ID: "1", Level: -1, Depends: map[string]*rstypes.RunConfigTaskDepend{ - "2": &rstypes.RunConfigTaskDepend{TaskID: "2"}, + "2": {TaskID: "2"}, }, }, { ID: "2", Level: -1, Depends: map[string]*rstypes.RunConfigTaskDepend{ - "1": &rstypes.RunConfigTaskDepend{TaskID: "1"}, + "1": {TaskID: "1"}, }, }, }, @@ -138,21 +138,21 @@ func TestGenTasksLevels(t *testing.T) { ID: "1", Level: -1, Depends: map[string]*rstypes.RunConfigTaskDepend{ - "2": &rstypes.RunConfigTaskDepend{TaskID: "2"}, + "2": {TaskID: "2"}, }, }, { ID: "2", Level: -1, Depends: map[string]*rstypes.RunConfigTaskDepend{ - "3": &rstypes.RunConfigTaskDepend{TaskID: "3"}, + "3": {TaskID: "3"}, }, }, { ID: "3", Level: -1, Depends: map[string]*rstypes.RunConfigTaskDepend{ - "1": &rstypes.RunConfigTaskDepend{TaskID: "1"}, + "1": {TaskID: "1"}, }, }, }, @@ -165,21 +165,21 @@ func TestGenTasksLevels(t *testing.T) { ID: "1", Level: -1, Depends: map[string]*rstypes.RunConfigTaskDepend{ - "2": &rstypes.RunConfigTaskDepend{TaskID: "2"}, + "2": {TaskID: "2"}, }, }, { ID: "2", Level: -1, Depends: map[string]*rstypes.RunConfigTaskDepend{ - "3": &rstypes.RunConfigTaskDepend{TaskID: "3"}, + "3": {TaskID: "3"}, }, }, { ID: "3", Level: -1, Depends: map[string]*rstypes.RunConfigTaskDepend{ - "2": &rstypes.RunConfigTaskDepend{TaskID: "2"}, + "2": {TaskID: "2"}, }, }, }, @@ -242,7 +242,7 @@ func TestGetAllParents(t *testing.T) { }, }, out: map[string][]string{ - "1": []string{}, + "1": {}, }, }, { @@ -258,8 +258,8 @@ func TestGetAllParents(t *testing.T) { }, }, out: map[string][]string{ - "1": []string{}, - "2": []string{}, + "1": {}, + "2": {}, }, }, { @@ -269,12 +269,12 @@ func TestGetAllParents(t *testing.T) { ID: "1", Level: -1, Depends: map[string]*rstypes.RunConfigTaskDepend{ - "1": &rstypes.RunConfigTaskDepend{TaskID: "1"}, + "1": {TaskID: "1"}, }, }, }, out: map[string][]string{ - "1": []string{"1"}, + "1": {"1"}, }, }, { @@ -288,13 +288,13 @@ func TestGetAllParents(t *testing.T) { ID: "2", Level: -1, Depends: map[string]*rstypes.RunConfigTaskDepend{ - "1": &rstypes.RunConfigTaskDepend{TaskID: "1"}, + "1": {TaskID: "1"}, }, }, }, out: map[string][]string{ - "1": []string{}, - "2": []string{"1"}, + "1": {}, + "2": {"1"}, }, }, { @@ -304,22 +304,22 @@ func TestGetAllParents(t *testing.T) { ID: "1", Level: -1, Depends: map[string]*rstypes.RunConfigTaskDepend{ - "2": &rstypes.RunConfigTaskDepend{TaskID: "2"}, - "3": &rstypes.RunConfigTaskDepend{TaskID: "3"}, + "2": {TaskID: "2"}, + "3": {TaskID: "3"}, }, }, { ID: "2", Level: -1, Depends: map[string]*rstypes.RunConfigTaskDepend{ - "4": &rstypes.RunConfigTaskDepend{TaskID: "4"}, + "4": {TaskID: "4"}, }, }, { ID: "3", Level: -1, Depends: map[string]*rstypes.RunConfigTaskDepend{ - "5": &rstypes.RunConfigTaskDepend{TaskID: "5"}, + "5": {TaskID: "5"}, }, }, { @@ -332,11 +332,11 @@ func TestGetAllParents(t *testing.T) { }, }, out: map[string][]string{ - "1": []string{"2", "3", "4", "5"}, - "2": []string{"4"}, - "3": []string{"5"}, - "4": []string{}, - "5": []string{}, + "1": {"2", "3", "4", "5"}, + "2": {"4"}, + "3": {"5"}, + "4": {}, + "5": {}, }, }, { @@ -346,20 +346,20 @@ func TestGetAllParents(t *testing.T) { ID: "1", Level: -1, Depends: map[string]*rstypes.RunConfigTaskDepend{ - "2": &rstypes.RunConfigTaskDepend{TaskID: "2"}, + "2": {TaskID: "2"}, }, }, { ID: "2", Level: -1, Depends: map[string]*rstypes.RunConfigTaskDepend{ - "1": &rstypes.RunConfigTaskDepend{TaskID: "1"}, + "1": {TaskID: "1"}, }, }, }, out: map[string][]string{ - "1": []string{"2", "1"}, - "2": []string{"1", "2"}, + "1": {"2", "1"}, + "2": {"1", "2"}, }, }, { @@ -369,28 +369,28 @@ func TestGetAllParents(t *testing.T) { ID: "1", Level: -1, Depends: map[string]*rstypes.RunConfigTaskDepend{ - "2": &rstypes.RunConfigTaskDepend{TaskID: "2"}, + "2": {TaskID: "2"}, }, }, { ID: "2", Level: -1, Depends: map[string]*rstypes.RunConfigTaskDepend{ - "3": &rstypes.RunConfigTaskDepend{TaskID: "3"}, + "3": {TaskID: "3"}, }, }, { ID: "3", Level: -1, Depends: map[string]*rstypes.RunConfigTaskDepend{ - "1": &rstypes.RunConfigTaskDepend{TaskID: "1"}, + "1": {TaskID: "1"}, }, }, }, out: map[string][]string{ - "1": []string{"2", "3", "1"}, - "2": []string{"3", "1", "2"}, - "3": []string{"1", "2", "3"}, + "1": {"2", "3", "1"}, + "2": {"3", "1", "2"}, + "3": {"1", "2", "3"}, }, }, { @@ -400,28 +400,28 @@ func TestGetAllParents(t *testing.T) { ID: "1", Level: -1, Depends: map[string]*rstypes.RunConfigTaskDepend{ - "2": &rstypes.RunConfigTaskDepend{TaskID: "2"}, + "2": {TaskID: "2"}, }, }, { ID: "2", Level: -1, Depends: map[string]*rstypes.RunConfigTaskDepend{ - "3": &rstypes.RunConfigTaskDepend{TaskID: "3"}, + "3": {TaskID: "3"}, }, }, { ID: "3", Level: -1, Depends: map[string]*rstypes.RunConfigTaskDepend{ - "2": &rstypes.RunConfigTaskDepend{TaskID: "2"}, + "2": {TaskID: "2"}, }, }, }, out: map[string][]string{ - "1": []string{"2", "3"}, - "2": []string{"3", "2"}, - "3": []string{"2", "3"}, + "1": {"2", "3"}, + "2": {"3", "2"}, + "3": {"2", "3"}, }, }, } @@ -497,7 +497,7 @@ func TestCheckRunConfig(t *testing.T) { ID: "2", Level: -1, Depends: map[string]*rstypes.RunConfigTaskDepend{ - "1": &rstypes.RunConfigTaskDepend{TaskID: "1"}, + "1": {TaskID: "1"}, }, }, }, @@ -509,14 +509,14 @@ func TestCheckRunConfig(t *testing.T) { ID: "1", Level: -1, Depends: map[string]*rstypes.RunConfigTaskDepend{ - "2": &rstypes.RunConfigTaskDepend{TaskID: "2"}, + "2": {TaskID: "2"}, }, }, { ID: "2", Level: -1, Depends: map[string]*rstypes.RunConfigTaskDepend{ - "1": &rstypes.RunConfigTaskDepend{TaskID: "1"}, + "1": {TaskID: "1"}, }, }, }, @@ -534,21 +534,21 @@ func TestCheckRunConfig(t *testing.T) { ID: "1", Level: -1, Depends: map[string]*rstypes.RunConfigTaskDepend{ - "2": &rstypes.RunConfigTaskDepend{TaskID: "2"}, + "2": {TaskID: "2"}, }, }, { ID: "2", Level: -1, Depends: map[string]*rstypes.RunConfigTaskDepend{ - "3": &rstypes.RunConfigTaskDepend{TaskID: "3"}, + "3": {TaskID: "3"}, }, }, { ID: "3", Level: -1, Depends: map[string]*rstypes.RunConfigTaskDepend{ - "1": &rstypes.RunConfigTaskDepend{TaskID: "1"}, + "1": {TaskID: "1"}, }, }, }, @@ -567,21 +567,21 @@ func TestCheckRunConfig(t *testing.T) { ID: "1", Level: -1, Depends: map[string]*rstypes.RunConfigTaskDepend{ - "2": &rstypes.RunConfigTaskDepend{TaskID: "2"}, + "2": {TaskID: "2"}, }, }, { ID: "2", Level: -1, Depends: map[string]*rstypes.RunConfigTaskDepend{ - "3": &rstypes.RunConfigTaskDepend{TaskID: "3"}, + "3": {TaskID: "3"}, }, }, { ID: "3", Level: -1, Depends: map[string]*rstypes.RunConfigTaskDepend{ - "2": &rstypes.RunConfigTaskDepend{TaskID: "2"}, + "2": {TaskID: "2"}, }, }, }, @@ -603,15 +603,15 @@ func TestCheckRunConfig(t *testing.T) { ID: "2", Level: -1, Depends: map[string]*rstypes.RunConfigTaskDepend{ - "1": &rstypes.RunConfigTaskDepend{TaskID: "1"}, + "1": {TaskID: "1"}, }, }, { ID: "3", Level: -1, Depends: map[string]*rstypes.RunConfigTaskDepend{ - "2": &rstypes.RunConfigTaskDepend{TaskID: "2"}, - "1": &rstypes.RunConfigTaskDepend{TaskID: "1"}, + "2": {TaskID: "2"}, + "1": {TaskID: "1"}, }, }, }, @@ -628,22 +628,22 @@ func TestCheckRunConfig(t *testing.T) { ID: "2", Level: -1, Depends: map[string]*rstypes.RunConfigTaskDepend{ - "1": &rstypes.RunConfigTaskDepend{TaskID: "1"}, + "1": {TaskID: "1"}, }, }, { ID: "3", Level: -1, Depends: map[string]*rstypes.RunConfigTaskDepend{ - "2": &rstypes.RunConfigTaskDepend{TaskID: "2"}, + "2": {TaskID: "2"}, }, }, { ID: "4", Level: -1, Depends: map[string]*rstypes.RunConfigTaskDepend{ - "3": &rstypes.RunConfigTaskDepend{TaskID: "3"}, - "1": &rstypes.RunConfigTaskDepend{TaskID: "1"}, + "3": {TaskID: "3"}, + "1": {TaskID: "1"}, }, }, }, @@ -694,7 +694,7 @@ func TestGenRunConfig(t *testing.T) { name: "test runconfig generation", in: &config.Config{ Runs: []*config.Run{ - &config.Run{ + { Name: "run01", DockerRegistriesAuth: map[string]*config.DockerRegistryAuth{ "index.docker.io": { @@ -704,7 +704,7 @@ func TestGenRunConfig(t *testing.T) { }, }, Tasks: []*config.Task{ - &config.Task{ + { Name: "task01", DockerRegistriesAuth: map[string]*config.DockerRegistryAuth{ "index.docker.io": { @@ -717,19 +717,19 @@ func TestGenRunConfig(t *testing.T) { 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"}, + "ENV01": {Type: config.ValueTypeString, Value: "ENV01"}, + "ENVFROMVARIABLE01": {Type: config.ValueTypeFromVariable, Value: "variable01"}, }, User: "", 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)}, }, @@ -738,8 +738,8 @@ func TestGenRunConfig(t *testing.T) { }, }, Environment: map[string]config.Value{ - "ENV01": config.Value{Type: config.ValueTypeString, Value: "ENV01"}, - "ENVFROMVARIABLE01": config.Value{Type: config.ValueTypeFromVariable, Value: "variable01"}, + "ENV01": {Type: config.ValueTypeString, Value: "ENV01"}, + "ENVFROMVARIABLE01": {Type: config.ValueTypeFromVariable, Value: "variable01"}, }, WorkingDir: "", Shell: "", @@ -766,8 +766,8 @@ func TestGenRunConfig(t *testing.T) { }, Command: "command03", Environment: map[string]config.Value{ - "ENV01": config.Value{Type: config.ValueTypeString, Value: "ENV01"}, - "ENVFROMVARIABLE01": config.Value{Type: config.ValueTypeFromVariable, Value: "variable01"}, + "ENV01": {Type: config.ValueTypeString, Value: "ENV01"}, + "ENVFROMVARIABLE01": {Type: config.ValueTypeFromVariable, Value: "variable01"}, }, }, }, @@ -793,7 +793,7 @@ func TestGenRunConfig(t *testing.T) { "registry_username": "yourregistryusername", }, out: map[string]*rstypes.RunConfigTask{ - uuid.New("task01").String(): &rstypes.RunConfigTask{ + uuid.New("task01").String(): { ID: uuid.New("task01").String(), Name: "task01", Depends: map[string]*rstypes.RunConfigTaskDepend{}, DockerRegistriesAuth: map[string]rstypes.DockerRegistryAuth{ @@ -812,11 +812,11 @@ func TestGenRunConfig(t *testing.T) { "ENVFROMVARIABLE01": "VARVALUE01", }, Volumes: []rstypes.Volume{ - rstypes.Volume{ + { Path: "/mnt/vol01", TmpFS: &rstypes.VolumeTmpFS{}, }, - rstypes.Volume{ + { Path: "/mnt/vol01", TmpFS: &rstypes.VolumeTmpFS{Size: 1024 * 1024 * 1024}, }, @@ -842,7 +842,7 @@ func TestGenRunConfig(t *testing.T) { name: "test run auth used for task undefined auth", in: &config.Config{ Runs: []*config.Run{ - &config.Run{ + { Name: "run01", DockerRegistriesAuth: map[string]*config.DockerRegistryAuth{ "index.docker.io": { @@ -852,13 +852,13 @@ func TestGenRunConfig(t *testing.T) { }, }, Tasks: []*config.Task{ - &config.Task{ + { Name: "task01", Runtime: &config.Runtime{ Type: "pod", Arch: "", Containers: []*config.Container{ - &config.Container{ + { Image: "image01", }, }, @@ -882,7 +882,7 @@ func TestGenRunConfig(t *testing.T) { "password": "yourregistrypassword", }, out: map[string]*rstypes.RunConfigTask{ - uuid.New("task01").String(): &rstypes.RunConfigTask{ + uuid.New("task01").String(): { ID: uuid.New("task01").String(), Name: "task01", Depends: map[string]*rstypes.RunConfigTaskDepend{}, DockerRegistriesAuth: map[string]rstypes.DockerRegistryAuth{ @@ -913,7 +913,7 @@ func TestGenRunConfig(t *testing.T) { name: "test run auth override by task auth", in: &config.Config{ Runs: []*config.Run{ - &config.Run{ + { Name: "run01", DockerRegistriesAuth: map[string]*config.DockerRegistryAuth{ "index.docker.io": { @@ -928,7 +928,7 @@ func TestGenRunConfig(t *testing.T) { }, }, Tasks: []*config.Task{ - &config.Task{ + { Name: "task01", DockerRegistriesAuth: map[string]*config.DockerRegistryAuth{ "index.docker.io": { @@ -946,7 +946,7 @@ func TestGenRunConfig(t *testing.T) { Type: "pod", Arch: "", Containers: []*config.Container{ - &config.Container{ + { Image: "image01", }, }, @@ -971,7 +971,7 @@ func TestGenRunConfig(t *testing.T) { "password": "myregistrypassword", }, out: map[string]*rstypes.RunConfigTask{ - uuid.New("task01").String(): &rstypes.RunConfigTask{ + uuid.New("task01").String(): { ID: uuid.New("task01").String(), Name: "task01", Depends: map[string]*rstypes.RunConfigTaskDepend{}, DockerRegistriesAuth: map[string]rstypes.DockerRegistryAuth{ @@ -1012,28 +1012,28 @@ func TestGenRunConfig(t *testing.T) { name: "test run task depends on_skipped", in: &config.Config{ Runs: []*config.Run{ - &config.Run{ + { Name: "run01", Tasks: []*config.Task{ - &config.Task{ + { Name: "task01", Runtime: &config.Runtime{ Type: "pod", Arch: "", Containers: []*config.Container{ - &config.Container{ + { Image: "image01", }, }, }, }, - &config.Task{ + { Name: "task02", Runtime: &config.Runtime{ Type: "pod", Arch: "", Containers: []*config.Container{ - &config.Container{ + { Image: "image01", }, }, @@ -1052,7 +1052,7 @@ func TestGenRunConfig(t *testing.T) { }, }, out: map[string]*rstypes.RunConfigTask{ - uuid.New("task01").String(): &rstypes.RunConfigTask{ + uuid.New("task01").String(): { ID: uuid.New("task01").String(), Name: "task01", Depends: map[string]*rstypes.RunConfigTaskDepend{}, Runtime: &rstypes.Runtime{Type: rstypes.RuntimeType("pod"), @@ -1069,11 +1069,11 @@ func TestGenRunConfig(t *testing.T) { Environment: map[string]string{}, Steps: rstypes.Steps{}, }, - uuid.New("task02").String(): &rstypes.RunConfigTask{ + uuid.New("task02").String(): { ID: uuid.New("task02").String(), Name: "task02", Depends: map[string]*rstypes.RunConfigTaskDepend{ - uuid.New("task01").String(): &rstypes.RunConfigTaskDepend{ + uuid.New("task01").String(): { TaskID: uuid.New("task01").String(), Conditions: []rstypes.RunConfigTaskDependCondition{rstypes.RunConfigTaskDependConditionOnSkipped}, }, @@ -1104,16 +1104,16 @@ func TestGenRunConfig(t *testing.T) { }, }, Runs: []*config.Run{ - &config.Run{ + { Name: "run01", Tasks: []*config.Task{ - &config.Task{ + { Name: "task01", Runtime: &config.Runtime{ Type: "pod", Arch: "", Containers: []*config.Container{ - &config.Container{ + { Image: "image01", }, }, @@ -1129,7 +1129,7 @@ func TestGenRunConfig(t *testing.T) { }, }, out: map[string]*rstypes.RunConfigTask{ - uuid.New("task01").String(): &rstypes.RunConfigTask{ + uuid.New("task01").String(): { ID: uuid.New("task01").String(), Name: "task01", Depends: map[string]*rstypes.RunConfigTaskDepend{}, DockerRegistriesAuth: map[string]rstypes.DockerRegistryAuth{ @@ -1164,7 +1164,7 @@ func TestGenRunConfig(t *testing.T) { }, }, Runs: []*config.Run{ - &config.Run{ + { Name: "run01", DockerRegistriesAuth: map[string]*config.DockerRegistryAuth{ "index.docker.io": { @@ -1173,13 +1173,13 @@ func TestGenRunConfig(t *testing.T) { }, }, Tasks: []*config.Task{ - &config.Task{ + { Name: "task01", Runtime: &config.Runtime{ Type: "pod", Arch: "", Containers: []*config.Container{ - &config.Container{ + { Image: "image01", }, }, @@ -1195,7 +1195,7 @@ func TestGenRunConfig(t *testing.T) { }, }, out: map[string]*rstypes.RunConfigTask{ - uuid.New("task01").String(): &rstypes.RunConfigTask{ + uuid.New("task01").String(): { ID: uuid.New("task01").String(), Name: "task01", Depends: map[string]*rstypes.RunConfigTaskDepend{}, DockerRegistriesAuth: map[string]rstypes.DockerRegistryAuth{ @@ -1230,7 +1230,7 @@ func TestGenRunConfig(t *testing.T) { }, }, Runs: []*config.Run{ - &config.Run{ + { Name: "run01", DockerRegistriesAuth: map[string]*config.DockerRegistryAuth{ "index.docker.io": { @@ -1239,7 +1239,7 @@ func TestGenRunConfig(t *testing.T) { }, }, Tasks: []*config.Task{ - &config.Task{ + { Name: "task01", DockerRegistriesAuth: map[string]*config.DockerRegistryAuth{ "index.docker.io": { @@ -1251,7 +1251,7 @@ func TestGenRunConfig(t *testing.T) { Type: "pod", Arch: "", Containers: []*config.Container{ - &config.Container{ + { Image: "image01", }, }, @@ -1267,7 +1267,7 @@ func TestGenRunConfig(t *testing.T) { }, }, out: map[string]*rstypes.RunConfigTask{ - uuid.New("task01").String(): &rstypes.RunConfigTask{ + uuid.New("task01").String(): { ID: uuid.New("task01").String(), Name: "task01", Depends: map[string]*rstypes.RunConfigTaskDepend{}, DockerRegistriesAuth: map[string]rstypes.DockerRegistryAuth{ @@ -1296,7 +1296,7 @@ func TestGenRunConfig(t *testing.T) { name: "test runconfig generation with encoded value type", in: &config.Config{ Runs: []*config.Run{ - &config.Run{ + { Name: "run01", DockerRegistriesAuth: map[string]*config.DockerRegistryAuth{ "index.docker.io": { @@ -1305,7 +1305,7 @@ func TestGenRunConfig(t *testing.T) { }, }, Tasks: []*config.Task{ - &config.Task{ + { Name: "task01", DockerRegistriesAuth: map[string]*config.DockerRegistryAuth{ "index.docker.io": { @@ -1316,7 +1316,7 @@ func TestGenRunConfig(t *testing.T) { Runtime: &config.Runtime{ Type: "pod", Containers: []*config.Container{ - &config.Container{ + { Image: "image01", User: "", }, @@ -1334,7 +1334,7 @@ func TestGenRunConfig(t *testing.T) { "auth": "eW91cnJlZ2lzdHJ5dXNlcm5hbWU6cGFzc3dvcmQy", }, out: map[string]*rstypes.RunConfigTask{ - uuid.New("task01").String(): &rstypes.RunConfigTask{ + uuid.New("task01").String(): { ID: uuid.New("task01").String(), Name: "task01", Depends: map[string]*rstypes.RunConfigTaskDepend{}, DockerRegistriesAuth: map[string]rstypes.DockerRegistryAuth{ @@ -1363,16 +1363,16 @@ func TestGenRunConfig(t *testing.T) { name: "test runconfig generation task timeout global", in: &config.Config{ Runs: []*config.Run{ - &config.Run{ + { Name: "run01", Tasks: []*config.Task{ - &config.Task{ + { Name: "task01", Runtime: &config.Runtime{ Type: "pod", Arch: "", Containers: []*config.Container{ - &config.Container{ + { Image: "image01", }, }, @@ -1389,7 +1389,7 @@ func TestGenRunConfig(t *testing.T) { TaskTimeoutInterval: &types.Duration{Duration: 10 * time.Second}, }, out: map[string]*rstypes.RunConfigTask{ - uuid.New("task01").String(): &rstypes.RunConfigTask{ + uuid.New("task01").String(): { ID: uuid.New("task01").String(), Name: "task01", Depends: map[string]*rstypes.RunConfigTaskDepend{}, DockerRegistriesAuth: map[string]rstypes.DockerRegistryAuth{}, @@ -1414,16 +1414,16 @@ func TestGenRunConfig(t *testing.T) { name: "test global task timeout override by run", in: &config.Config{ Runs: []*config.Run{ - &config.Run{ + { Name: "run01", Tasks: []*config.Task{ - &config.Task{ + { Name: "task01", Runtime: &config.Runtime{ Type: "pod", Arch: "", Containers: []*config.Container{ - &config.Container{ + { Image: "image01", }, }, @@ -1441,7 +1441,7 @@ func TestGenRunConfig(t *testing.T) { TaskTimeoutInterval: &types.Duration{Duration: 10 * time.Second}, }, out: map[string]*rstypes.RunConfigTask{ - uuid.New("task01").String(): &rstypes.RunConfigTask{ + uuid.New("task01").String(): { ID: uuid.New("task01").String(), Name: "task01", Depends: map[string]*rstypes.RunConfigTaskDepend{}, DockerRegistriesAuth: map[string]rstypes.DockerRegistryAuth{}, @@ -1466,17 +1466,17 @@ func TestGenRunConfig(t *testing.T) { name: "test global task timeout override by task", in: &config.Config{ Runs: []*config.Run{ - &config.Run{ + { Name: "run01", Tasks: []*config.Task{ - &config.Task{ + { Name: "task01", TaskTimeoutInterval: &types.Duration{Duration: 20 * time.Second}, Runtime: &config.Runtime{ Type: "pod", Arch: "", Containers: []*config.Container{ - &config.Container{ + { Image: "image01", }, }, @@ -1494,7 +1494,7 @@ func TestGenRunConfig(t *testing.T) { TaskTimeoutInterval: &types.Duration{Duration: 10 * time.Second}, }, out: map[string]*rstypes.RunConfigTask{ - uuid.New("task01").String(): &rstypes.RunConfigTask{ + uuid.New("task01").String(): { ID: uuid.New("task01").String(), Name: "task01", Depends: map[string]*rstypes.RunConfigTaskDepend{}, DockerRegistriesAuth: map[string]rstypes.DockerRegistryAuth{}, diff --git a/internal/services/runservice/scheduler_test.go b/internal/services/runservice/scheduler_test.go index bd6614bec..9dff4c8cc 100644 --- a/internal/services/runservice/scheduler_test.go +++ b/internal/services/runservice/scheduler_test.go @@ -31,7 +31,7 @@ func TestAdvanceRunTasks(t *testing.T) { // a global run config for all tests rc := &types.RunConfig{ Tasks: map[string]*types.RunConfigTask{ - "task01": &types.RunConfigTask{ + "task01": { ID: "task01", Name: "task01", Depends: map[string]*types.RunConfigTaskDepend{}, @@ -42,11 +42,11 @@ func TestAdvanceRunTasks(t *testing.T) { Steps: types.Steps{}, Skip: false, }, - "task02": &types.RunConfigTask{ + "task02": { ID: "task02", Name: "task02", Depends: map[string]*types.RunConfigTaskDepend{ - "task01": &types.RunConfigTaskDepend{TaskID: "task01", Conditions: []types.RunConfigTaskDependCondition{types.RunConfigTaskDependConditionOnSuccess}}, + "task01": {TaskID: "task01", Conditions: []types.RunConfigTaskDependCondition{types.RunConfigTaskDependConditionOnSuccess}}, }, Runtime: &types.Runtime{Type: types.RuntimeType("pod"), Containers: []*types.Container{{Image: "image01"}}, @@ -55,7 +55,7 @@ func TestAdvanceRunTasks(t *testing.T) { Steps: types.Steps{}, Skip: false, }, - "task03": &types.RunConfigTask{ + "task03": { ID: "task03", Name: "task03", Depends: map[string]*types.RunConfigTaskDepend{}, @@ -66,7 +66,7 @@ func TestAdvanceRunTasks(t *testing.T) { Steps: types.Steps{}, Skip: false, }, - "task04": &types.RunConfigTask{ + "task04": { ID: "task04", Name: "task04", Depends: map[string]*types.RunConfigTaskDepend{}, @@ -77,12 +77,12 @@ func TestAdvanceRunTasks(t *testing.T) { Steps: types.Steps{}, Skip: false, }, - "task05": &types.RunConfigTask{ + "task05": { ID: "task05", Name: "task05", Depends: map[string]*types.RunConfigTaskDepend{ - "task03": &types.RunConfigTaskDepend{TaskID: "task03", Conditions: []types.RunConfigTaskDependCondition{types.RunConfigTaskDependConditionOnSuccess}}, - "task04": &types.RunConfigTaskDepend{TaskID: "task04", Conditions: []types.RunConfigTaskDependCondition{types.RunConfigTaskDependConditionOnSuccess}}, + "task03": {TaskID: "task03", Conditions: []types.RunConfigTaskDependCondition{types.RunConfigTaskDependConditionOnSuccess}}, + "task04": {TaskID: "task04", Conditions: []types.RunConfigTaskDependCondition{types.RunConfigTaskDependConditionOnSuccess}}, }, Runtime: &types.Runtime{Type: types.RuntimeType("pod"), Containers: []*types.Container{{Image: "image01"}}, @@ -103,23 +103,23 @@ func TestAdvanceRunTasks(t *testing.T) { Phase: types.RunPhaseRunning, Result: types.RunResultUnknown, Tasks: map[string]*types.RunTask{ - "task01": &types.RunTask{ + "task01": { ID: "task01", Status: types.RunTaskStatusNotStarted, }, - "task02": &types.RunTask{ + "task02": { ID: "task02", Status: types.RunTaskStatusNotStarted, }, - "task03": &types.RunTask{ + "task03": { ID: "task03", Status: types.RunTaskStatusNotStarted, }, - "task04": &types.RunTask{ + "task04": { ID: "task04", Status: types.RunTaskStatusNotStarted, }, - "task05": &types.RunTask{ + "task05": { ID: "task05", Status: types.RunTaskStatusNotStarted, }, @@ -418,7 +418,7 @@ func TestGetTasksToRun(t *testing.T) { // a global run config for all tests rc := &types.RunConfig{ Tasks: map[string]*types.RunConfigTask{ - "task01": &types.RunConfigTask{ + "task01": { ID: "task01", Name: "task01", Depends: map[string]*types.RunConfigTaskDepend{}, @@ -429,11 +429,11 @@ func TestGetTasksToRun(t *testing.T) { Steps: types.Steps{}, Skip: false, }, - "task02": &types.RunConfigTask{ + "task02": { ID: "task02", Name: "task02", Depends: map[string]*types.RunConfigTaskDepend{ - "task01": &types.RunConfigTaskDepend{TaskID: "task01", Conditions: []types.RunConfigTaskDependCondition{types.RunConfigTaskDependConditionOnSuccess}}, + "task01": {TaskID: "task01", Conditions: []types.RunConfigTaskDependCondition{types.RunConfigTaskDependConditionOnSuccess}}, }, Runtime: &types.Runtime{Type: types.RuntimeType("pod"), Containers: []*types.Container{{Image: "image01"}}, @@ -442,7 +442,7 @@ func TestGetTasksToRun(t *testing.T) { Steps: types.Steps{}, Skip: false, }, - "task03": &types.RunConfigTask{ + "task03": { ID: "task03", Name: "task03", Depends: map[string]*types.RunConfigTaskDepend{}, @@ -453,7 +453,7 @@ func TestGetTasksToRun(t *testing.T) { Steps: types.Steps{}, Skip: false, }, - "task04": &types.RunConfigTask{ + "task04": { ID: "task04", Name: "task04", Runtime: &types.Runtime{Type: types.RuntimeType("pod"), @@ -463,12 +463,12 @@ func TestGetTasksToRun(t *testing.T) { Steps: types.Steps{}, Skip: false, }, - "task05": &types.RunConfigTask{ + "task05": { ID: "task05", Name: "task05", Depends: map[string]*types.RunConfigTaskDepend{ - "task03": &types.RunConfigTaskDepend{TaskID: "task03", Conditions: []types.RunConfigTaskDependCondition{types.RunConfigTaskDependConditionOnSuccess}}, - "task04": &types.RunConfigTaskDepend{TaskID: "task04", Conditions: []types.RunConfigTaskDependCondition{types.RunConfigTaskDependConditionOnSuccess}}, + "task03": {TaskID: "task03", Conditions: []types.RunConfigTaskDependCondition{types.RunConfigTaskDependConditionOnSuccess}}, + "task04": {TaskID: "task04", Conditions: []types.RunConfigTaskDependCondition{types.RunConfigTaskDependConditionOnSuccess}}, }, Runtime: &types.Runtime{Type: types.RuntimeType("pod"), Containers: []*types.Container{{Image: "image01"}}, @@ -485,23 +485,23 @@ func TestGetTasksToRun(t *testing.T) { // generated by command.genRun() run := &types.Run{ Tasks: map[string]*types.RunTask{ - "task01": &types.RunTask{ + "task01": { ID: "task01", Status: types.RunTaskStatusNotStarted, }, - "task02": &types.RunTask{ + "task02": { ID: "task02", Status: types.RunTaskStatusNotStarted, }, - "task03": &types.RunTask{ + "task03": { ID: "task03", Status: types.RunTaskStatusNotStarted, }, - "task04": &types.RunTask{ + "task04": { ID: "task04", Status: types.RunTaskStatusNotStarted, }, - "task05": &types.RunTask{ + "task05": { ID: "task05", Status: types.RunTaskStatusNotStarted, }, diff --git a/tests/setup_test.go b/tests/setup_test.go index 8484fb16f..85ac94d5d 100644 --- a/tests/setup_test.go +++ b/tests/setup_test.go @@ -433,7 +433,7 @@ func (sc *setupContext) startAgola() error { go func() { err := <-tagola.errCh if err != nil { - panic(errors.Wrap(err, "agola component returned error: %w")) + panic(errors.Wrap(err, "agola component returned error")) } }() @@ -1602,7 +1602,7 @@ func TestPullRequest(t *testing.T) { secret, _, err := gwClient.CreateProjectSecret(context.TODO(), project.ID, sreq) if err != nil { - t.Fatal("failed to create project secret: %w", err) + t.Fatalf("failed to create project secret: %v", err) } // create project variable @@ -1619,7 +1619,7 @@ func TestPullRequest(t *testing.T) { _, _, err = gwClient.CreateProjectVariable(context.TODO(), project.ID, vreq) if err != nil { - t.Fatal("failed to create project variable: %w", err) + t.Fatalf("failed to create project variable: %v", err) } if tt.prFromSameRepo { @@ -1633,7 +1633,7 @@ func TestPullRequest(t *testing.T) { } _, err = giteaClient.CreatePullRequest(giteaUser01, "repo01", prOpts) if err != nil { - t.Fatal("failed to create pull request: %w", err) + t.Fatalf("failed to create pull request: %v", err) } } else { // create PR from forked repo @@ -1647,7 +1647,7 @@ func TestPullRequest(t *testing.T) { } _, err := giteaClient.AdminCreateUser(userOpts) if err != nil { - t.Fatal("failed to create user02: %w", err) + t.Fatalf("failed to create user02: %v", err) } giteaClient.SetBasicAuth(giteaUser02, "password") @@ -1659,7 +1659,7 @@ func TestPullRequest(t *testing.T) { giteaUser02Client := gitea.NewClient(giteaAPIURL, giteaUser02Token.Token) giteaForkedRepo, err := giteaUser02Client.CreateFork(giteaUser01, "repo01", gitea.CreateForkOption{}) if err != nil { - t.Fatal("failed to fork repo01: %w", err) + t.Fatalf("failed to fork repo01: %v", err) } gitfs := memfs.New() @@ -1719,7 +1719,7 @@ func TestPullRequest(t *testing.T) { } _, err = giteaUser02Client.CreatePullRequest(giteaUser01, "repo01", prOpts) if err != nil { - t.Fatal("failed to create pull request: %w", err) + t.Fatalf("failed to create pull request: %v", err) } } _ = testutil.Wait(30*time.Second, func() (bool, error) {