diff --git a/core/workflow/aggregatorrole.go b/core/workflow/aggregatorrole.go index f1ae9d7c..9fa89d71 100644 --- a/core/workflow/aggregatorrole.go +++ b/core/workflow/aggregatorrole.go @@ -230,6 +230,11 @@ func (r *aggregatorRole) ProcessTemplates(workflowRepo repos.IRepo, loadSubworkf } r.Roles = enabledRoles + // If there are no roles in the aggregator role, it has no use and should be disabled + if len(r.Roles) == 0 { + r.Enabled = "false" + } + return } diff --git a/core/workflow/aggregatorrole_test.go b/core/workflow/aggregatorrole_test.go new file mode 100644 index 00000000..3f3e1ff3 --- /dev/null +++ b/core/workflow/aggregatorrole_test.go @@ -0,0 +1,72 @@ +package workflow + +import ( + "github.com/AliceO2Group/Control/core/repos" + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" +) + +var _ = Describe("aggregator role", func() { + var _ = Describe("processing templates", func() { + var root Role + var repo repos.Repo + var configStack map[string]string + + BeforeEach(func() { + _, repo, _ = repos.NewRepo("/home/user/git/ControlWorkflows", "", "/var/lib/o2/aliecs/repos") + configStack = make(map[string]string) + }) + + When("an aggregator role is empty", func() { + BeforeEach(func() { + root = &aggregatorRole{ + roleBase{Name: "root", Enabled: "true"}, + aggregator{Roles: []Role{}}, + } + }) + It("should disable itself", func() { + Expect(root.IsEnabled()).To(BeTrue()) + err := root.ProcessTemplates(&repo, nil, configStack) + Expect(err).NotTo(HaveOccurred()) + Expect(root.IsEnabled()).To(BeFalse()) + }) + }) + + When("an aggregator role has only disabled sub-roles", func() { + BeforeEach(func() { + root = &aggregatorRole{ + roleBase{Name: "root", Enabled: "true"}, + aggregator{ + Roles: []Role{&taskRole{roleBase: roleBase{Name: "task1", Enabled: "false"}}}, + }, + } + }) + It("remove the disabled roles and disable itself", func() { + Expect(root.IsEnabled()).To(BeTrue()) + err := root.ProcessTemplates(&repo, nil, configStack) + Expect(err).NotTo(HaveOccurred()) + Expect(root.IsEnabled()).To(BeFalse()) + Expect(root.GetRoles()).Should(BeEmpty()) + }) + }) + + When("an aggregator role has an enabled role", func() { + BeforeEach(func() { + root = &aggregatorRole{ + roleBase{Name: "root", Enabled: "true"}, + aggregator{ + Roles: []Role{&taskRole{roleBase: roleBase{Name: "task1", Enabled: "true"}}}, + }, + } + }) + It("should be enabled", func() { + Expect(root.IsEnabled()).To(BeTrue()) + err := root.ProcessTemplates(&repo, nil, configStack) + Expect(err).NotTo(HaveOccurred()) + Expect(root.IsEnabled()).To(BeTrue()) + Expect(root.GetRoles()).ShouldNot(BeEmpty()) + }) + }) + }) + +}) diff --git a/core/workflow/workflow_test.go b/core/workflow/workflow_test.go index f370b01c..07ce5d69 100644 --- a/core/workflow/workflow_test.go +++ b/core/workflow/workflow_test.go @@ -3,9 +3,14 @@ package workflow import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" + "github.com/spf13/viper" "testing" ) +var _ = BeforeSuite(func() { + viper.Set("config_endpoint", "mock://") +}) + func TestCoreWorkflow(t *testing.T) { RegisterFailHandler(Fail) RunSpecs(t, "Core Workflow Test Suite")