@@ -39,8 +39,8 @@ func TestNewDatafileProjectConfigNil(t *testing.T) {
3939}
4040
4141func TestNewDatafileProjectConfigNotNil (t * testing.T ) {
42- dpc := DatafileProjectConfig {accountID : "123" , revision : "1" , projectID : "12345" , sdkKey : "a" , environmentKey : "production" }
43- jsonDatafileStr := `{"accountID": "123", "revision": "1", "projectId": "12345", "version": "4", "sdkKey": "a", "environmentKey": "production"}`
42+ dpc := DatafileProjectConfig {accountID : "123" , revision : "1" , projectID : "12345" , sdkKey : "a" , environmentKey : "production" , eventMap : map [ string ]entities. Event { "event_single_targeted_exp" : { Key : "event_single_targeted_exp" }}, attributeMap : map [ string ]entities. Attribute { "10401066170" : { ID : "10401066170" }} }
43+ jsonDatafileStr := `{"accountID":"123","revision":"1","projectId":"12345","version":"4","sdkKey":"a","environmentKey":"production","events":[{"key":"event_single_targeted_exp"}],"attributes":[{"id":"10401066170"}] }`
4444 jsonDatafile := []byte (jsonDatafileStr )
4545 projectConfig , err := NewDatafileProjectConfig (jsonDatafile , logging .GetLogger ("" , "DatafileProjectConfig" ))
4646 assert .Nil (t , err )
@@ -52,6 +52,16 @@ func TestNewDatafileProjectConfigNotNil(t *testing.T) {
5252 assert .Equal (t , dpc .sdkKey , projectConfig .sdkKey )
5353}
5454
55+ func TestGetDatafile (t * testing.T ) {
56+ jsonDatafileStr := `{"accountID": "123", "revision": "1", "projectId": "12345", "version": "4", "sdkKey": "a", "environmentKey": "production"}`
57+ jsonDatafile := []byte (jsonDatafileStr )
58+ config := & DatafileProjectConfig {
59+ datafile : string (jsonDatafile ),
60+ }
61+
62+ assert .Equal (t , string (jsonDatafile ), config .GetDatafile ())
63+ }
64+
5565func TestGetProjectID (t * testing.T ) {
5666 projectID := "projectID"
5767 config := & DatafileProjectConfig {
@@ -88,6 +98,14 @@ func TestGetAnonymizeIP(t *testing.T) {
8898 assert .Equal (t , anonymizeIP , config .GetAnonymizeIP ())
8999}
90100
101+ func TestGetAttributes (t * testing.T ) {
102+ config := & DatafileProjectConfig {
103+ attributeMap : map [string ]entities.Attribute {"id1" : {ID : "id1" , Key : "key" }, "id2" : {ID : "id1" , Key : "key" }},
104+ }
105+
106+ assert .Equal (t , []entities.Attribute {config .attributeMap ["id1" ], config .attributeMap ["id2" ]}, config .GetAttributes ())
107+ }
108+
91109func TestGetAttributeID (t * testing.T ) {
92110 id := "id"
93111 key := "key"
@@ -115,6 +133,13 @@ func TestGetEnvironmentKey(t *testing.T) {
115133 assert .Equal (t , "production" , config .GetEnvironmentKey ())
116134}
117135
136+ func TestGetEvents (t * testing.T ) {
137+ config := & DatafileProjectConfig {
138+ eventMap : map [string ]entities.Event {"key" : {ID : "5" , Key : "key" }},
139+ }
140+ assert .Equal (t , []entities.Event {config .eventMap ["key" ]}, config .GetEvents ())
141+ }
142+
118143func TestGetBotFiltering (t * testing.T ) {
119144 botFiltering := true
120145 config := & DatafileProjectConfig {
@@ -298,20 +323,34 @@ func TestGetExperimentList(t *testing.T) {
298323 experiment := entities.Experiment {
299324 Key : key ,
300325 }
326+
301327 experimentMap := make (map [string ]entities.Experiment )
302328 experimentMap [id ] = experiment
303329
304330 config := & DatafileProjectConfig {
305331 experimentKeyToIDMap : experimentKeyToIDMap ,
306332 experimentMap : experimentMap ,
307333 }
308-
309334 experiments := config .GetExperimentList ()
310335
311336 assert .Equal (t , 1 , len (experiments ))
312337 assert .Equal (t , experiment , experiments [0 ])
313338}
314339
340+ func TestGetRolloutList (t * testing.T ) {
341+ config := & DatafileProjectConfig {
342+ rollouts : []entities.Rollout {{ID : "5" }},
343+ }
344+ assert .Equal (t , config .rollouts , config .GetRolloutList ())
345+ }
346+
347+ func TestGetAudienceList (t * testing.T ) {
348+ config := & DatafileProjectConfig {
349+ audienceMap : map [string ]entities.Audience {"5" : {ID : "5" , Name : "one" }, "6" : {ID : "6" , Name : "two" }},
350+ }
351+ assert .ElementsMatch (t , []entities.Audience {config .audienceMap ["5" ], config .audienceMap ["6" ]}, config .GetAudienceList ())
352+ }
353+
315354func TestGetAudienceByID (t * testing.T ) {
316355 id := "id"
317356 audience := entities.Audience {
@@ -409,6 +448,13 @@ func TestGetGroupByID(t *testing.T) {
409448 assert .Equal (t , group , actual )
410449}
411450
451+ func TestSendFlagDecisions (t * testing.T ) {
452+ config := & DatafileProjectConfig {
453+ sendFlagDecisions : true ,
454+ }
455+ assert .Equal (t , config .sendFlagDecisions , config .SendFlagDecisions ())
456+ }
457+
412458func TestGetGroupByIDMissingIDError (t * testing.T ) {
413459 config := & DatafileProjectConfig {}
414460 _ , err := config .GetGroupByID ("id" )
0 commit comments