Skip to content

Commit

Permalink
w
Browse files Browse the repository at this point in the history
  • Loading branch information
jpogran committed Sep 19, 2023
1 parent fa62eb9 commit 3956181
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 6 deletions.
39 changes: 34 additions & 5 deletions internal/terraform/module/module_ops_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"log"
"net/http"
"net/http/httptest"
"os"
"path/filepath"
"sync"
"testing"
Expand Down Expand Up @@ -972,11 +973,26 @@ func TestParseModuleConfiguration(t *testing.T) {
t.Fatal(err)
}

fmt.Println("--------before---------")
fmt.Println(string(before.ParsedModuleFiles["foo.tf"].Bytes))
fmt.Println("--------before---------")


f, err := os.OpenFile(filepath.Join(singleFileModulePath, "foo.tf"),
os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
if err != nil {
t.Fatal(err)
}
if _, err := f.WriteString("\n\nvariable \"awesome\" {\n\n}\n"); err != nil {
t.Fatal(err)
}
f.Close()

// ignore job state
ctx = job.WithIgnoreState(ctx, true)

// say we're coming from did_change request
fooURI, _ := filepath.Abs("testdata/single-file-change-module/foo.tf")
fooURI, _ := filepath.Abs(filepath.Join(singleFileModulePath, "foo.tf"))
x := lsctx.RPCContextData{
Method: "textDocument/didChange",
URI: uri.FromPath(fooURI),
Expand All @@ -991,18 +1007,31 @@ func TestParseModuleConfiguration(t *testing.T) {
if err != nil {
t.Fatal(err)
}
fmt.Println("--------after---------")
fmt.Println(string(after.ParsedModuleFiles["foo.tf"].Bytes))
fmt.Println("--------after---------")


// test if foo.tf is not the same as first seen
if before.ParsedModuleFiles["foo.tf"] != after.ParsedModuleFiles["foo.tf"] {
t.Fatal("linked file mismatch")
if before.ParsedModuleFiles["foo.tf"] == after.ParsedModuleFiles["foo.tf"] {
t.Fatal("file should mismatch")
}

// test if main.tf is the same as first seen
if before.ParsedModuleFiles["main.tf"] == after.ParsedModuleFiles["main.tf"] {
t.Fatal("linked file mismatch")
t.Fatal("file mismatch")
}

// TODO examine diags should change for foo.tf
// examine diags should change for foo.tf
diagsBefore := before.ModuleDiagnostics["foo.tf"]
diagsAfter := after.ModuleDiagnostics["foo.tf"]
// if before.ModuleDiagnostics["foo.tf"] == after.ModuleDiagnostics["foo.tf"] {
// t.Fatal("diags should mismatch")
// }

if diff := cmp.Diff(diagsBefore, diagsAfter, ctydebug.CmpOptions); diff != "" {
t.Fatalf("diags should mismatch: %s", diff)
}
}

func gzipCompressBytes(t *testing.T, b []byte) []byte {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
variable "gogo" {

}
}


variable "awesome" {

}

0 comments on commit 3956181

Please sign in to comment.