9
9
"net/http/httptest"
10
10
"os"
11
11
"os/exec"
12
- "path"
13
12
"path/filepath"
14
13
"regexp"
15
14
"sort"
@@ -799,9 +798,9 @@ func getTestCasesForDoCurationAudit() []testCase {
799
798
tech : techutils .Dotnet ,
800
799
pathToProject : filepath .Join ("projects" , "package-managers" , "dotnet" , "dotnet-curation" ),
801
800
serveResources : map [string ]string {
802
- "curated-nuget" : filepath .Join ("resources" , "feed.json" ),
803
- "index.json" : filepath .Join ("resources" , "index.json" ),
804
- "13.0.3" : filepath .Join ("resources" , "newtonsoft.json.13.0.3.nupkg" ),
801
+ "curated-nuget/index.json " : filepath .Join ("resources" , "feed.json" ),
802
+ "index.json" : filepath .Join ("resources" , "index.json" ),
803
+ "13.0.3" : filepath .Join ("resources" , "newtonsoft.json.13.0.3.nupkg" ),
805
804
},
806
805
requestToFail : map [string ]bool {
807
806
"/api/nuget/v3/curated-nuget/registration-semver2/Download/newtonsoft.json/13.0.3" : false ,
@@ -853,7 +852,7 @@ func curationServer(t *testing.T, expectedBuildRequest map[string]bool, expected
853
852
}
854
853
if r .Method == http .MethodGet {
855
854
if resourceToServe != nil {
856
- if pathToRes , ok := resourceToServe [ path . Base ( r .RequestURI )]; ok && strings .Contains (r .RequestURI , "api/curation/audit" ) {
855
+ if pathToRes := getResourceToServe ( resourceToServe , r .RequestURI ); pathToRes != "" && strings .Contains (r .RequestURI , "api/curation/audit" ) {
857
856
f , err := fileutils .ReadFile (pathToRes )
858
857
require .NoError (t , err )
859
858
f = bytes .ReplaceAll (f , []byte ("127.0.0.1:80" ), []byte (r .Host ))
@@ -880,6 +879,15 @@ func curationServer(t *testing.T, expectedBuildRequest map[string]bool, expected
880
879
return serverMock , config
881
880
}
882
881
882
+ func getResourceToServe (resourcesToServe map [string ]string , pathToRes string ) string {
883
+ for key , value := range resourcesToServe {
884
+ if strings .HasSuffix (strings .TrimSuffix (pathToRes , "/" ), key ) {
885
+ return value
886
+ }
887
+ }
888
+ return ""
889
+ }
890
+
883
891
func WriteServerDetailsConfigFileBytes (t * testing.T , url string , configPath string , withoutCreds bool ) string {
884
892
var username , password string
885
893
if ! withoutCreds {
0 commit comments