From c507e7fc077cb6321929643fb3b8b0d963988bf4 Mon Sep 17 00:00:00 2001 From: Grigoriy Mikhalkin Date: Tue, 25 Jan 2022 12:02:44 +0100 Subject: [PATCH] fixed All bahavior and added Active method --- cmdutils/switches/switches.go | 14 +++++++++++++- cmdutils/switches/switches_test.go | 11 +++++++++-- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/cmdutils/switches/switches.go b/cmdutils/switches/switches.go index 331c871..1eedd54 100644 --- a/cmdutils/switches/switches.go +++ b/cmdutils/switches/switches.go @@ -121,13 +121,25 @@ func (s *Switches) Enabled(name string) bool { // All returns names of all items set in settings func (s *Switches) All() sets.String { names := sets.NewString() - for k := range s.settings { + for k := range s.defaults { names.Insert(k) } return names } +// Active returns names of all active items +func (s *Switches) Active() sets.String { + names := sets.NewString() + for k, enabled := range s.settings { + if enabled { + names.Insert(k) + } + } + + return names +} + // EnabledByDefault returns names of all enabled items func (s *Switches) EnabledByDefault() sets.String { names := sets.NewString() diff --git a/cmdutils/switches/switches_test.go b/cmdutils/switches/switches_test.go index 9e65f4a..445df99 100644 --- a/cmdutils/switches/switches_test.go +++ b/cmdutils/switches/switches_test.go @@ -31,12 +31,19 @@ var _ = Describe("CMD Switches", func() { Expect(s.Enabled("runner-b")).To(BeFalse()) }) It("should return all items", func() { - s := New("runner-a", "runner-b") + s := New("runner-a", "runner-b", Disable("runner-c")) Expect(s.Set("*,-runner-b")).ToNot(HaveOccurred()) - expected := sets.NewString("runner-a", "runner-b") + expected := sets.NewString("runner-a", "runner-b", "runner-c") Expect(s.All()).To(Equal(expected)) }) + It("should return only active items", func() { + s := New("runner-a", "runner-b", Disable("runner-c")) + Expect(s.Set("*,-runner-b")).ToNot(HaveOccurred()) + + expected := sets.NewString("runner-a") + Expect(s.Active()).To(Equal(expected)) + }) It("should return all enabled items", func() { s := New("runner-a", Disable("runner-b"))