@@ -996,6 +996,67 @@ func TestToMarkdown_NoChanges(t *testing.T) {
996996 }
997997}
998998
999+ func TestHasChanges (t * testing.T ) {
1000+ tests := []struct {
1001+ name string
1002+ result syncResult
1003+ want bool
1004+ }{
1005+ {
1006+ name : "empty result" ,
1007+ result : syncResult {},
1008+ want : false ,
1009+ },
1010+ {
1011+ name : "only unchanged repos" ,
1012+ result : syncResult {unchanged : []string {"repo-a" }},
1013+ want : false ,
1014+ },
1015+ {
1016+ name : "added repo" ,
1017+ result : syncResult {added : []string {"new-repo" }},
1018+ want : true ,
1019+ },
1020+ {
1021+ name : "updated repo" ,
1022+ result : syncResult {updated : []string {"existing-repo" }},
1023+ want : true ,
1024+ },
1025+ {
1026+ name : "removed repo" ,
1027+ result : syncResult {removed : []string {"old-repo" }},
1028+ want : true ,
1029+ },
1030+ {
1031+ name : "doc file changed without repo-level change" ,
1032+ result : syncResult {
1033+ unchanged : []string {"some-repo" },
1034+ changedRepoFiles : map [string ][]string {
1035+ "some-repo" : {"docs/guide.md" },
1036+ },
1037+ },
1038+ want : true ,
1039+ },
1040+ {
1041+ name : "changedRepoFiles present but empty slice" ,
1042+ result : syncResult {
1043+ changedRepoFiles : map [string ][]string {
1044+ "some-repo" : {},
1045+ },
1046+ },
1047+ want : false ,
1048+ },
1049+ }
1050+
1051+ for i := range tests {
1052+ t .Run (tests [i ].name , func (t * testing.T ) {
1053+ if got := tests [i ].result .hasChanges (); got != tests [i ].want {
1054+ t .Errorf ("hasChanges() = %v, want %v" , got , tests [i ].want )
1055+ }
1056+ })
1057+ }
1058+ }
1059+
9991060func TestToMarkdown_FallbackWithoutDetails (t * testing.T ) {
10001061 result := & syncResult {
10011062 synced : 1 ,
@@ -1357,3 +1418,124 @@ func TestParseNameList_RepoFilterOverridesExclude(t *testing.T) {
13571418 t .Error ("complyctl should be in includeSet" )
13581419 }
13591420}
1421+
1422+ func TestChangedRepos (t * testing.T ) {
1423+ tests := []struct {
1424+ name string
1425+ result syncResult
1426+ want []string
1427+ }{
1428+ {
1429+ name : "empty result" ,
1430+ result : syncResult {},
1431+ want : []string {},
1432+ },
1433+ {
1434+ name : "repo-level added only" ,
1435+ result : syncResult {added : []string {"repo-b" , "repo-a" }},
1436+ want : []string {"repo-a" , "repo-b" },
1437+ },
1438+ {
1439+ name : "repo-level updated only" ,
1440+ result : syncResult {updated : []string {"repo-c" }},
1441+ want : []string {"repo-c" },
1442+ },
1443+ {
1444+ name : "file-level changes only (no repo-level add/update)" ,
1445+ result : syncResult {
1446+ unchanged : []string {"repo-x" },
1447+ changedRepoFiles : map [string ][]string {
1448+ "repo-x" : {"docs/guide.md" },
1449+ },
1450+ },
1451+ want : []string {"repo-x" },
1452+ },
1453+ {
1454+ name : "overlap: repo in both updated and changedRepoFiles" ,
1455+ result : syncResult {
1456+ updated : []string {"repo-z" },
1457+ changedRepoFiles : map [string ][]string {
1458+ "repo-z" : {"docs/page.md" },
1459+ "repo-a" : {"docs/intro.md" },
1460+ },
1461+ },
1462+ want : []string {"repo-a" , "repo-z" },
1463+ },
1464+ {
1465+ name : "changedRepoFiles with empty slice excluded" ,
1466+ result : syncResult {
1467+ changedRepoFiles : map [string ][]string {
1468+ "repo-empty" : {},
1469+ },
1470+ },
1471+ want : []string {},
1472+ },
1473+ }
1474+
1475+ for i := range tests {
1476+ t .Run (tests [i ].name , func (t * testing.T ) {
1477+ got := tests [i ].result .changedRepos ()
1478+ if got == nil {
1479+ got = []string {}
1480+ }
1481+ if len (got ) != len (tests [i ].want ) {
1482+ t .Fatalf ("changedRepos() = %v, want %v" , got , tests [i ].want )
1483+ }
1484+ for j := range got {
1485+ if got [j ] != tests [i ].want [j ] {
1486+ t .Errorf ("changedRepos()[%d] = %q, want %q" , j , got [j ], tests [i ].want [j ])
1487+ }
1488+ }
1489+ })
1490+ }
1491+ }
1492+
1493+ func TestChangedFilesCount (t * testing.T ) {
1494+ tests := []struct {
1495+ name string
1496+ result syncResult
1497+ want int
1498+ }{
1499+ {
1500+ name : "zero files" ,
1501+ result : syncResult {},
1502+ want : 0 ,
1503+ },
1504+ {
1505+ name : "single repo with files" ,
1506+ result : syncResult {
1507+ changedRepoFiles : map [string ][]string {
1508+ "repo-a" : {"docs/a.md" , "docs/b.md" },
1509+ },
1510+ },
1511+ want : 2 ,
1512+ },
1513+ {
1514+ name : "multiple repos" ,
1515+ result : syncResult {
1516+ changedRepoFiles : map [string ][]string {
1517+ "repo-a" : {"docs/a.md" },
1518+ "repo-b" : {"docs/b.md" , "docs/c.md" , "docs/d.md" },
1519+ },
1520+ },
1521+ want : 4 ,
1522+ },
1523+ {
1524+ name : "empty slice counts as zero" ,
1525+ result : syncResult {
1526+ changedRepoFiles : map [string ][]string {
1527+ "repo-a" : {},
1528+ },
1529+ },
1530+ want : 0 ,
1531+ },
1532+ }
1533+
1534+ for i := range tests {
1535+ t .Run (tests [i ].name , func (t * testing.T ) {
1536+ if got := tests [i ].result .changedFilesCount (); got != tests [i ].want {
1537+ t .Errorf ("changedFilesCount() = %d, want %d" , got , tests [i ].want )
1538+ }
1539+ })
1540+ }
1541+ }
0 commit comments