New ๐ŸŒŠ wave for @helm

Commit 9a5e73ed

9a5e73edfa21Merged

Anurag Agarwal <[email protected]> ยท 2 years ago ยท 1 file ยท ~1 modified

Description

Adds tests for reverse method

Details

Commit
9a5e73edfa21
Parent
8f61af101eb9

pkg/release/dependency/graph_test.gomodifiedView file

@@ -120,6 +120,86 @@
120120 s.Require().Error(graph.Build())
121121 }
122122
123+// 1 -> 3 -> 4
124+// 2 /
125+// Reversed
126+// 4 -> 3 -> 1
127+// --------> 2
128+func (s *GraphTestSuite) TestReverse() {
129+ graph := dependency.NewGraph[string, string]()
130+
131+ s.Require().NoError(graph.NewNode("1", "1"))
132+ s.Require().NoError(graph.NewNode("2", "2"))
133+ s.Require().NoError(graph.NewNode("3", "3"))
134+ s.Require().NoError(graph.NewNode("4", "4"))
135+
136+ graph.AddDependency("3", "1")
137+ graph.AddDependency("3", "2")
138+ graph.AddDependency("4", "3")
139+
140+ s.Require().NoError(graph.Build())
141+ graph, err := graph.Reverse()
142+ s.Require().Nil(err)
143+
144+ ch := graph.Run()
145+
146+ s.Require().NotNil(ch)
147+ s.Require().Eventually(func() bool { return len(ch) == 1 }, time.Second, time.Millisecond)
148+ s.Require().Never(func() bool { return len(ch) > 1 }, time.Second, time.Millisecond)
149+ d := <-ch
150+ s.Require().Equal("4", d.Data)
151+ d.SetSucceeded()
152+
153+ s.Require().Eventually(func() bool { return len(ch) == 1 }, time.Second, time.Millisecond)
154+ s.Require().Never(func() bool { return len(ch) > 1 }, time.Second, time.Millisecond)
155+ d = <-ch
156+ s.Require().Equal("3", d.Data)
157+ d.SetSucceeded()
158+
159+ s.Require().Eventually(func() bool { return len(ch) == 2 }, time.Second, time.Millisecond)
160+ s.Require().Never(func() bool { return len(ch) > 2 }, time.Second, time.Millisecond)
161+ d1, d2 := <-ch, <-ch
162+ s.Require().ElementsMatch([]string{"1", "2"}, []string{d1.Data, d2.Data})
163+ d1.SetSucceeded()
164+ d2.SetSucceeded()
165+
166+ s.Require().Never(func() bool { return len(ch) > 0 }, time.Second, time.Millisecond)
167+}
168+
169+func (s *GraphTestSuite) TestReverseFailedDependencies() {
170+ graph := dependency.NewGraph[string, string]()
171+
172+ s.Require().NoError(graph.NewNode("1", "1"))
173+ s.Require().NoError(graph.NewNode("2", "2"))
174+ s.Require().NoError(graph.NewNode("3", "3"))
175+ s.Require().NoError(graph.NewNode("4", "4"))
176+
177+ graph.AddDependency("3", "1")
178+ graph.AddDependency("3", "2")
179+ graph.AddDependency("4", "3")
180+
181+ s.Require().NoError(graph.Build())
182+ graph, err := graph.Reverse()
183+ s.Require().Nil(err)
184+
185+ ch := graph.Run()
186+
187+ s.Require().NotNil(ch)
188+ s.Require().Eventually(func() bool { return len(ch) == 1 }, time.Second, time.Millisecond)
189+ s.Require().Never(func() bool { return len(ch) > 1 }, time.Second, time.Millisecond)
190+ d := <-ch
191+ s.Require().Equal("4", d.Data)
192+ d.SetSucceeded()
193+
194+ s.Require().Eventually(func() bool { return len(ch) == 1 }, time.Second, time.Millisecond)
195+ s.Require().Never(func() bool { return len(ch) > 1 }, time.Second, time.Millisecond)
196+ d = <-ch
197+ s.Require().Equal("3", d.Data)
198+ d.SetFailed()
199+
200+ s.Require().Never(func() bool { return len(ch) > 0 }, time.Second, time.Millisecond)
201+}
202+
123203 func TestGraphTestSuite(t *testing.T) {
124204 t.Parallel()
125205 suite.Run(t, new(GraphTestSuite))