github.com/hashicorp/go-getter/v2@v2.2.2/module_test.go (about)

     1  package getter
     2  
     3  import (
     4  	"net/http"
     5  	"net/http/httptest"
     6  	"net/url"
     7  	"path/filepath"
     8  
     9  	urlhelper "github.com/hashicorp/go-getter/v2/helper/url"
    10  )
    11  
    12  const fixtureDir = "./testdata"
    13  
    14  func testModule(n string) string {
    15  	p := filepath.Join(fixtureDir, n)
    16  	p, err := filepath.Abs(p)
    17  	if err != nil {
    18  		panic(err)
    19  	}
    20  	return fmtFileURL(p)
    21  }
    22  
    23  func httpTestModule(n string) *httptest.Server {
    24  	p := filepath.Join(fixtureDir, n)
    25  	p, err := filepath.Abs(p)
    26  	if err != nil {
    27  		panic(err)
    28  	}
    29  
    30  	return httptest.NewServer(http.FileServer(http.Dir(p)))
    31  }
    32  
    33  func testModuleURL(n string) *url.URL {
    34  	n, subDir := SourceDirSubdir(n)
    35  	u, err := urlhelper.Parse(testModule(n))
    36  	if err != nil {
    37  		panic(err)
    38  	}
    39  	if subDir != "" {
    40  		u.Path += "//" + subDir
    41  		u.RawPath = u.Path
    42  	}
    43  
    44  	return u
    45  }