TestHeadTailBufferKeepsExactHeadAndTail: once the middle is dropped, the reassembly must carry exactly the first head-cap bytes and the last tail-cap bytes in order, across chunked writes that wrap the ring several times.
(t *testing.T)
| 84 | // reassembly must carry exactly the first head-cap bytes and the last tail-cap |
| 85 | // bytes in order, across chunked writes that wrap the ring several times. |
| 86 | func TestHeadTailBufferKeepsExactHeadAndTail(t *testing.T) { |
| 87 | var b headTailBuffer |
| 88 | total := bashOutputHead + 5*bashOutputTail |
| 89 | // Deterministic byte stream in awkward chunk sizes to exercise ring wraps. |
| 90 | buf := make([]byte, 0, total) |
| 91 | for i := 0; len(buf) < total; i++ { |
| 92 | buf = append(buf, byte('a'+i%26)) |
| 93 | } |
| 94 | for i := 0; i < total; i += 3333 { |
| 95 | b.Write(buf[i:min(i+3333, total)]) |
| 96 | } |
| 97 | got := b.String() |
| 98 | if !strings.HasPrefix(got, string(buf[:bashOutputHead])) { |
| 99 | t.Fatal("head bytes wrong") |
| 100 | } |
| 101 | if !strings.HasSuffix(got, string(buf[total-bashOutputTail:])) { |
| 102 | t.Fatal("tail bytes wrong after ring wraps") |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | // TestBashHonorsAlreadyCancelledParent: a pre-cancelled parent (Ctrl+C raced |
| 107 | // the dispatch) must report "(cancelled)", not "(empty command)" or, worse, |