func TestProxy(modules []*TestModule) *http.ServeMux {
	// Group different modules of a module together, so that we can get
	// the latest modules and create the list endpoint.
	byModule := make(map[string][]*TestModule)
	for _, m := range modules {
		byModule[m.ModulePath] = append(byModule[m.ModulePath], m)
	}

	mux := http.NewServeMux()
	for modPath, modVersions := range byModule {
		sort.Slice(modVersions, func(i, j int) bool {
			return semver.Compare(modVersions[i].Version, modVersions[j].Version) < 0
		})
		handle := func(path string, content io.ReadSeeker) {
			mux.HandleFunc(path, func(w http.ResponseWriter, r *http.Request) {
				http.ServeContent(w, r, path, time.Now(), content)
			})
		}
		latest := func(modVersions []*TestModule) string {
			return modVersions[len(modVersions)-1].Version
		}
		master := func(modVersions []*TestModule) string {
			// TODO(https://golang.org/issue/39985): master should return the
			// most recently published version, which is not necessarily the
			// latest version according to semver.
			return modVersions[len(modVersions)-1].Version
		}
		handle(fmt.Sprintf("/%s/@v/list", modPath), strings.NewReader(versionList(modVersions)))
		handle(fmt.Sprintf("/%s/@latest", modPath), strings.NewReader(defaultInfo(latest(modVersions))))
		handle(fmt.Sprintf("/%s/@v/master.info", modPath), strings.NewReader(defaultInfo(master(modVersions))))
		for _, m := range modVersions {
			handle(fmt.Sprintf("/%s/@v/%s.info", m.ModulePath, m.Version), strings.NewReader(defaultInfo(m.Version)))
			handle(fmt.Sprintf("/%s/@v/%s.mod", m.ModulePath, m.Version), strings.NewReader(goMod(m)))
			handle(fmt.Sprintf("/%s/@v/%s.zip", m.ModulePath, m.Version), bytes.NewReader(m.zip))
		}
	}
	return mux
}
// TestProxy implements a fake proxy, hosting the given modules. If modules
// is nil, it serves the modules in the testdata directory.
TestProxy implements a fake proxy, hosting the given modules. If modules
is nil, it serves the modules in the testdata directory.
// TestProxy implements a fake proxy hosting the given modules . If modules // is nil it serves the modules in the testdata directory .
func TestProxy(modules []*TestModule) *http.ServeMux {
	byModule := make(map[string][]*TestModule)
	for _, m := range modules {
		byModule[m.ModulePath] = append(byModule[m.ModulePath], m)
	}
	mux := http.NewServeMux()
	for modPath, modVersions := range byModule {
		sort.Slice(modVersions, func(i, j int) bool {
			return semver.Compare(modVersions[i].Version, modVersions[j].Version) < 0
		})
		handle := func(path string, content io.ReadSeeker) {
			mux.HandleFunc(path, func(w http.ResponseWriter, r *http.Request) {
				http.ServeContent(w, r, path, time.Now(), content)
			})
		}
		latest := func(modVersions []*TestModule) string {
			return modVersions[len(modVersions)-1].Version
		}
		master := func(modVersions []*TestModule) string {
			return modVersions[len(modVersions)-1].Version
		}
		handle(fmt.Sprintf("/%s/@v/list", modPath), strings.NewReader(versionList(modVersions)))
		handle(fmt.Sprintf("/%s/@latest", modPath), strings.NewReader(defaultInfo(latest(modVersions))))
		handle(fmt.Sprintf("/%s/@v/master.info", modPath), strings.NewReader(defaultInfo(master(modVersions))))
		for _, m := range modVersions {
			handle(fmt.Sprintf("/%s/@v/%s.info", m.ModulePath, m.Version), strings.NewReader(defaultInfo(m.Version)))
			handle(fmt.Sprintf("/%s/@v/%s.mod", m.ModulePath, m.Version), strings.NewReader(goMod(m)))
			handle(fmt.Sprintf("/%s/@v/%s.zip", m.ModulePath, m.Version), bytes.NewReader(m.zip))
		}
	}
	return mux
}
func TestProxy ( modules [ ] * TestModule ) * http . ServeMux { byModule := make ( map [ string ] [ ] * TestModule ) for _ , m := range modules { byModule [ m . ModulePath ] = append ( byModule [ m . ModulePath ] , m ) } mux := http . NewServeMux ( ) for modPath , modVersions := range byModule { sort . Slice ( modVersions , func ( i , j int ) bool { return semver . Compare ( modVersions [ i ] . Version , modVersions [ j ] . Version ) < 0 } ) handle := func ( path string , content io . ReadSeeker ) { mux . HandleFunc ( path , func ( w http . ResponseWriter , r * http . Request ) { http . ServeContent ( w , r , path , time . Now ( ) , content ) } ) } latest := func ( modVersions [ ] * TestModule ) string { return modVersions [ len ( modVersions ) - 1 ] . Version } master := func ( modVersions [ ] * TestModule ) string { return modVersions [ len ( modVersions ) - 1 ] . Version } handle ( fmt . Sprintf ( " " , modPath ) , strings . NewReader ( versionList ( modVersions ) ) ) handle ( fmt . Sprintf ( " " , modPath ) , strings . NewReader ( defaultInfo ( latest ( modVersions ) ) ) ) handle ( fmt . Sprintf ( " " , modPath ) , strings . NewReader ( defaultInfo ( master ( modVersions ) ) ) ) for _ , m := range modVersions { handle ( fmt . Sprintf ( " " , m . ModulePath , m . Version ) , strings . NewReader ( defaultInfo ( m . Version ) ) ) handle ( fmt . Sprintf ( " " , m . ModulePath , m . Version ) , strings . NewReader ( goMod ( m ) ) ) handle ( fmt . Sprintf ( " " , m . ModulePath , m . Version ) , bytes . NewReader ( m . zip ) ) } } return mux }
TestProxy implements a fake proxy, hosting the given modules.
TestProxy implements a fake proxy hosting the given modules .
// Group different modules of a module together, so that we can get // the latest modules and create the list endpoint. // TODO(https://golang.org/issue/39985): master should return the // most recently published version, which is not necessarily the // latest version according to semver.