github.com/cycloidio/terraform@v1.1.10-0.20220513142504-76d5c768dc63/addrs/output_value_test.go (about) 1 package addrs 2 3 import ( 4 "fmt" 5 "testing" 6 ) 7 8 func TestAbsOutputValueInstanceEqual_true(t *testing.T) { 9 foo, diags := ParseModuleInstanceStr("module.foo") 10 if len(diags) > 0 { 11 t.Fatalf("unexpected diags: %s", diags.Err()) 12 } 13 foobar, diags := ParseModuleInstanceStr("module.foo[1].module.bar") 14 if len(diags) > 0 { 15 t.Fatalf("unexpected diags: %s", diags.Err()) 16 } 17 18 ovs := []AbsOutputValue{ 19 foo.OutputValue("a"), 20 foobar.OutputValue("b"), 21 } 22 for _, r := range ovs { 23 t.Run(r.String(), func(t *testing.T) { 24 if !r.Equal(r) { 25 t.Fatalf("expected %#v to be equal to itself", r) 26 } 27 }) 28 } 29 } 30 31 func TestAbsOutputValueInstanceEqual_false(t *testing.T) { 32 foo, diags := ParseModuleInstanceStr("module.foo") 33 if len(diags) > 0 { 34 t.Fatalf("unexpected diags: %s", diags.Err()) 35 } 36 foobar, diags := ParseModuleInstanceStr("module.foo[1].module.bar") 37 if len(diags) > 0 { 38 t.Fatalf("unexpected diags: %s", diags.Err()) 39 } 40 41 testCases := []struct { 42 left AbsOutputValue 43 right AbsOutputValue 44 }{ 45 { 46 foo.OutputValue("a"), 47 foo.OutputValue("b"), 48 }, 49 { 50 foo.OutputValue("a"), 51 foobar.OutputValue("a"), 52 }, 53 } 54 for _, tc := range testCases { 55 t.Run(fmt.Sprintf("%s = %s", tc.left, tc.right), func(t *testing.T) { 56 if tc.left.Equal(tc.right) { 57 t.Fatalf("expected %#v not to be equal to %#v", tc.left, tc.right) 58 } 59 60 if tc.right.Equal(tc.left) { 61 t.Fatalf("expected %#v not to be equal to %#v", tc.right, tc.left) 62 } 63 }) 64 } 65 }