You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
helper/resource: Added error when errantly checking list, map, or set attributes in TestCheckNoResourceAttr, TestCheckResourceAttr, and TestCheckResourceAttrSet (#920)
helper/resource: Added error when errantly checking list, map, or set attributes in `TestCheckNoResourceAttr`, `TestCheckResourceAttr`, and `TestCheckResourceAttrSet`
3
+
```
4
+
5
+
```release-note:note
6
+
helper/resource: False positive checks of list, map, and set attributes with `TestCheckNoResourceAttr` and `TestCheckResourceAttrSet` will now return an error to explain how to accurately check those types of attributes. Some previously passing tests will now fail until the check is correctly updated.
returnfmt.Errorf("%s: Attribute '%s' expected to be set", name, key)
826
+
val, ok:=is.Attributes[key]
827
+
828
+
ifok&&val!="" {
829
+
returnnil
828
830
}
829
831
830
-
returnnil
832
+
if_, ok:=is.Attributes[key+".#"]; ok {
833
+
returnfmt.Errorf(
834
+
"%s: list or set attribute '%s' must be checked by element count key (%s) or element value keys (e.g. %s). Set element value checks should use TestCheckTypeSet functions instead.",
835
+
name,
836
+
key,
837
+
key+".#",
838
+
key+".0",
839
+
)
840
+
}
841
+
842
+
if_, ok:=is.Attributes[key+".%"]; ok {
843
+
returnfmt.Errorf(
844
+
"%s: map attribute '%s' must be checked by element count key (%s) or element value keys (e.g. %s).",
845
+
name,
846
+
key,
847
+
key+".%",
848
+
key+".examplekey",
849
+
)
850
+
}
851
+
852
+
returnfmt.Errorf("%s: Attribute '%s' expected to be set", name, key)
831
853
}
832
854
833
855
// TestCheckResourceAttr ensures a specific value is stored in state for the
@@ -892,30 +914,48 @@ func TestCheckModuleResourceAttr(mp []string, name string, key string, value str
returnfmt.Errorf("%s: Attribute '%s' not found", name, key)
927
+
if_, ok:=is.Attributes[key+".#"]; ok {
928
+
returnfmt.Errorf(
929
+
"%s: list or set attribute '%s' must be checked by element count key (%s) or element value keys (e.g. %s). Set element value checks should use TestCheckTypeSet functions instead.",
930
+
name,
931
+
key,
932
+
key+".#",
933
+
key+".0",
934
+
)
935
+
}
936
+
937
+
if_, ok:=is.Attributes[key+".%"]; ok {
938
+
returnfmt.Errorf(
939
+
"%s: map attribute '%s' must be checked by element count key (%s) or element value keys (e.g. %s).",
940
+
name,
941
+
key,
942
+
key+".%",
943
+
key+".examplekey",
944
+
)
910
945
}
911
946
947
+
returnfmt.Errorf("%s: Attribute '%s' not found", name, key)
returnfmt.Errorf("%s: Attribute '%s' found when not expected", name, key)
994
1030
}
995
1031
1032
+
if_, ok:=is.Attributes[key+".#"]; ok {
1033
+
returnfmt.Errorf(
1034
+
"%s: list or set attribute '%s' must be checked by element count key (%s) or element value keys (e.g. %s). Set element value checks should use TestCheckTypeSet functions instead.",
1035
+
name,
1036
+
key,
1037
+
key+".#",
1038
+
key+".0",
1039
+
)
1040
+
}
1041
+
1042
+
if_, ok:=is.Attributes[key+".%"]; ok {
1043
+
returnfmt.Errorf(
1044
+
"%s: map attribute '%s' must be checked by element count key (%s) or element value keys (e.g. %s).",
0 commit comments