(t *testing.T)
| 123 | } |
| 124 | |
| 125 | func newFakeInit(t *testing.T) *fakeInit { |
| 126 | t.Helper() |
| 127 | tmpdir := t.TempDir() |
| 128 | fi := &fakeInit{ |
| 129 | events: make(chan struct{}, 8), |
| 130 | sent: make(chan *HTTPClientSends, 8), |
| 131 | } |
| 132 | fi.init = &engine.Init{ |
| 133 | VarDir: func(p string) (string, error) { |
| 134 | return filepath.Join(tmpdir, p), nil |
| 135 | }, |
| 136 | Event: func(ctx context.Context) error { |
| 137 | select { |
| 138 | case fi.events <- struct{}{}: |
| 139 | return nil |
| 140 | case <-ctx.Done(): |
| 141 | return ctx.Err() |
| 142 | } |
| 143 | }, |
| 144 | Refresh: func() bool { return fi.refresh.Load() }, |
| 145 | Send: func(v interface{}) error { |
| 146 | s, ok := v.(*HTTPClientSends) |
| 147 | if !ok { |
| 148 | return fmt.Errorf("unexpected Send payload %T", v) |
| 149 | } |
| 150 | // Copy so callers can't observe later mutation. |
| 151 | cp := *s |
| 152 | if s.Content != nil { |
| 153 | c := *s.Content |
| 154 | cp.Content = &c |
| 155 | } |
| 156 | fi.sent <- &cp |
| 157 | return nil |
| 158 | }, |
| 159 | Debug: testing.Verbose(), |
| 160 | Logf: func(format string, v ...interface{}) { t.Logf("res: "+format, v...) }, |
| 161 | } |
| 162 | fi.init.Local = (&local.API{ |
| 163 | Prefix: filepath.Join(tmpdir, "local"), |
| 164 | Debug: testing.Verbose(), |
| 165 | Logf: func(format string, v ...interface{}) { t.Logf("local: "+format, v...) }, |
| 166 | }).Init() |
| 167 | return fi |
| 168 | } |
| 169 | |
| 170 | // drainSent pulls a Send payload non-blockingly. Returns nil if none pending. |
| 171 | func (obj *fakeInit) drainSent() *HTTPClientSends { |
no test coverage detected