// Copyright 2024 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 cryptotest

import (
	
	
	
	
	
)

// FetchModule fetches the module at the given version and returns the directory
// containing its source tree. It skips the test if fetching modules is not
// possible in this environment.
func ( *testing.T, ,  string) string {
	testenv.MustHaveExternalNetwork()
	 := testenv.GoToolPath()

	// If the default GOMODCACHE doesn't exist, use a temporary directory
	// instead. (For example, run.bash sets GOPATH=/nonexist-gopath.)
	,  := testenv.Command(, , "env", "GOMODCACHE").Output()
	if  != nil {
		.Fatalf("%s env GOMODCACHE: %v\n%s", , , )
	}
	 := false
	if  := string(bytes.TrimSpace());  != "" {
		if ,  := os.Stat();  == nil {
			 = true
		}
	}
	if ! {
		.Setenv("GOMODCACHE", .TempDir())
		// Allow t.TempDir() to clean up subdirectories.
		.Setenv("GOFLAGS", os.Getenv("GOFLAGS")+" -modcacherw")
	}

	.Logf("fetching %s@%s\n", , )

	,  := testenv.Command(, , "mod", "download", "-json", +"@"+).CombinedOutput()
	if  != nil {
		.Fatalf("failed to download %s@%s: %s\n%s\n", , , , )
	}
	var  struct {
		 string
	}
	if  := json.Unmarshal(, &);  != nil {
		.Fatalf("failed to parse 'go mod download': %s\n%s\n", , )
	}

	return .
}