-
Notifications
You must be signed in to change notification settings - Fork 133
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use terraform-exec #268
Use terraform-exec #268
Conversation
Move exec tests to exec_mock_test.go since they don't use the concrete implementation.
internal/terraform/exec/exec.go
Outdated
} | ||
tf.SetLogger(e.logger) | ||
|
||
// TODO: make sense of how this works |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still need to reason about how this worked
version := strings.TrimPrefix(lines[0], "Terraform v") | ||
|
||
return version, nil | ||
// TODO: consider refactoring codebase to work directly with go-version.Version |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I noticed a fair bit of back and forth between go-version.Version
and the stringified representation. I think given I saw go-version
types bled onto a few structs throughout the codebade, and given terraform-exec
works with it directly it may be worth changing the language server codebase to work directly in that type, in a follow up PR.
return formatterForVersion(v, m.Format) | ||
} | ||
|
||
func (m *mockExecutor) run(ctx context.Context, args ...string) ([]byte, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the mockExecutor
is essentially a stripped down copy of the previous "melded" implementation we had before
@@ -13,3 +17,82 @@ func TestMain(m *testing.M) { | |||
|
|||
os.Exit(m.Run()) | |||
} | |||
|
|||
func TestExec_timeout(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These tests were moved out of exec_test.go
because I felt it was just testing the mock.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah i think you can just drop them
@@ -210,65 +112,30 @@ func (e *Executor) FormatterForVersion(v string) (Formatter, error) { | |||
} | |||
|
|||
if ver.GreaterThanOrEqual(fmtCapableVersion) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could move this version compatibility check to terraform-exec
if you wanted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is something @radeksimko upstreaming now. Depending on the outcome of the upstreaming work, this PR may be superseded.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return &schemas, nil | ||
func contextWithTimeout(ctx context.Context, timeout time.Duration) (context.Context, context.CancelFunc) { | ||
cancel := func() {} | ||
if timeout > 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should it just be a WithCancel
if its zero?
Just to summarize what we discussed via Zoom today:
|
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. |
Will bump terraform-exec to proper release before merging, but ready for review. Previously we maintained an "executor" library internally, the implementation had a nice trick that allowed it to become mocked for unit testing. While switching to terraform-exec was relatively easy, decoupling the built in mock required some refactoring.
This represents the least obtrusive drop in replacement of terraform-exec I could think of. With further refactoring we could likely remove the wrapping
Executor
struct. This refactor tried to strictly follow placing the responsibility of interface definitions on the consuming packages, which allows the producing packages to work in concrete types, and thus not forcing 1 large monolithic interface just for the sake of a mock to build up, albeit the interface created inrootmodule
covers most of the surface area.Closes #266