vitess.io/vitess@v0.16.2/go/vt/vttablet/tabletmanager/vreplication/queryhistory/dsl.go (about) 1 package queryhistory 2 3 // Expect generates a sequence of expectations, where each query after the head 4 // query immediately follows the preceding query. 5 func Expect(head string, tail ...string) ExpectationSequencer { 6 return Immediately(head, tail...)(nil) 7 } 8 9 // ExpectNone generates an empty sequence of expectations. 10 func ExpectNone() ExpectationSequence { 11 return &expectationSequence{} 12 } 13 14 // Eventually generates an ExpectationSequencerFn which can be used to append a 15 // new sequence of expectations onto an existing sequence. 16 // 17 // Expect("foo", "bar").Then(Eventually("hello", "world") 18 // 19 // Generates a sequence of expectations such that: 20 // 21 // - "foo" is expected first 22 // - "bar" immediately follows "foo" 23 // - "hello" eventually follows "bar" 24 // - "world" eventually follows "hello" 25 func Eventually(head string, tail ...string) ExpectationSequencerFn { 26 return func(sequencer ExpectationSequencer) ExpectationSequencer { 27 current := Query(head) 28 var head, last SequencedExpectation 29 if sequencer != nil && sequencer.Current() != nil { 30 head = sequencer.Head() 31 sequencer.Current().ExpectEventuallyBefore(current) 32 } else { 33 head = current 34 } 35 for _, q := range tail { 36 last = current 37 current = Query(q) 38 last.ExpectEventuallyBefore(current) 39 } 40 return &expectationSequencer{ 41 ExpectationSequence: &expectationSequence{head}, 42 current: current, 43 } 44 } 45 } 46 47 // Immediately generates an ExpectationSequencerFn which can be used to append a 48 // new sequence of expectations onto an existing sequence. 49 // 50 // Expect("foo", "bar").Then(Immediately("hello", "world") 51 // 52 // Generates a sequence of expectations such that: 53 // 54 // - "foo" is expected first 55 // - "bar" immediately follows "foo" 56 // - "hello" immediately follows "bar" 57 // - "world" immediately follows "hello" 58 func Immediately(head string, tail ...string) ExpectationSequencerFn { 59 return func(sequencer ExpectationSequencer) ExpectationSequencer { 60 current := Query(head) 61 var head, last SequencedExpectation 62 if sequencer != nil && sequencer.Current() != nil { 63 head = sequencer.Head() 64 sequencer.Current().ExpectImmediatelyBefore(current) 65 } else { 66 head = current 67 } 68 for _, q := range tail { 69 last = current 70 current = Query(q) 71 last.ExpectImmediatelyBefore(current) 72 } 73 return &expectationSequencer{ 74 ExpectationSequence: &expectationSequence{head}, 75 current: current, 76 } 77 } 78 } 79 80 // Query generates a single-member expectation sequence. 81 func Query(query string) SequencedExpectation { 82 return newSequencedExpectation(newExpectation(query)) 83 }