-
Notifications
You must be signed in to change notification settings - Fork 4
/
tidy_test.go
105 lines (83 loc) · 2.61 KB
/
tidy_test.go
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
package gomodrun
import (
"io/ioutil"
"os"
"path"
"runtime"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/otiai10/copy"
)
var _ = Describe("tidy", func() {
var tempDir string
var goVersion string
BeforeSuite(func() {
var err error
goVersion, err = getGoVersion()
if err != nil {
panic(err)
}
tempDir, err = ioutil.TempDir(os.TempDir(), "gomodrun-tidy")
if err != nil {
panic(err)
}
//nolint:dogsled // Test file, don't need any of the extra values
_, filename, _, _ := runtime.Caller(0)
err = copy.Copy(path.Join(path.Dir(filename), "./tests/alternative-tools-dir"), tempDir)
if err != nil {
panic(err)
}
bins := []string{
// Bins to keep
"github.com/dustinblackman/go-hello-world-test@v0.0.2/hello-world",
// Bins to drop
"github.com/dustinblackman/go-hello-world-test@v0.0.1/hello-world",
}
emptyFolders := []string{
"github.com/dustinblackman/go-hello-world-test-no-gomod@v0.0.1",
}
for _, binPath := range bins {
fullPath := path.Join(tempDir, ".gomodrun", goVersion, binPath, path.Base(binPath))
err = os.MkdirAll(path.Dir(fullPath), 0750)
if err != nil {
panic(err)
}
emptyFile, emptyErr := os.Create(fullPath)
if emptyErr != nil {
panic(err)
}
err = emptyFile.Close()
if err != nil {
panic(err)
}
}
for _, folderPath := range emptyFolders {
fullPath := path.Join(tempDir, ".gomodrun", goVersion, folderPath)
err = os.MkdirAll(path.Dir(fullPath), 0750)
if err != nil {
panic(err)
}
}
})
AfterSuite(func() {
err := os.RemoveAll(tempDir)
if err != nil {
panic(err)
}
})
It("should clean outdated binaries and empty folders from .gomodrun", func() {
baseDir := path.Join(tempDir, ".gomodrun", goVersion)
err := Tidy(tempDir)
Expect(err).To(BeNil())
_, existsErr := os.Stat(path.Join(baseDir, "github.com/dustinblackman/go-hello-world-test@v0.0.2/hello-world/hello-world"))
Expect(os.IsNotExist(existsErr)).To(BeFalse())
_, existsErr = os.Stat(path.Join(baseDir, "github.com/dustinblackman/go-hello-world-test@v0.0.1/hello-world/hello-world"))
Expect(os.IsNotExist(existsErr)).To(BeTrue())
_, existsErr = os.Stat(path.Join(baseDir, "github.com/dustinblackman/go-hello-world-test@v0.0.1/hello-world"))
Expect(os.IsNotExist(existsErr)).To(BeTrue())
_, existsErr = os.Stat(path.Join(baseDir, "github.com/dustinblackman/go-hello-world-test@v0.0.1"))
Expect(os.IsNotExist(existsErr)).To(BeTrue())
_, existsErr = os.Stat(path.Join(baseDir, "github.com/dustinblackman/go-hello-world-test-no-gomod@v0.0.1"))
Expect(os.IsNotExist(existsErr)).To(BeTrue())
})
})