-
Notifications
You must be signed in to change notification settings - Fork 131
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for Stacks feature (#1879)
* Add tests for Stacks related jobs * Add tests for Stacks state store * Add changelog
- Loading branch information
Showing
10 changed files
with
1,015 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
kind: INTERNAL | ||
body: Add tests for Stacks feature | ||
time: 2024-11-28T14:57:42.823414+01:00 | ||
custom: | ||
Issue: "1879" | ||
Repository: terraform-ls |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
package jobs | ||
|
||
import ( | ||
"context" | ||
"path/filepath" | ||
"testing" | ||
|
||
lsctx "github.com/hashicorp/terraform-ls/internal/context" | ||
"github.com/hashicorp/terraform-ls/internal/features/stacks/ast" | ||
"github.com/hashicorp/terraform-ls/internal/features/stacks/state" | ||
"github.com/hashicorp/terraform-ls/internal/filesystem" | ||
"github.com/hashicorp/terraform-ls/internal/job" | ||
ilsp "github.com/hashicorp/terraform-ls/internal/lsp" | ||
globalState "github.com/hashicorp/terraform-ls/internal/state" | ||
globalAst "github.com/hashicorp/terraform-ls/internal/terraform/ast" | ||
"github.com/hashicorp/terraform-ls/internal/uri" | ||
) | ||
|
||
func TestParseStackConfiguration(t *testing.T) { | ||
ctx := context.Background() | ||
gs, err := globalState.NewStateStore() | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
ss, err := state.NewStackStore(gs.ChangeStore, gs.ProviderSchemas) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
testData, err := filepath.Abs("testdata") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
testFs := filesystem.NewFilesystem(gs.DocumentStore) | ||
|
||
simpleStackPath := filepath.Join(testData, "simple-stack") | ||
|
||
err = ss.Add(simpleStackPath) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
ctx = lsctx.WithDocumentContext(ctx, lsctx.Document{}) | ||
err = ParseStackConfiguration(ctx, testFs, ss, simpleStackPath) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
before, err := ss.StackRecordByPath(simpleStackPath) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
// ignore job state | ||
ctx = job.WithIgnoreState(ctx, true) | ||
|
||
// say we're coming from did_change request | ||
componentsURI, err := filepath.Abs(filepath.Join(simpleStackPath, "components.tfstack.hcl")) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
x := lsctx.Document{ | ||
Method: "textDocument/didChange", | ||
LanguageID: ilsp.Stacks.String(), | ||
URI: uri.FromPath(componentsURI), | ||
} | ||
ctx = lsctx.WithDocumentContext(ctx, x) | ||
err = ParseStackConfiguration(ctx, testFs, ss, simpleStackPath) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
after, err := ss.StackRecordByPath(simpleStackPath) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
componentsFile := ast.StackFilename("components.tfstack.hcl") | ||
// test if components.tfstack.hcl is not the same as first seen | ||
if before.ParsedFiles[componentsFile] == after.ParsedFiles[componentsFile] { | ||
t.Fatal("file should mismatch") | ||
} | ||
|
||
variablesFile := ast.StackFilename("variables.tfstack.hcl") | ||
// test if variables.tfstack.hcl is the same as first seen | ||
if before.ParsedFiles[variablesFile] != after.ParsedFiles[variablesFile] { | ||
t.Fatal("file mismatch") | ||
} | ||
|
||
// examine diags should change for components.tfstack.hcl | ||
if before.Diagnostics[globalAst.HCLParsingSource][componentsFile][0] == after.Diagnostics[globalAst.HCLParsingSource][componentsFile][0] { | ||
t.Fatal("diags should mismatch") | ||
} | ||
|
||
// examine diags should not change for variables.tfstack.hcl | ||
if before.Diagnostics[globalAst.HCLParsingSource][variablesFile][0] != after.Diagnostics[globalAst.HCLParsingSource][variablesFile][0] { | ||
t.Fatal("diags should match") | ||
} | ||
} |
Oops, something went wrong.