-
Notifications
You must be signed in to change notification settings - Fork 257
Expand file tree
/
Copy pathmodule_test.go
More file actions
70 lines (58 loc) · 1.22 KB
/
module_test.go
File metadata and controls
70 lines (58 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// Copyright IBM Corp. 2015, 2025
// SPDX-License-Identifier: MPL-2.0
package getter
import (
"net/http"
"net/http/httptest"
"net/url"
"os"
"path/filepath"
"reflect"
"testing"
urlhelper "github.com/hashicorp/go-getter/helper/url"
)
const fixtureDir = "./testdata"
func testModule(n string) string {
p := filepath.Join(fixtureDir, n)
p, err := filepath.Abs(p)
if err != nil {
panic(err)
}
return fmtFileURL(p)
}
func httpTestModule(n string) *httptest.Server {
p := filepath.Join(fixtureDir, n)
p, err := filepath.Abs(p)
if err != nil {
panic(err)
}
return httptest.NewServer(http.FileServer(http.Dir(p)))
}
func testModuleURL(n string) *url.URL {
n, subDir := SourceDirSubdir(n)
u, err := urlhelper.Parse(testModule(n))
if err != nil {
panic(err)
}
if subDir != "" {
u.Path += "//" + subDir
u.RawPath = u.Path
}
return u
}
func testURL(s string) *url.URL {
u, err := urlhelper.Parse(s)
if err != nil {
panic(err)
}
return u
}
func assertContents(t *testing.T, path string, contents string) {
data, err := os.ReadFile(path)
if err != nil {
t.Fatalf("err: %s", err)
}
if !reflect.DeepEqual(data, []byte(contents)) {
t.Fatalf("bad. expected:\n\n%s\n\nGot:\n\n%s", contents, string(data))
}
}