-
Notifications
You must be signed in to change notification settings - Fork 19
/
fs_test.go
104 lines (87 loc) · 2.33 KB
/
fs_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
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package fs
import (
"context"
"os"
"testing"
"github.com/hashicorp/go-version"
"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"
)
var (
_ src.Findable = &AnyVersion{}
_ src.LoggerSettable = &AnyVersion{}
_ src.Findable = &ExactVersion{}
_ src.LoggerSettable = &ExactVersion{}
_ src.Findable = &Version{}
_ src.LoggerSettable = &Version{}
)
func TestExactVersion(t *testing.T) {
t.Skip("TODO")
testutil.EndToEndTest(t)
// TODO: mock out command execution?
t.Setenv("PATH", "")
ev := &ExactVersion{
Product: product.Terraform,
Version: version.Must(version.NewVersion("0.14.0")),
}
ev.SetLogger(testutil.TestLogger())
_, err := ev.Find(context.Background())
if err != nil {
t.Fatal(err)
}
}
func TestVersion(t *testing.T) {
testutil.EndToEndTest(t)
ctx := context.Background()
p := t.TempDir()
t.Setenv("PATH", p)
ev := releases.ExactVersion{
Product: product.Terraform,
Version: version.Must(version.NewVersion("1.1.0")),
InstallDir: p,
}
ev.SetLogger(testutil.TestLogger())
execPath, err := ev.Install(ctx)
if err != nil {
t.Fatalf("installing release version failed: %v", err)
}
// Version matches constraint
v := &Version{
Product: product.Terraform,
Constraints: version.MustConstraints(version.NewConstraint(">= 1.1")),
}
v.SetLogger(testutil.TestLogger())
if _, err := v.Find(ctx); err != nil {
// this occasionally fails on Windows and we don't know why
t.Logf("Terraform installed to %q", execPath)
t.Logf("PATH: %q", os.Getenv("PATH"))
t.Logf("PATHEXT: %q", os.Getenv("PATHEXT"))
fi, err := os.Stat(execPath)
if err != nil {
t.Logf("stat failed: %s", err)
} else {
t.Logf("exec path %s FileInfo:\n"+
" - Size: %d bytes\n"+
" - ModTime: %s\n"+
" - Perm: %s\n"+
" - IsDir?: %t\n"+
" - IsRegular?: %t\n",
execPath,
fi.Size(),
fi.ModTime(),
fi.Mode().Perm(),
fi.Mode().IsDir(),
fi.Mode().IsRegular())
}
t.Fatalf("finding: %v", err)
}
// Version mismatches constraint
v.Constraints = version.MustConstraints(version.NewConstraint("> 1.1"))
if _, err := v.Find(ctx); err == nil {
t.Fatal("expecting error")
}
}