Skip to content
This repository was archived by the owner on Jun 29, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions pkg/terraform/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -534,10 +534,8 @@ func (ex *Executor) checkVersion() error {
return fmt.Errorf("checking Terraform version: %w", err)
}

constraints, err := version.NewConstraint(requiredVersion)
if err != nil {
return fmt.Errorf("checking Terraform version: %w", err)
}
// requiredVersion is const, so we test it in unit tests.
constraints, _ := version.NewConstraint(requiredVersion)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can log it in debug mode? So we don't lose track of it altogether.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why? It is covered by unit tests, running exactly the same code.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's best to panic in such case, if this error should be found during development itself.


if !constraints.Check(v) {
return fmt.Errorf("version '%s' of Terraform not supported. Needed %s", v, constraints)
Expand Down
27 changes: 27 additions & 0 deletions pkg/terraform/executor_internal_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright 2020 The Lokomotive Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package terraform

import (
"testing"

"github.com/hashicorp/go-version"
)

func TestRequiredVersion(t *testing.T) {
if _, err := version.NewConstraint(requiredVersion); err != nil {
t.Fatalf("requiredVersion const must be valid version constraint, got: %v", err)
}
}