@@ -981,40 +981,49 @@ func (suite *ReposSuite) TestIntrospectRepository() {
981
981
t .Setenv ("OPTIONS_INTROSPECT_API_TIME_LIMIT_SEC" , "0" )
982
982
config .Load ()
983
983
984
- uuid := "abcadaba"
984
+ repoConfigUUID := "abcadaba"
985
985
repoUuid := "repoUuid"
986
986
intReq := api.RepositoryIntrospectRequest {ResetCount : true }
987
987
repoResp := api.RepositoryResponse {
988
988
Name : "my repo" ,
989
989
URL : "https://example.com" ,
990
- UUID : uuid ,
990
+ UUID : repoConfigUUID ,
991
991
RepositoryUUID : repoUuid ,
992
992
}
993
993
repoUpdate := dao.RepositoryUpdate {UUID : "12345" , FailedIntrospectionsCount : pointy .Int (0 ), LastIntrospectionStatus : pointy .String ("Pending" )}
994
994
now := time .Now ()
995
995
repo := dao.Repository {UUID : "12345" , LastIntrospectionTime : & now }
996
+ expectedTaskInfo := api.TaskInfoResponse {OrgId : test_handler .MockOrgId }
996
997
997
998
mockTaskClientEnqueueIntrospect (suite .tcMock , "https://example.com" , repoUuid )
998
999
999
1000
// Fetch will filter the request by Org ID before updating
1000
1001
suite .reg .Repository .On ("Update" , test .MockCtx (), repoUpdate ).Return (nil ).NotBefore (
1001
1002
suite .reg .Repository .On ("FetchForUrl" , test .MockCtx (), repoResp .URL ).Return (repo , nil ).NotBefore (
1002
- suite .reg .RepositoryConfig .WithContextMock ().On ("Fetch" , test .MockCtx (), test_handler .MockOrgId , uuid ).Return (repoResp , nil ),
1003
+ suite .reg .RepositoryConfig .WithContextMock ().On ("Fetch" , test .MockCtx (), test_handler .MockOrgId , repoConfigUUID ).Return (repoResp , nil ),
1003
1004
),
1004
1005
)
1006
+ suite .reg .TaskInfo .On ("Fetch" , test .MockCtx (), test_handler .MockOrgId , uuid .Nil .String ()).Return (expectedTaskInfo , nil )
1007
+
1005
1008
body , err := json .Marshal (intReq )
1006
1009
if err != nil {
1007
1010
t .Error ("Could not marshal JSON" )
1008
1011
}
1009
1012
1010
- req := httptest .NewRequest (http .MethodPost , api .FullRootPath ()+ "/repositories/" + uuid + "/introspect/" ,
1013
+ req := httptest .NewRequest (http .MethodPost , api .FullRootPath ()+ "/repositories/" + repoConfigUUID + "/introspect/" ,
1011
1014
bytes .NewReader (body ))
1012
1015
req .Header .Set ("Content-Type" , "application/json" )
1013
1016
req .Header .Set (api .IdentityHeader , test_handler .EncodedIdentity (t ))
1014
1017
1015
- code , _ , err := suite .serveRepositoriesRouter (req )
1018
+ code , body , err := suite .serveRepositoriesRouter (req )
1016
1019
assert .Nil (t , err )
1017
- assert .Equal (t , http .StatusNoContent , code )
1020
+
1021
+ var actualTaskInfo api.TaskInfoResponse
1022
+ err = json .Unmarshal (body , & actualTaskInfo )
1023
+ assert .Nil (t , err )
1024
+
1025
+ assert .Equal (t , actualTaskInfo , expectedTaskInfo )
1026
+ assert .Equal (t , http .StatusOK , code )
1018
1027
}
1019
1028
func (suite * ReposSuite ) TestIntrospectRepositoryFailedLimit () {
1020
1029
t := suite .T ()
@@ -1052,41 +1061,49 @@ func (suite *ReposSuite) TestCreateSnapshot() {
1052
1061
config .Get ().Features .Snapshots .Accounts = & []string {test_handler .MockAccountNumber }
1053
1062
defer resetFeatures ()
1054
1063
1055
- uuid := "abcadaba"
1064
+ repoConfigUUID := "abcadaba"
1056
1065
repoUuid := "repoUuid"
1057
1066
repoResp := api.RepositoryResponse {
1058
1067
Name : "my repo" ,
1059
1068
URL : "https://example.com" ,
1060
- UUID : uuid ,
1069
+ UUID : repoConfigUUID ,
1061
1070
RepositoryUUID : repoUuid ,
1062
1071
Snapshot : true ,
1063
1072
}
1064
1073
1065
1074
repoUpdate := dao.RepositoryUpdate {UUID : repoUuid , LastIntrospectionStatus : pointy .String (config .StatusPending )}
1066
1075
repo := dao.Repository {UUID : repoUuid }
1076
+ expectedTaskInfo := api.TaskInfoResponse {OrgId : test_handler .MockOrgId }
1067
1077
1068
1078
mockTaskClientEnqueueSnapshot (suite , & repoResp )
1069
1079
1070
1080
// Fetch will filter the request by Org ID before updating
1071
1081
suite .reg .Repository .On ("Update" , test .MockCtx (), repoUpdate ).Return (nil ).NotBefore (
1072
1082
suite .reg .TaskInfo .On ("IsTaskInProgress" , test .MockCtx (), test_handler .MockOrgId , repo .UUID , config .RepositorySnapshotTask ).Return (false , "" , nil ).
1073
- NotBefore (suite .reg .RepositoryConfig .On ("Fetch" , test .MockCtx (), test_handler .MockOrgId , uuid ).Return (repoResp , nil )),
1083
+ NotBefore (suite .reg .RepositoryConfig .On ("Fetch" , test .MockCtx (), test_handler .MockOrgId , repoConfigUUID ).Return (repoResp , nil )),
1074
1084
suite .reg .TaskInfo .On ("IsTaskInProgress" , test .MockCtx (), test_handler .MockOrgId , repo .UUID , config .IntrospectTask ).Return (false , "" , nil ).
1075
- NotBefore (suite .reg .RepositoryConfig .On ("Fetch" , test .MockCtx (), test_handler .MockOrgId , uuid ).Return (repoResp , nil )),
1085
+ NotBefore (suite .reg .RepositoryConfig .On ("Fetch" , test .MockCtx (), test_handler .MockOrgId , repoConfigUUID ).Return (repoResp , nil )),
1076
1086
)
1077
1087
1088
+ suite .reg .TaskInfo .On ("Fetch" , test .MockCtx (), test_handler .MockOrgId , uuid .Nil .String ()).Return (expectedTaskInfo , nil )
1089
+
1078
1090
body , err := json .Marshal ("" )
1079
1091
if err != nil {
1080
1092
t .Error ("Could not marshal JSON" )
1081
1093
}
1082
1094
1083
- req := httptest .NewRequest (http .MethodPost , api .FullRootPath ()+ "/repositories/" + uuid + "/snapshot/" , bytes .NewReader (body ))
1095
+ req := httptest .NewRequest (http .MethodPost , api .FullRootPath ()+ "/repositories/" + repoConfigUUID + "/snapshot/" , bytes .NewReader (body ))
1084
1096
req .Header .Set ("Content-Type" , "application/json" )
1085
1097
req .Header .Set (api .IdentityHeader , test_handler .EncodedIdentity (t ))
1086
1098
1087
- code , _ , err := suite .serveRepositoriesRouter (req )
1099
+ code , body , err := suite .serveRepositoriesRouter (req )
1088
1100
assert .Nil (t , err )
1089
- assert .Equal (t , http .StatusNoContent , code )
1101
+
1102
+ var actualTaskInfo api.TaskInfoResponse
1103
+ err = json .Unmarshal (body , & actualTaskInfo )
1104
+ assert .Nil (t , err )
1105
+
1106
+ assert .Equal (t , http .StatusOK , code )
1090
1107
}
1091
1108
1092
1109
func (suite * ReposSuite ) TestCreateSnapshotError () {
0 commit comments