Copyright 2019 The Go Authors. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.

package proxy

import (
	
	
	
	

	
	
	
)
SetupTestClient creates a fake module proxy for testing using the given test version information. It returns a function for tearing down the proxy after the test is completed and a Client for interacting with the test proxy.
func ( *testing.T,  []*Module) (*Client, func()) {
	.Helper()
	 := NewServer()
	, ,  := NewClientForServer()
	if  != nil {
		.Fatal()
	}
	return , 
}
NewClientForServer starts serving proxyMux locally. It returns a client to the server and a function to shut down the server.
override client.httpClient to skip TLS verification
	, ,  := testhelper.SetupTestClientAndServer(.mux)
	,  := New(.URL)
	if  != nil {
		return nil, nil, 
	}
	.httpClient = 
	return , , nil
}
LoadTestModules reads the modules in the given directory. Each file in that directory with a .txtar extension should be named "path@version" and should be in txtar format (golang.org/x/tools/txtar). The path part of the filename will be preceded by "example.com/" and colons will be replaced by slashes to form a full module path. The file contents are used verbatim except that some variables beginning with "$" are substituted with predefined strings. LoadTestModules panics if there is an error reading any of the files.
func ( string) []*Module {
	,  := filepath.Glob(filepath.Join(, "*.txtar"))
	if  != nil {
		panic()
	}
	var  []*Module
	for ,  := range  {
		,  := readTxtarModule()
		if  != nil {
			panic()
		}
		 = append(, )
	}
	return 
}

var testModuleReplacer = strings.NewReplacer(
	"$MITLicense", testhelper.MITLicense,
	"$BSD0License", testhelper.BSD0License,
)

func ( string) (*Module, error) {
	 := strings.TrimSuffix(filepath.Base(), filepath.Ext())
	 := strings.IndexRune(, '@')
	if  < 0 {
		return nil, fmt.Errorf("%s: filename missing '@'", )
	}
	,  := "example.com/"+[:], [+1:]
	 = strings.ReplaceAll(, ":", "/")
	if  == "" ||  == "" {
		return nil, fmt.Errorf("%s: empty module path or version", )
	}
	 := &Module{
		ModulePath: ,
		Version:    ,
		Files:      map[string]string{},
	}
	,  := txtar.ParseFile()
	if  != nil {
		return nil, 
	}
	for ,  := range .Files {
Overwrite the pregenerated module path if one is specified in the go.mod file.
FindModule returns the module in mods with the given path and version, or nil if there isn't one. An empty version argument matches any version.
func ( []*Module, ,  string) *Module {
	for ,  := range  {
		if .ModulePath ==  && ( == "" || .Version == ) {
			return 
		}
	}
	return nil