From c50fdf16c95e30198f2f94fea0e4278fc56b196b Mon Sep 17 00:00:00 2001 From: Lucas Lee Date: Fri, 3 Jun 2022 11:33:39 +0800 Subject: [PATCH 1/2] added main.goconvey --- web/server/watch/functional_core.go | 12 ++++++ web/server/watch/functional_core_test.go | 49 ++++++++++++++++++++++++ 2 files changed, 61 insertions(+) diff --git a/web/server/watch/functional_core.go b/web/server/watch/functional_core.go index 404a25d3..70292f66 100644 --- a/web/server/watch/functional_core.go +++ b/web/server/watch/functional_core.go @@ -2,6 +2,7 @@ package watch import ( "os" + "path" "path/filepath" "strings" @@ -114,9 +115,20 @@ func LimitDepth(folders messaging.Folders, depth int) { /////////////////////////////////////////////////////////////////////////////// func AttachProfiles(folders messaging.Folders, items []*FileSystemItem) { + var rootProfile *FileSystemItem + for _, profile := range items { + path, _ := path.Split(profile.Path) + if path == profile.Root && profile.Name == "main.goconvey" { + rootProfile = profile + break + } + } + for _, profile := range items { if folder, exists := folders[filepath.Dir(profile.Path)]; exists { folder.Disabled, folder.BuildTags, folder.TestArguments = profile.ProfileDisabled, profile.ProfileTags, profile.ProfileArguments + } else if rootProfile != nil { + folder.Disabled, folder.BuildTags, folder.TestArguments = rootProfile.ProfileDisabled, rootProfile.ProfileTags, rootProfile.ProfileArguments } } } diff --git a/web/server/watch/functional_core_test.go b/web/server/watch/functional_core_test.go index b610a030..1940a18b 100644 --- a/web/server/watch/functional_core_test.go +++ b/web/server/watch/functional_core_test.go @@ -337,6 +337,55 @@ func TestAttachProfiles(t *testing.T) { }) } +func TestAttachMainProfiles(t *testing.T) { + Convey("Subject: Attaching profile information to a folder", t, func() { + folders := map[string]*messaging.Folder{ + "/root": { + Path: "/root", + Root: "/root", + }, + "/root/1": { + Path: "/root/1", + Root: "/root", + }, + "/root/1/2": { + Path: "/root/1/2", + Root: "/root", + }, + } + + profiles := []*FileSystemItem{ + { + Path: "/root/main.goconvey", + ProfileDisabled: true, + ProfileArguments: []string{"1"}, + }, + { + Path: "/root/1/2/hi.goconvey", + ProfileDisabled: true, + ProfileArguments: []string{"1", "2"}, + }, + } + + Convey("Main profiles at root should be merged with all folders without folder profile", func() { + AttachProfiles(folders, profiles) + + Convey("Main profiles matched the all other folder", func() { + So(folders["/root"].Disabled, ShouldBeTrue) + So(folders["/root"].TestArguments, ShouldResemble, []string{"1"}) + + So(folders["/root/1"].Disabled, ShouldBeTrue) + So(folders["/root/1"].TestArguments, ShouldResemble, []string{"1"}) + }) + + Convey("The second folder should match the first profile", func() { + So(folders["/root/1/2"].Disabled, ShouldBeTrue) + So(folders["/root/1/2"].TestArguments, ShouldResemble, []string{"1", "2"}) + }) + }) + }) +} + func TestMarkIgnored(t *testing.T) { Convey("Subject: folders that have been ignored should be marked as such", t, func() { folders := map[string]*messaging.Folder{ From d3ecc51f32e78997abe16720dfcfc8fd5272a53d Mon Sep 17 00:00:00 2001 From: Lucas Lee Date: Fri, 3 Jun 2022 13:06:19 +0800 Subject: [PATCH 2/2] fix issue: folder will not add profile is he has no profile --- web/server/watch/functional_core.go | 12 +++++++++--- web/server/watch/functional_core_test.go | 14 +++++++++----- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/web/server/watch/functional_core.go b/web/server/watch/functional_core.go index 70292f66..1033b05e 100644 --- a/web/server/watch/functional_core.go +++ b/web/server/watch/functional_core.go @@ -117,18 +117,24 @@ func LimitDepth(folders messaging.Folders, depth int) { func AttachProfiles(folders messaging.Folders, items []*FileSystemItem) { var rootProfile *FileSystemItem for _, profile := range items { - path, _ := path.Split(profile.Path) + path := path.Dir(profile.Path) if path == profile.Root && profile.Name == "main.goconvey" { rootProfile = profile break } } + // put root profile to all folders + if rootProfile != nil { + for _, folder := range folders { + folder.Disabled, folder.BuildTags, folder.TestArguments = rootProfile.ProfileDisabled, rootProfile.ProfileTags, rootProfile.ProfileArguments + } + } + + // use folder profile to replace root profile for _, profile := range items { if folder, exists := folders[filepath.Dir(profile.Path)]; exists { folder.Disabled, folder.BuildTags, folder.TestArguments = profile.ProfileDisabled, profile.ProfileTags, profile.ProfileArguments - } else if rootProfile != nil { - folder.Disabled, folder.BuildTags, folder.TestArguments = rootProfile.ProfileDisabled, rootProfile.ProfileTags, rootProfile.ProfileArguments } } } diff --git a/web/server/watch/functional_core_test.go b/web/server/watch/functional_core_test.go index 1940a18b..563d859d 100644 --- a/web/server/watch/functional_core_test.go +++ b/web/server/watch/functional_core_test.go @@ -356,13 +356,17 @@ func TestAttachMainProfiles(t *testing.T) { profiles := []*FileSystemItem{ { + Root: "/root", + Name: "main.goconvey", Path: "/root/main.goconvey", - ProfileDisabled: true, + ProfileDisabled: false, ProfileArguments: []string{"1"}, }, { + Root: "/root", + Name: "hi.goconvey", Path: "/root/1/2/hi.goconvey", - ProfileDisabled: true, + ProfileDisabled: false, ProfileArguments: []string{"1", "2"}, }, } @@ -371,15 +375,15 @@ func TestAttachMainProfiles(t *testing.T) { AttachProfiles(folders, profiles) Convey("Main profiles matched the all other folder", func() { - So(folders["/root"].Disabled, ShouldBeTrue) + So(folders["/root"].Disabled, ShouldBeFalse) So(folders["/root"].TestArguments, ShouldResemble, []string{"1"}) - So(folders["/root/1"].Disabled, ShouldBeTrue) + So(folders["/root/1"].Disabled, ShouldBeFalse) So(folders["/root/1"].TestArguments, ShouldResemble, []string{"1"}) }) Convey("The second folder should match the first profile", func() { - So(folders["/root/1/2"].Disabled, ShouldBeTrue) + So(folders["/root/1/2"].Disabled, ShouldBeFalse) So(folders["/root/1/2"].TestArguments, ShouldResemble, []string{"1", "2"}) }) })