File tree 3 files changed +95
-2
lines changed
3 files changed +95
-2
lines changed Original file line number Diff line number Diff line change 1
1
package install
2
+
3
+ import (
4
+ "context"
5
+ "testing"
6
+
7
+ "github.com/hashicorp/hc-install/internal/testutil"
8
+ "github.com/hashicorp/hc-install/product"
9
+ "github.com/hashicorp/hc-install/releases"
10
+ "github.com/hashicorp/hc-install/src"
11
+ )
12
+
13
+ func TestInstaller_Ensure (t * testing.T ) {
14
+ testutil .EndToEndTest (t )
15
+
16
+ // most of this logic is already tested within individual packages
17
+ // so this is just a simple E2E test to ensure the public API
18
+ // also works and continues working
19
+
20
+ i := NewInstaller ()
21
+ _ , err := i .Ensure (context .Background (), []src.Source {
22
+ & releases.LatestVersion {
23
+ Product : product .Terraform ,
24
+ },
25
+ })
26
+ if err != nil {
27
+ t .Fatal (err )
28
+ }
29
+ }
Original file line number Diff line number Diff line change @@ -3,8 +3,8 @@ package validators
3
3
import "regexp"
4
4
5
5
var (
6
- productNameRe = regexp .MustCompile (`/ [a-z0-9-]+/ ` )
7
- binaryNameRe = regexp .MustCompile (`/ [a-zA-Z0-9-_.]+/ ` )
6
+ productNameRe = regexp .MustCompile (`^ [a-z0-9-]+$ ` )
7
+ binaryNameRe = regexp .MustCompile (`^ [a-zA-Z0-9-_.]+$ ` )
8
8
)
9
9
10
10
// IsProductNameValid provides early user-facing validation of a product name
Original file line number Diff line number Diff line change
1
+ package validators
2
+
3
+ import "testing"
4
+
5
+ func TestIsProductNameValid (t * testing.T ) {
6
+ testCases := []struct {
7
+ name string
8
+ expectedValid bool
9
+ }{
10
+ {
11
+ "terraform" ,
12
+ true ,
13
+ },
14
+ {
15
+ "in.valid" ,
16
+ false ,
17
+ },
18
+ }
19
+ for _ , tc := range testCases {
20
+ isValid := IsProductNameValid (tc .name )
21
+ if ! isValid && tc .expectedValid {
22
+ t .Fatalf ("expected %q to be valid" , tc .name )
23
+ }
24
+ if isValid && ! tc .expectedValid {
25
+ t .Fatalf ("expected %q to be invalid" , tc .name )
26
+ }
27
+ }
28
+ }
29
+
30
+ func TestIsBinaryNameValid (t * testing.T ) {
31
+ testCases := []struct {
32
+ name string
33
+ expectedValid bool
34
+ }{
35
+ {
36
+ "terraform" ,
37
+ true ,
38
+ },
39
+ {
40
+ "Terraform" ,
41
+ true ,
42
+ },
43
+ {
44
+ "va_lid" ,
45
+ true ,
46
+ },
47
+ {
48
+ "va.lid" ,
49
+ true ,
50
+ },
51
+ {
52
+ "in/valid" ,
53
+ false ,
54
+ },
55
+ }
56
+ for _ , tc := range testCases {
57
+ isValid := IsBinaryNameValid (tc .name )
58
+ if ! isValid && tc .expectedValid {
59
+ t .Fatalf ("expected %q to be valid" , tc .name )
60
+ }
61
+ if isValid && ! tc .expectedValid {
62
+ t .Fatalf ("expected %q to be invalid" , tc .name )
63
+ }
64
+ }
65
+ }
You can’t perform that action at this time.
0 commit comments