MCPcopy Create free account
hub / github.com/CrunchyData/postgres-operator / TestExecutorGetTimeline

Function TestExecutorGetTimeline

internal/patroni/api_test.go:229–289  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

227}
228
229func TestExecutorGetTimeline(t *testing.T) {
230 t.Run("Error", func(t *testing.T) {
231 expected := errors.New("bang")
232 tl, actual := Executor(func(
233 context.Context, io.Reader, io.Writer, io.Writer, ...string,
234 ) error {
235 return expected
236 }).GetTimeline(context.Background())
237
238 assert.Equal(t, expected, actual)
239 assert.Equal(t, tl, int64(0))
240 })
241
242 t.Run("Stderr", func(t *testing.T) {
243 tl, actual := Executor(func(
244 _ context.Context, stdin io.Reader, stdout, stderr io.Writer, command ...string,
245 ) error {
246 _, _ = stderr.Write([]byte(`no luck`))
247 return nil
248 }).GetTimeline(context.Background())
249
250 assert.Error(t, actual, "no luck")
251 assert.Equal(t, tl, int64(0))
252 })
253
254 t.Run("BadJSON", func(t *testing.T) {
255 tl, actual := Executor(func(
256 _ context.Context, stdin io.Reader, stdout, stderr io.Writer, command ...string,
257 ) error {
258 _, _ = stdout.Write([]byte(`no luck`))
259 return nil
260 }).GetTimeline(context.Background())
261
262 assert.Error(t, actual, "invalid character 'o' in literal null (expecting 'u')")
263 assert.Equal(t, tl, int64(0))
264 })
265
266 t.Run("NoLeader", func(t *testing.T) {
267 tl, actual := Executor(func(
268 _ context.Context, stdin io.Reader, stdout, stderr io.Writer, command ...string,
269 ) error {
270 _, _ = stdout.Write([]byte(`[{"Cluster": "hippo-ha", "Member": "hippo-instance1-ltcf-0", "Host": "hippo-instance1-ltcf-0.hippo-pods", "Role": "Replica", "State": "running", "TL": 4, "Lag in MB": 0}]`))
271 return nil
272 }).GetTimeline(context.Background())
273
274 assert.NilError(t, actual)
275 assert.Equal(t, tl, int64(0))
276 })
277
278 t.Run("Success", func(t *testing.T) {
279 tl, actual := Executor(func(
280 _ context.Context, stdin io.Reader, stdout, stderr io.Writer, command ...string,
281 ) error {
282 _, _ = stdout.Write([]byte(`[{"Cluster": "hippo-ha", "Member": "hippo-instance1-67mc-0", "Host": "hippo-instance1-67mc-0.hippo-pods", "Role": "Leader", "State": "running", "TL": 4}, {"Cluster": "hippo-ha", "Member": "hippo-instance1-ltcf-0", "Host": "hippo-instance1-ltcf-0.hippo-pods", "Role": "Replica", "State": "running", "TL": 4, "Lag in MB": 0}]`))
283 return nil
284 }).GetTimeline(context.Background())
285
286 assert.NilError(t, actual)

Callers

nothing calls this directly

Calls 4

GetTimelineMethod · 0.80
ErrorMethod · 0.80
ExecutorFuncType · 0.70
EqualMethod · 0.45

Tested by

no test coverage detected