@@ -978,6 +978,206 @@ Below is the list of checks that were disabled for each Prometheus server define
978978 return err
979979 },
980980 },
981+ {
982+ description : "rule moved to a different file, old deleted, no diff" ,
983+ timeout : time .Minute ,
984+ maxComments : 1 ,
985+ summary : reporter .NewSummary ([]reporter.Report {
986+ {
987+ Path : discovery.Path {
988+ SymlinkTarget : mockPath ,
989+ Name : mockPath ,
990+ },
991+ ModifiedLines : []int {2 , 3 },
992+ Rule : mockFile .Groups [0 ].Rules [0 ],
993+ Problem : checks.Problem {
994+ Reporter : "a" ,
995+ Summary : "foo error1" ,
996+ Details : "foo details" ,
997+ Diagnostics : []diags.Diagnostic {
998+ {
999+ Message : "Diagnostic message" ,
1000+ Pos : diags.PositionRanges {
1001+ {
1002+ Line : 2 ,
1003+ FirstColumn : 3 ,
1004+ LastColumn : 24 ,
1005+ },
1006+ {
1007+ Line : 3 ,
1008+ FirstColumn : 3 ,
1009+ LastColumn : 15 ,
1010+ },
1011+ },
1012+ FirstColumn : 1 ,
1013+ LastColumn : 24 ,
1014+ Kind : diags .Issue ,
1015+ },
1016+ },
1017+ Lines : diags.LineRange {First : 1 , Last : 3 },
1018+ Severity : checks .Fatal ,
1019+ Anchor : checks .AnchorAfter ,
1020+ },
1021+ },
1022+ }),
1023+ mock : httpmock .New (func (s * httpmock.Server ) {
1024+ s .ExpectGet (apiUser ).ReturnJSON (gitlab.User {ID : 123 })
1025+ s .ExpectGet (apiOpenMergeRequests ).ReturnJSON ([]gitlab.BasicMergeRequest {
1026+ {IID : 1 },
1027+ })
1028+ s .ExpectGet (apiVersions (1 )).ReturnJSON ([]gitlab.MergeRequestDiffVersion {
1029+ {ID : 2 , HeadCommitSHA : "head" , BaseCommitSHA : "base" , StartCommitSHA : "start" },
1030+ {ID : 1 , HeadCommitSHA : "head" , BaseCommitSHA : "base" , StartCommitSHA : "start" },
1031+ })
1032+ s .ExpectGet (apiDiffs (1 )).ReturnJSON ([]gitlab.MergeRequestDiff {
1033+ {
1034+ Diff : "" ,
1035+ NewPath : mockPath ,
1036+ OldPath : "foo.old" ,
1037+ AMode : "100644" ,
1038+ BMode : "100644" ,
1039+ RenamedFile : true ,
1040+ },
1041+ {
1042+ Diff : "" ,
1043+ NewPath : "foo.txt" ,
1044+ OldPath : "foo.txt" ,
1045+ },
1046+ })
1047+ s .ExpectGet (apiDiscussions (1 , true )).ReturnJSON ([]gitlab.Discussion {})
1048+ s .ExpectPost (apiDiscussions (1 , false )).WithBodyJSON (gitlab.CreateMergeRequestDiscussionOptions {
1049+ Body : discBodyWithDiag ("a" , "foo error1" , "foo details" , "```yaml\n 2 | - record: target is down\n 3 | expr: up == 0\n ^^ \n ```" , "Diagnostic message" ),
1050+ Position : gitlab .Ptr (gitlab.PositionOptions {
1051+ BaseSHA : gitlab .Ptr ("base" ),
1052+ StartSHA : gitlab .Ptr ("start" ),
1053+ HeadSHA : gitlab .Ptr ("head" ),
1054+ OldPath : gitlab .Ptr ("foo.old" ),
1055+ NewPath : gitlab .Ptr (mockPath ),
1056+ PositionType : gitlab .Ptr ("text" ),
1057+ NewLine : gitlab .Ptr (3 ),
1058+ // Old file is gone so we don't have OldLine here at all
1059+ }),
1060+ }).ReturnJSON (gitlab.Response {})
1061+ }),
1062+ errorHandler : func (err error ) error {
1063+ return err
1064+ },
1065+ },
1066+ {
1067+ description : "deleted rule, no diff" ,
1068+ timeout : time .Minute ,
1069+ maxComments : 1 ,
1070+ summary : reporter .NewSummary ([]reporter.Report {
1071+ {
1072+ Path : discovery.Path {
1073+ SymlinkTarget : mockPath ,
1074+ Name : mockPath ,
1075+ },
1076+ ModifiedLines : []int {2 , 3 },
1077+ Rule : mockFile .Groups [0 ].Rules [0 ],
1078+ Problem : checks.Problem {
1079+ Reporter : "a" ,
1080+ Summary : "foo error1" ,
1081+ Details : "foo details" ,
1082+ Diagnostics : []diags.Diagnostic {},
1083+ Lines : diags.LineRange {First : 1 , Last : 3 },
1084+ Severity : checks .Fatal ,
1085+ Anchor : checks .AnchorBefore ,
1086+ },
1087+ },
1088+ }),
1089+ mock : httpmock .New (func (s * httpmock.Server ) {
1090+ s .ExpectGet (apiUser ).ReturnJSON (gitlab.User {ID : 123 })
1091+ s .ExpectGet (apiOpenMergeRequests ).ReturnJSON ([]gitlab.BasicMergeRequest {
1092+ {IID : 1 },
1093+ })
1094+ s .ExpectGet (apiVersions (1 )).ReturnJSON ([]gitlab.MergeRequestDiffVersion {
1095+ {ID : 2 , HeadCommitSHA : "head" , BaseCommitSHA : "base" , StartCommitSHA : "start" },
1096+ {ID : 1 , HeadCommitSHA : "head" , BaseCommitSHA : "base" , StartCommitSHA : "start" },
1097+ })
1098+ s .ExpectGet (apiDiffs (1 )).ReturnJSON ([]gitlab.MergeRequestDiff {
1099+ {
1100+ Diff : "" ,
1101+ NewPath : mockPath ,
1102+ OldPath : mockPath ,
1103+ },
1104+ })
1105+ s .ExpectGet (apiDiscussions (1 , true )).ReturnJSON ([]gitlab.Discussion {})
1106+ s .ExpectPost (apiDiscussions (1 , false )).WithBodyJSON (gitlab.CreateMergeRequestDiscussionOptions {
1107+ Body : discBody ("a" , "foo error1" , "foo details" ),
1108+ Position : gitlab .Ptr (gitlab.PositionOptions {
1109+ BaseSHA : gitlab .Ptr ("base" ),
1110+ StartSHA : gitlab .Ptr ("start" ),
1111+ HeadSHA : gitlab .Ptr ("head" ),
1112+ OldPath : gitlab .Ptr (mockPath ),
1113+ NewPath : gitlab .Ptr (mockPath ),
1114+ PositionType : gitlab .Ptr ("text" ),
1115+ OldLine : gitlab .Ptr (3 ),
1116+ }),
1117+ }).ReturnJSON (gitlab.Response {})
1118+ }),
1119+ errorHandler : func (err error ) error {
1120+ return err
1121+ },
1122+ },
1123+ {
1124+ description : "unmodified rule, no diff" ,
1125+ timeout : time .Minute ,
1126+ maxComments : 1 ,
1127+ summary : reporter .NewSummary ([]reporter.Report {
1128+ {
1129+ Path : discovery.Path {
1130+ SymlinkTarget : mockPath ,
1131+ Name : mockPath ,
1132+ },
1133+ ModifiedLines : []int {4 , 5 },
1134+ Rule : mockFile .Groups [0 ].Rules [0 ],
1135+ Problem : checks.Problem {
1136+ Reporter : "a" ,
1137+ Summary : "foo error1" ,
1138+ Details : "foo details" ,
1139+ Diagnostics : []diags.Diagnostic {},
1140+ Lines : diags.LineRange {First : 1 , Last : 3 },
1141+ Severity : checks .Fatal ,
1142+ Anchor : checks .AnchorAfter ,
1143+ },
1144+ },
1145+ }),
1146+ mock : httpmock .New (func (s * httpmock.Server ) {
1147+ s .ExpectGet (apiUser ).ReturnJSON (gitlab.User {ID : 123 })
1148+ s .ExpectGet (apiOpenMergeRequests ).ReturnJSON ([]gitlab.BasicMergeRequest {
1149+ {IID : 1 },
1150+ })
1151+ s .ExpectGet (apiVersions (1 )).ReturnJSON ([]gitlab.MergeRequestDiffVersion {
1152+ {ID : 2 , HeadCommitSHA : "head" , BaseCommitSHA : "base" , StartCommitSHA : "start" },
1153+ {ID : 1 , HeadCommitSHA : "head" , BaseCommitSHA : "base" , StartCommitSHA : "start" },
1154+ })
1155+ s .ExpectGet (apiDiffs (1 )).ReturnJSON ([]gitlab.MergeRequestDiff {
1156+ {
1157+ Diff : "" ,
1158+ NewPath : mockPath ,
1159+ OldPath : mockPath ,
1160+ },
1161+ })
1162+ s .ExpectGet (apiDiscussions (1 , true )).ReturnJSON ([]gitlab.Discussion {})
1163+ s .ExpectPost (apiDiscussions (1 , false )).WithBodyJSON (gitlab.CreateMergeRequestDiscussionOptions {
1164+ Body : discBody ("a" , "foo error1" , "foo details" ),
1165+ Position : gitlab .Ptr (gitlab.PositionOptions {
1166+ BaseSHA : gitlab .Ptr ("base" ),
1167+ StartSHA : gitlab .Ptr ("start" ),
1168+ HeadSHA : gitlab .Ptr ("head" ),
1169+ OldPath : gitlab .Ptr (mockPath ),
1170+ NewPath : gitlab .Ptr (mockPath ),
1171+ PositionType : gitlab .Ptr ("text" ),
1172+ OldLine : gitlab .Ptr (3 ),
1173+ NewLine : gitlab .Ptr (3 ),
1174+ }),
1175+ }).ReturnJSON (gitlab.Response {})
1176+ }),
1177+ errorHandler : func (err error ) error {
1178+ return err
1179+ },
1180+ },
9811181 }
9821182
9831183 for _ , tc := range testCases {
0 commit comments