@@ -11,6 +11,7 @@ import (
1111 "github.com/gorilla/mux"
1212 "github.com/launchdarkly/go-sdk-common/v3/ldcontext"
1313 "github.com/launchdarkly/go-sdk-common/v3/ldvalue"
14+ "github.com/launchdarkly/go-server-sdk/v7/subsystems"
1415 "github.com/launchdarkly/ldcli/internal/dev_server/model"
1516 "github.com/launchdarkly/ldcli/internal/dev_server/model/mocks"
1617 "github.com/stretchr/testify/assert"
@@ -53,7 +54,7 @@ func TestBuildPollResponse(t *testing.T) {
5354
5455 require .GreaterOrEqual (t , len (resp .Events ), 3 ) // server-intent + put-objects + payload-transferred
5556
56- assertServerIntentEvent (t , resp .Events [0 ], payloadID , currentVersion , fdv2IntentXferFull , fdv2ReasonPayloadMissing )
57+ assertServerIntentEvent (t , resp .Events [0 ], payloadID , currentVersion , subsystems . IntentTransferFull , fdv2ReasonPayloadMissing )
5758 assertPayloadTransferredEvent (t , resp .Events [len (resp .Events )- 1 ], payloadID , currentVersion )
5859 })
5960
@@ -62,23 +63,23 @@ func TestBuildPollResponse(t *testing.T) {
6263 require .NoError (t , err )
6364
6465 require .Len (t , resp .Events , 1 )
65- assertServerIntentEvent (t , resp .Events [0 ], payloadID , currentVersion , fdv2IntentNone , fdv2ReasonUpToDate )
66+ assertServerIntentEvent (t , resp .Events [0 ], payloadID , currentVersion , subsystems . IntentNone , fdv2ReasonUpToDate )
6667 })
6768
6869 t .Run ("basis ahead of current version sends none with up-to-date" , func (t * testing.T ) {
6970 resp , err := buildPollResponse (payloadID , currentVersion , flags , currentVersion + 10 )
7071 require .NoError (t , err )
7172
7273 require .Len (t , resp .Events , 1 )
73- assertServerIntentEvent (t , resp .Events [0 ], payloadID , currentVersion , fdv2IntentNone , fdv2ReasonUpToDate )
74+ assertServerIntentEvent (t , resp .Events [0 ], payloadID , currentVersion , subsystems . IntentNone , fdv2ReasonUpToDate )
7475 })
7576
7677 t .Run ("stale basis sends xfer-full with cant-catchup" , func (t * testing.T ) {
7778 resp , err := buildPollResponse (payloadID , currentVersion , flags , currentVersion - 1 )
7879 require .NoError (t , err )
7980
8081 require .GreaterOrEqual (t , len (resp .Events ), 3 )
81- assertServerIntentEvent (t , resp .Events [0 ], payloadID , currentVersion , fdv2IntentXferFull , fdv2ReasonCantCatchup )
82+ assertServerIntentEvent (t , resp .Events [0 ], payloadID , currentVersion , subsystems . IntentTransferFull , fdv2ReasonCantCatchup )
8283 assertPayloadTransferredEvent (t , resp .Events [len (resp .Events )- 1 ], payloadID , currentVersion )
8384 })
8485
@@ -94,12 +95,12 @@ func TestBuildPollResponse(t *testing.T) {
9495 assert .Len (t , resp .Events , 4 )
9596 putKeys := make (map [string ]bool )
9697 for _ , event := range resp .Events {
97- if event .Event == fdv2EventPutObject {
98- var put fdv2PutObjectData
98+ if event .Name == subsystems . EventPutObject {
99+ var put subsystems. PutObject
99100 require .NoError (t , json .Unmarshal (event .Data , & put ))
100101 putKeys [put .Key ] = true
101102 assert .Equal (t , currentVersion , put .Version )
102- assert .Equal (t , "flag" , put .Kind )
103+ assert .Equal (t , subsystems . FlagKind , put .Kind )
103104 }
104105 }
105106 assert .True (t , putKeys ["flag-a" ])
@@ -141,10 +142,10 @@ func TestPollV2Handler(t *testing.T) {
141142 require .Equal (t , http .StatusOK , rec .Code )
142143 assert .Equal (t , "application/json" , rec .Header ().Get ("Content-Type" ))
143144
144- var resp fdv2PollResponse
145+ var resp subsystems. PollingPayload
145146 require .NoError (t , json .Unmarshal (rec .Body .Bytes (), & resp ))
146147 require .GreaterOrEqual (t , len (resp .Events ), 3 )
147- assertServerIntentEvent (t , resp .Events [0 ], exampleProjectKey , 3 , fdv2IntentXferFull , fdv2ReasonPayloadMissing )
148+ assertServerIntentEvent (t , resp .Events [0 ], exampleProjectKey , 3 , subsystems . IntentTransferFull , fdv2ReasonPayloadMissing )
148149 assertPayloadTransferredEvent (t , resp .Events [len (resp .Events )- 1 ], exampleProjectKey , 3 )
149150 })
150151
@@ -160,10 +161,10 @@ func TestPollV2Handler(t *testing.T) {
160161
161162 require .Equal (t , http .StatusOK , rec .Code )
162163
163- var resp fdv2PollResponse
164+ var resp subsystems. PollingPayload
164165 require .NoError (t , json .Unmarshal (rec .Body .Bytes (), & resp ))
165166 require .Len (t , resp .Events , 1 )
166- assertServerIntentEvent (t , resp .Events [0 ], exampleProjectKey , 3 , fdv2IntentNone , fdv2ReasonUpToDate )
167+ assertServerIntentEvent (t , resp .Events [0 ], exampleProjectKey , 3 , subsystems . IntentNone , fdv2ReasonUpToDate )
167168 })
168169
169170 t .Run ("stale basis returns full payload with cant-catchup" , func (t * testing.T ) {
@@ -178,10 +179,10 @@ func TestPollV2Handler(t *testing.T) {
178179
179180 require .Equal (t , http .StatusOK , rec .Code )
180181
181- var resp fdv2PollResponse
182+ var resp subsystems. PollingPayload
182183 require .NoError (t , json .Unmarshal (rec .Body .Bytes (), & resp ))
183184 require .GreaterOrEqual (t , len (resp .Events ), 3 )
184- assertServerIntentEvent (t , resp .Events [0 ], exampleProjectKey , 3 , fdv2IntentXferFull , fdv2ReasonCantCatchup )
185+ assertServerIntentEvent (t , resp .Events [0 ], exampleProjectKey , 3 , subsystems . IntentTransferFull , fdv2ReasonCantCatchup )
185186 assertPayloadTransferredEvent (t , resp .Events [len (resp .Events )- 1 ], exampleProjectKey , 3 )
186187 })
187188
@@ -198,24 +199,23 @@ func TestPollV2Handler(t *testing.T) {
198199}
199200
200201// assertServerIntentEvent unmarshals a server-intent event and checks its fields.
201- func assertServerIntentEvent (t * testing.T , event fdv2RawEvent , payloadID string , target int , intentCode , reason string ) {
202+ func assertServerIntentEvent (t * testing.T , event subsystems. RawEvent , payloadID string , target int , intentCode subsystems. IntentCode , reason string ) {
202203 t .Helper ()
203- assert .Equal (t , fdv2EventServerIntent , event .Event )
204- var data fdv2ServerIntentData
204+ assert .Equal (t , subsystems . EventServerIntent , event .Name )
205+ var data subsystems. ServerIntent
205206 require .NoError (t , json .Unmarshal (event .Data , & data ))
206- require .Len (t , data .Payloads , 1 )
207- assert .Equal (t , payloadID , data .Payloads [0 ].ID )
208- assert .Equal (t , target , data .Payloads [0 ].Target )
209- assert .Equal (t , intentCode , data .Payloads [0 ].IntentCode )
210- assert .Equal (t , reason , data .Payloads [0 ].Reason )
207+ assert .Equal (t , payloadID , data .Payload .ID )
208+ assert .Equal (t , target , data .Payload .Target )
209+ assert .Equal (t , intentCode , data .Payload .Code )
210+ assert .Equal (t , reason , data .Payload .Reason )
211211}
212212
213213// assertPayloadTransferredEvent unmarshals a payload-transferred event and checks its fields.
214- func assertPayloadTransferredEvent (t * testing.T , event fdv2RawEvent , payloadID string , version int ) {
214+ func assertPayloadTransferredEvent (t * testing.T , event subsystems. RawEvent , payloadID string , version int ) {
215215 t .Helper ()
216- assert .Equal (t , fdv2EventPayloadTransferred , event .Event )
217- var data fdv2PayloadTransferredData
216+ assert .Equal (t , subsystems . EventPayloadTransferred , event .Name )
217+ var data subsystems. Selector
218218 require .NoError (t , json .Unmarshal (event .Data , & data ))
219- assert .Equal (t , version , data .Version )
220- assert .Equal (t , fmt .Sprintf ("(p:%s:%d)" , payloadID , version ), data .State )
219+ assert .Equal (t , version , data .Version () )
220+ assert .Equal (t , fmt .Sprintf ("(p:%s:%d)" , payloadID , version ), data .State () )
221221}
0 commit comments