@@ -20,13 +20,16 @@ import (
2020 "testing"
2121
2222 pb "github.com/GoogleCloudPlatform/khi/pkg/generated/khifile/v6"
23+ "github.com/google/go-cmp/cmp"
24+ "google.golang.org/protobuf/proto"
25+ "google.golang.org/protobuf/testing/protocmp"
2326)
2427
2528func TestRegisterTimelineType (t * testing.T ) {
2629 reset ()
2730
28- res1 := MustRegisterTimelineType ("Type 1" , "Desc 1" , "icon-1" , 1.0 , Color {1 , 1 , 1 , 1 }, Color {0 , 0 , 0 , 1 }, Color {0.5 , 0.5 , 0.5 , 1 }, true , 1 )
29- res2 := MustRegisterTimelineType ("Type 2" , "Desc 2" , "icon-2" , 1.0 , Color {1 , 1 , 1 , 1 }, Color {0 , 0 , 0 , 1 }, Color {0.5 , 0.5 , 0.5 , 1 }, true , 2 )
31+ res1 := MustRegisterTimelineType ("Type 1" , "Desc 1" , "icon-1" , 1.0 , Color {1 , 1 , 1 , 1 }, Color {0 , 0 , 0 , 1 }, Color {0.5 , 0.5 , 0.5 , 1 }, true , 1 , nil )
32+ res2 := MustRegisterTimelineType ("Type 2" , "Desc 2" , "icon-2" , 1.0 , Color {1 , 1 , 1 , 1 }, Color {0 , 0 , 0 , 1 }, Color {0.5 , 0.5 , 0.5 , 1 }, true , 2 , nil )
3033
3134 // Verify IDs were assigned starting from 1
3235 if res1 .Id == nil || * res1 .Id != 1 {
@@ -90,7 +93,7 @@ func TestGenerateChunkHasAllSlices(t *testing.T) {
9093 MustRegisterVerb ("Verb" , Color {1 , 1 , 1 , 1 }, Color {0 , 0 , 0 , 1 }, true )
9194 MustRegisterLogType ("Log" , "Desc" , Color {1 , 1 , 1 , 1 }, Color {0 , 0 , 0 , 1 })
9295 MustRegisterRevisionState ("RevState" , "icon" , "Desc" , Color {1 , 1 , 1 , 1 }, pb .RevisionStateStyle_REVISION_STATE_STYLE_NORMAL )
93- MustRegisterTimelineType ("Timeline" , "Desc" , "icon" , 1.0 , Color {1 , 1 , 1 , 1 }, Color {0 , 0 , 0 , 1 }, Color {0.5 , 0.5 , 0.5 , 1 }, true , 1 )
96+ MustRegisterTimelineType ("Timeline" , "Desc" , "icon" , 1.0 , Color {1 , 1 , 1 , 1 }, Color {0 , 0 , 0 , 1 }, Color {0.5 , 0.5 , 0.5 , 1 }, true , 1 , nil )
9497
9598 chunk := GenerateChunk ()
9699
@@ -207,7 +210,7 @@ func TestLockRegistry(t *testing.T) {
207210 label : "T" ,
208211 styleClass : "timeline type" ,
209212 fn : func () {
210- MustRegisterTimelineType ("T" , "D" , "icon" , 1 , Color {1 , 1 , 1 , 1 }, Color {0 , 0 , 0 , 1 }, Color {0 , 0 , 0 , 1 }, true , 10 )
213+ MustRegisterTimelineType ("T" , "D" , "icon" , 1 , Color {1 , 1 , 1 , 1 }, Color {0 , 0 , 0 , 1 }, Color {0 , 0 , 0 , 1 }, true , 10 , nil )
211214 },
212215 },
213216 {
@@ -270,3 +273,48 @@ func TestLockRegistry(t *testing.T) {
270273 })
271274 }
272275}
276+
277+ func TestRegisterTimelineTypeWithSortPolicy (t * testing.T ) {
278+ testCases := []struct {
279+ name string
280+ sortOpt TimelineSortOpt
281+ wantType * pb.TimelineType
282+ }{
283+ {
284+ name : "alphabetical sort policy" ,
285+ sortOpt : AlphabeticalSortPolicy ("a" , "b" ),
286+ wantType : & pb.TimelineType {
287+ SortPolicyConfig : & pb.TimelineType_AlphabeticalPolicy {
288+ AlphabeticalPolicy : & pb.AlphabeticalSortPolicy {
289+ PrioritizedNames : []string {"a" , "b" },
290+ },
291+ },
292+ },
293+ },
294+ {
295+ name : "chronological sort policy" ,
296+ sortOpt : ChronologicalSortPolicy (5 ),
297+ wantType : & pb.TimelineType {
298+ SortPolicyConfig : & pb.TimelineType_ChronologicalPolicy {
299+ ChronologicalPolicy : & pb.ChronologicalSortPolicy {
300+ ChronologicalSearchDepth : proto .Int32 (5 ),
301+ },
302+ },
303+ },
304+ },
305+ }
306+
307+ for _ , tc := range testCases {
308+ t .Run (tc .name , func (t * testing.T ) {
309+ reset ()
310+ registered := MustRegisterTimelineType ("T" , "D" , "icon" , 1 , Color {1 , 1 , 1 , 1 }, Color {0 , 0 , 0 , 1 }, Color {0 , 0 , 0 , 1 }, true , 10 , tc .sortOpt )
311+
312+ // We only compare the SortPolicyConfig portion
313+ got := registered .SortPolicyConfig
314+ want := tc .wantType .SortPolicyConfig
315+ if diff := cmp .Diff (want , got , protocmp .Transform ()); diff != "" {
316+ t .Errorf ("MustRegisterTimelineType() sort policy config mismatch (-want +got):\n %s" , diff )
317+ }
318+ })
319+ }
320+ }
0 commit comments