-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgogetd_test.go
More file actions
70 lines (61 loc) · 1.59 KB
/
gogetd_test.go
File metadata and controls
70 lines (61 loc) · 1.59 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
package main
import (
"testing"
"github.com/stretchr/testify/require"
)
const selfModuleName = "github.com/otaviof/go-get-d"
func TestGoGetD_ParseURL(t *testing.T) {
tests := []struct {
name string // test case short description
input string // raw input given to GoGetD
module string // expected module name parsed
wantErr bool // error is expected on the test case
}{{
name: "Regular GitHub HTTP repository",
input: "https://github.com/otaviof/go-get-d.git",
module: selfModuleName,
wantErr: false,
}, {
name: "Go Module",
input: selfModuleName,
module: selfModuleName,
wantErr: false,
}, {
name: "Invalid URL",
input: "something invalid...",
wantErr: true,
}}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
g := NewGoGetD()
g.input = tt.input
if err := g.parseURL(); (err != nil) != tt.wantErr {
t.Errorf("GoGetD.ParseURL() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !tt.wantErr {
if tt.module != g.module {
t.Errorf("GoGetD.ParseURL() module name mismatch = %q, want %q",
g.module, tt.module)
}
if g.repositoryURL == nil {
t.Error("GoGetD.ParseURL() g.repositoryURL is nil")
}
}
})
}
}
func TestGoGetD_ModuleDir(t *testing.T) {
g := NewGoGetD()
g.input = selfModuleName
g.module = selfModuleName
t.Run("LookupModuleDirInGopath", func(t *testing.T) {
err := g.lookupModuleDirInGopath()
require.NoError(t, err)
require.NotEmpty(t, g.fullPath)
})
t.Run("ModuleDirExists", func(t *testing.T) {
exists := g.moduleDirExits()
require.True(t, exists)
})
}