From a914bcd96c503f365a47206e3414b02bbe97eb4b Mon Sep 17 00:00:00 2001 From: Anton Rigin Date: Fri, 15 Apr 2022 17:58:09 +0300 Subject: [PATCH] Fix distbuild watch folders (squashed) --- .deadlines.yml | 6 ++-- tools/testtool/commands/deadlines.go | 2 +- tools/testtool/commands/deadlines_test.go | 35 ++++++++++++++++--- .../testdata/deadlines/.deadlines.yml | 15 ++++++++ 4 files changed, 50 insertions(+), 8 deletions(-) create mode 100644 tools/testtool/testdata/deadlines/.deadlines.yml diff --git a/.deadlines.yml b/.deadlines.yml index 5f8d107..9cd2ee2 100644 --- a/.deadlines.yml +++ b/.deadlines.yml @@ -25,15 +25,15 @@ - task: tarstreamtest score: 100 watch: - - distbuild + - distbuild/pkg/tarstream - task: filecachetest score: 100 watch: - - distbuild + - distbuild/pkg/filecache - task: artifacttest score: 100 watch: - - distbuild + - distbuild/pkg/artifact - group: Generics start: 08-04-2022 21:00 diff --git a/tools/testtool/commands/deadlines.go b/tools/testtool/commands/deadlines.go index ff33b14..a168029 100644 --- a/tools/testtool/commands/deadlines.go +++ b/tools/testtool/commands/deadlines.go @@ -97,7 +97,7 @@ func findChangedTasks(d Deadlines, files []string) []string { for _, task := range d.Tasks() { for _, path := range task.Watch { - if components[0] == path { + if strings.HasPrefix(f, path) { tasks[task.Name] = struct{}{} } } diff --git a/tools/testtool/commands/deadlines_test.go b/tools/testtool/commands/deadlines_test.go index 96f9192..7fa8430 100644 --- a/tools/testtool/commands/deadlines_test.go +++ b/tools/testtool/commands/deadlines_test.go @@ -17,9 +17,36 @@ func TestDeadlines(t *testing.T) { } func TestDetectChange(t *testing.T) { - d, err := loadDeadlines("../../../.deadlines.yml") - require.NoError(t, err) + for _, tc := range []struct { + name string + deadlines string + changedFiles []string + changedTasks []string + }{ + { + name: "sum", // Original deadlines file with sum task. + deadlines: "../../../.deadlines.yml", + changedFiles: []string{"sum/sum.go", "testtool/foo.go", "README.md"}, + changedTasks: []string{"sum"}, + }, + { + name: "tarstreamtest", // Deadlines file with tarstreamtest task. + deadlines: "../testdata/deadlines/.deadlines.yml", + changedFiles: []string{ + "sum/sum.go", + "testtool/foo.go", + "distbuild/pkg/tarstream/stream.go", + "README.md", + }, + changedTasks: []string{"sum", "tarstreamtest"}, + }, + } { + t.Run(tc.name, func(t *testing.T) { + d, err := loadDeadlines(tc.deadlines) + require.NoError(t, err) - changed := findChangedTasks(d, []string{"sum/sum.go", "testtool/foo.go", "README.md"}) - require.Equal(t, []string{"sum"}, changed) + changed := findChangedTasks(d, tc.changedFiles) + require.Equal(t, tc.changedTasks, changed) + }) + } } diff --git a/tools/testtool/testdata/deadlines/.deadlines.yml b/tools/testtool/testdata/deadlines/.deadlines.yml new file mode 100644 index 0000000..b50124d --- /dev/null +++ b/tools/testtool/testdata/deadlines/.deadlines.yml @@ -0,0 +1,15 @@ +- group: "[HW] Dist Build Blocks" + start: 14-04-2022 17:59 + deadline: 28-04-2022 23:59 + tasks: + - task: tarstreamtest + score: 100 + watch: + - distbuild/pkg/tarstream + +- group: Hello World + start: 10-02-2022 18:00 + deadline: 20-02-2022 23:59 + tasks: + - task: sum + score: 100