@@ -2,6 +2,7 @@ package daemon
22
33import (
44 "context"
5+ "encoding/json"
56 "net/http"
67 "net/http/httptest"
78 "testing"
@@ -23,6 +24,8 @@ type fakeCommandStore struct {
2324
2425 cursorSetCalls int
2526 pruneCalls int
27+
28+ engine string
2629}
2730
2831func (f * fakeCommandStore ) SavePre (ctx context.Context , cmd model.Command , rt time.Time ) error {
@@ -72,6 +75,13 @@ func (f *fakeCommandStore) Prune(ctx context.Context, cursor time.Time) error {
7275 return nil
7376}
7477
78+ func (f * fakeCommandStore ) Engine () string {
79+ if f .engine == "" {
80+ return model .StorageEngineFile
81+ }
82+ return f .engine
83+ }
84+
7585func (f * fakeCommandStore ) Close () error { return nil }
7686
7787// fakeConfigService implements model.ConfigService without mockery.
@@ -184,12 +194,14 @@ func (s *TrackHandlerTestSuite) TestTrackPostNotEnoughToFlush() {
184194}
185195
186196func (s * TrackHandlerTestSuite ) TestTrackPostFlushSyncsAndPrunes () {
197+ var sentPayload model.PostTrackArgs
187198 server := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
199+ _ = json .NewDecoder (r .Body ).Decode (& sentPayload )
188200 w .WriteHeader (http .StatusNoContent )
189201 }))
190202 defer server .Close ()
191203
192- store := & fakeCommandStore {noCursorExist : true }
204+ store := & fakeCommandStore {noCursorExist : true , engine : model . StorageEngineBolt }
193205 commandStore = store
194206 stConfig = fakeConfigService {cfg : model.ShellTimeConfig {Token : "t" , APIEndpoint : server .URL , FlushCount : 1 }}
195207
@@ -204,6 +216,9 @@ func (s *TrackHandlerTestSuite) TestTrackPostFlushSyncsAndPrunes() {
204216 assert .Len (s .T (), store .post , 1 )
205217 assert .Equal (s .T (), 1 , store .cursorSetCalls )
206218 assert .Equal (s .T (), 1 , store .pruneCalls )
219+ // the payload must report the engine that buffered the commands
220+ assert .Equal (s .T (), model .StorageEngineBolt , sentPayload .Meta .CliEngine )
221+ assert .Equal (s .T (), 1 , sentPayload .Meta .Source , "daemon path must mark source as daemon" )
207222}
208223
209224func (s * TrackHandlerTestSuite ) TestTrackPostFallsBackToFileStore () {
0 commit comments