-
Notifications
You must be signed in to change notification settings - Fork 21
/
installer_test.go
150 lines (129 loc) · 3.43 KB
/
installer_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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package install_test
import (
"context"
"os"
"path/filepath"
"runtime"
"testing"
"github.com/hashicorp/go-version"
install "github.com/hashicorp/hc-install"
"github.com/hashicorp/hc-install/fs"
"github.com/hashicorp/hc-install/internal/testutil"
"github.com/hashicorp/hc-install/product"
"github.com/hashicorp/hc-install/releases"
"github.com/hashicorp/hc-install/src"
)
func TestInstaller_Ensure_installable(t *testing.T) {
testutil.EndToEndTest(t)
// most of this logic is already tested within individual packages
// so this is just a simple E2E test to ensure the public API
// also works and continues working
i := install.NewInstaller()
i.SetLogger(testutil.TestLogger())
ctx := context.Background()
_, err := i.Ensure(ctx, []src.Source{
&releases.LatestVersion{
Product: product.Terraform,
},
})
if err != nil {
t.Fatal(err)
}
err = i.Remove(ctx)
if err != nil {
t.Fatal(err)
}
}
func TestInstaller_Ensure_findable(t *testing.T) {
testutil.EndToEndTest(t)
dirPath, fileName := testutil.CreateTempFile(t, "")
fullPath := filepath.Join(dirPath, fileName)
err := os.Chmod(fullPath, 0700)
if err != nil {
t.Fatal(err)
}
t.Setenv("PATH", dirPath)
// most of this logic is already tested within individual packages
// so this is just a simple E2E test to ensure the public API
// also works and continues working
i := install.NewInstaller()
i.SetLogger(testutil.TestLogger())
ctx := context.Background()
_, err = i.Ensure(ctx, []src.Source{
&fs.AnyVersion{
Product: &product.Product{
BinaryName: func() string {
return fileName
},
},
},
})
if err != nil {
t.Fatal(err)
}
}
func TestInstaller_Install(t *testing.T) {
testutil.EndToEndTest(t)
// most of this logic is already tested within individual packages
// so this is just a simple E2E test to ensure the public API
// also works and continues working
i := install.NewInstaller()
i.SetLogger(testutil.TestLogger())
ctx := context.Background()
_, err := i.Install(ctx, []src.Installable{
&releases.LatestVersion{
Product: product.Terraform,
},
})
if err != nil {
t.Fatal(err)
}
err = i.Remove(ctx)
if err != nil {
t.Fatal(err)
}
}
func TestInstaller_Install_enterprise(t *testing.T) {
testutil.EndToEndTest(t)
// most of this logic is already tested within individual packages
// so this is just a simple E2E test to ensure the public API
// also works and continues working
tmpBinaryDir := t.TempDir()
tmpLicenseDir := t.TempDir()
i := install.NewInstaller()
i.SetLogger(testutil.TestLogger())
ctx := context.Background()
_, err := i.Install(ctx, []src.Installable{
&releases.ExactVersion{
Product: product.Vault,
Version: version.Must(version.NewVersion("1.9.8")),
InstallDir: tmpBinaryDir,
LicenseDir: tmpLicenseDir,
Enterprise: &releases.EnterpriseOptions{},
},
})
if err != nil {
t.Fatal(err)
}
// Ensure the binary was installed
binName := "vault"
if runtime.GOOS == "windows" {
binName = "vault.exe"
}
if _, err = os.Stat(filepath.Join(tmpBinaryDir, binName)); err != nil {
t.Fatal(err)
}
// Ensure the enterprise license files were installed
if _, err = os.Stat(filepath.Join(tmpLicenseDir, "EULA.txt")); err != nil {
t.Fatal(err)
}
if _, err = os.Stat(filepath.Join(tmpLicenseDir, "TermsOfEvaluation.txt")); err != nil {
t.Fatal(err)
}
err = i.Remove(ctx)
if err != nil {
t.Fatal(err)
}
}