7
7
8
8
"github.com/google/go-cmp/cmp"
9
9
"github.com/hashicorp/go-version"
10
+ "github.com/hashicorp/hcl-lang/lang"
11
+ "github.com/hashicorp/hcl-lang/reference"
10
12
"github.com/hashicorp/hcl/v2"
11
13
"github.com/hashicorp/hcl/v2/hclparse"
12
14
"github.com/hashicorp/hcl/v2/hclsyntax"
@@ -15,6 +17,7 @@ import (
15
17
"github.com/hashicorp/terraform-ls/internal/terraform/module/operation"
16
18
tfaddr "github.com/hashicorp/terraform-registry-address"
17
19
tfmod "github.com/hashicorp/terraform-schema/module"
20
+ "github.com/zclconf/go-cty/cty"
18
21
)
19
22
20
23
func TestModuleStore_Add_duplicate (t * testing.T ) {
@@ -508,6 +511,88 @@ dev = {
508
511
}
509
512
}
510
513
514
+ func TestModuleStore_SetVarsReferenceOriginsState (t * testing.T ) {
515
+ s , err := NewStateStore ()
516
+ if err != nil {
517
+ t .Fatal (err )
518
+ }
519
+
520
+ tmpDir := t .TempDir ()
521
+ err = s .Modules .Add (tmpDir )
522
+ if err != nil {
523
+ t .Fatal (err )
524
+ }
525
+
526
+ s .Modules .SetVarsReferenceOriginsState (tmpDir , operation .OpStateQueued )
527
+
528
+ mod , err := s .Modules .ModuleByPath (tmpDir )
529
+ if err != nil {
530
+ t .Fatal (err )
531
+ }
532
+
533
+ if diff := cmp .Diff (mod .VarsRefOriginsState , operation .OpStateQueued , cmpOpts ); diff != "" {
534
+ t .Fatalf ("unexpected module vars ref origins state: %s" , diff )
535
+ }
536
+ }
537
+
538
+ func TestModuleStore_UpdateVarsReferenceOrigins (t * testing.T ) {
539
+ s , err := NewStateStore ()
540
+ if err != nil {
541
+ t .Fatal (err )
542
+ }
543
+
544
+ tmpDir := t .TempDir ()
545
+ err = s .Modules .Add (tmpDir )
546
+ if err != nil {
547
+ t .Fatal (err )
548
+ }
549
+
550
+ origins := reference.Origins {
551
+ reference.PathOrigin {
552
+ Range : hcl.Range {
553
+ Filename : "terraform.tfvars" ,
554
+ Start : hcl.Pos {
555
+ Line : 1 ,
556
+ Column : 1 ,
557
+ Byte : 0 ,
558
+ },
559
+ End : hcl.Pos {
560
+ Line : 1 ,
561
+ Column : 5 ,
562
+ Byte : 4 ,
563
+ },
564
+ },
565
+ TargetAddr : lang.Address {
566
+ lang.RootStep {Name : "var" },
567
+ lang.AttrStep {Name : "name" },
568
+ },
569
+ TargetPath : lang.Path {
570
+ Path : tmpDir ,
571
+ LanguageID : "terraform" ,
572
+ },
573
+ Constraints : reference.OriginConstraints {
574
+ reference.OriginConstraint {
575
+ OfScopeId : "variable" ,
576
+ OfType : cty .String ,
577
+ },
578
+ },
579
+ },
580
+ }
581
+ s .Modules .UpdateVarsReferenceOrigins (tmpDir , origins , nil )
582
+
583
+ mod , err := s .Modules .ModuleByPath (tmpDir )
584
+ if err != nil {
585
+ t .Fatal (err )
586
+ }
587
+
588
+ if diff := cmp .Diff (mod .VarsRefOrigins , origins , cmpOpts ); diff != "" {
589
+ t .Fatalf ("unexpected module vars ref origins: %s" , diff )
590
+ }
591
+ if diff := cmp .Diff (mod .VarsRefOriginsState , operation .OpStateLoaded , cmpOpts ); diff != "" {
592
+ t .Fatalf ("unexpected module vars ref origins state: %s" , diff )
593
+ }
594
+ }
595
+
511
596
func BenchmarkModuleByPath (b * testing.B ) {
512
597
s , err := NewStateStore ()
513
598
if err != nil {
0 commit comments