-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: incorrect validation of product & binary names (#28)
* fix: incorrect validation of product & binary names * installer: add E2E test for the public API too
- Loading branch information
1 parent
f29401f
commit e677aa4
Showing
3 changed files
with
95 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,29 @@ | ||
package install | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"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(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 := NewInstaller() | ||
_, err := i.Ensure(context.Background(), []src.Source{ | ||
&releases.LatestVersion{ | ||
Product: product.Terraform, | ||
}, | ||
}) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package validators | ||
|
||
import "testing" | ||
|
||
func TestIsProductNameValid(t *testing.T) { | ||
testCases := []struct { | ||
name string | ||
expectedValid bool | ||
}{ | ||
{ | ||
"terraform", | ||
true, | ||
}, | ||
{ | ||
"in.valid", | ||
false, | ||
}, | ||
} | ||
for _, tc := range testCases { | ||
isValid := IsProductNameValid(tc.name) | ||
if !isValid && tc.expectedValid { | ||
t.Fatalf("expected %q to be valid", tc.name) | ||
} | ||
if isValid && !tc.expectedValid { | ||
t.Fatalf("expected %q to be invalid", tc.name) | ||
} | ||
} | ||
} | ||
|
||
func TestIsBinaryNameValid(t *testing.T) { | ||
testCases := []struct { | ||
name string | ||
expectedValid bool | ||
}{ | ||
{ | ||
"terraform", | ||
true, | ||
}, | ||
{ | ||
"Terraform", | ||
true, | ||
}, | ||
{ | ||
"va_lid", | ||
true, | ||
}, | ||
{ | ||
"va.lid", | ||
true, | ||
}, | ||
{ | ||
"in/valid", | ||
false, | ||
}, | ||
} | ||
for _, tc := range testCases { | ||
isValid := IsBinaryNameValid(tc.name) | ||
if !isValid && tc.expectedValid { | ||
t.Fatalf("expected %q to be valid", tc.name) | ||
} | ||
if isValid && !tc.expectedValid { | ||
t.Fatalf("expected %q to be invalid", tc.name) | ||
} | ||
} | ||
} |