Skip to content

Commit

Permalink
watcher: Refresh versions when schema changes
Browse files Browse the repository at this point in the history
  • Loading branch information
radeksimko committed Feb 9, 2021
1 parent 43b242d commit c24d93c
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
6 changes: 5 additions & 1 deletion internal/terraform/module/watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ func (w *watcher) processEvent(event fsnotify.Event) {
}
if containsPath(mod.Watchable.PluginLockFiles, eventPath) {
w.modMgr.EnqueueModuleOp(mod.Path, OpTypeObtainSchema)
w.modMgr.EnqueueModuleOp(mod.Path, OpTypeGetTerraformVersion)
return
}
}
Expand All @@ -150,7 +151,9 @@ func (w *watcher) processEvent(event fsnotify.Event) {
return w.modMgr.EnqueueModuleOp(mod.Path, OpTypeParseModuleManifest)
}
if containsPath(mod.Watchable.PluginLockFiles, path) {
return w.modMgr.EnqueueModuleOp(mod.Path, OpTypeObtainSchema)
w.modMgr.EnqueueModuleOp(mod.Path, OpTypeObtainSchema)
w.modMgr.EnqueueModuleOp(mod.Path, OpTypeGetTerraformVersion)
return nil
}
return nil
})
Expand All @@ -165,6 +168,7 @@ func (w *watcher) processEvent(event fsnotify.Event) {

if containsPath(mod.Watchable.PluginLockFiles, eventPath) {
w.modMgr.EnqueueModuleOp(mod.Path, OpTypeObtainSchema)
w.modMgr.EnqueueModuleOp(mod.Path, OpTypeGetTerraformVersion)
return
}
}
Expand Down
24 changes: 24 additions & 0 deletions internal/terraform/module/watcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"time"

"github.com/google/go-cmp/cmp"
"github.com/hashicorp/go-version"
"github.com/hashicorp/terraform-json"
"github.com/hashicorp/terraform-ls/internal/filesystem"
"github.com/hashicorp/terraform-ls/internal/terraform/exec"
Expand Down Expand Up @@ -45,6 +46,17 @@ func TestWatcher_initFromScratch(t *testing.T) {
nil,
},
},
{
Method: "Version",
Arguments: []interface{}{
mock.AnythingOfType("*context.cancelCtx"),
},
ReturnArguments: []interface{}{
version.Must(version.NewVersion("1.0.0")),
nil,
nil,
},
},
},
},
},
Expand Down Expand Up @@ -114,4 +126,16 @@ resource "aws_vpc" "example" {
if diff := cmp.Diff(psMock, ps); diff != "" {
t.Fatalf("schema mismatch: %s", diff)
}

v, err := mod.TerraformVersion()
if err != nil {
t.Fatal(err)
}
if v == nil {
t.Fatal("expected non-nil version")
}
if v.String() != "1.0.0" {
t.Fatalf("version mismatch.\ngiven: %q\nexpected: %q",
v.String(), "1.0.0")
}
}

0 comments on commit c24d93c

Please sign in to comment.