Skip to content

Commit

Permalink
installer: align Install with Ensure & test it (#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
radeksimko authored Nov 11, 2021
1 parent 38e1640 commit 489c6f6
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
14 changes: 14 additions & 0 deletions installer.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,25 @@ func (i *Installer) Ensure(ctx context.Context, sources []src.Source) (string, e
func (i *Installer) Install(ctx context.Context, sources []src.Installable) (string, error) {
var errs *multierror.Error

i.removableSources = make([]src.Removable, 0)

for _, source := range sources {
if srcWithLogger, ok := source.(src.LoggerSettable); ok {
srcWithLogger.SetLogger(i.logger)
}

if srcValidatable, ok := source.(src.Validatable); ok {
err := srcValidatable.Validate()
if err != nil {
errs = multierror.Append(errs, err)
continue
}
}

if s, ok := source.(src.Removable); ok {
i.removableSources = append(i.removableSources, s)
}

execPath, err := source.Install(ctx)
if err != nil {
if errors.IsErrorSkippable(err) {
Expand Down
24 changes: 24 additions & 0 deletions installer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,27 @@ func TestInstaller_Ensure(t *testing.T) {
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 := 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)
}
}

0 comments on commit 489c6f6

Please sign in to comment.