remove deprecation origin for now

we will add sth like this again when we will be able display a nicer diagnostic with the origin
This commit is contained in:
Daniel Schmidt 2025-12-12 14:26:30 +01:00
parent d813ad14f7
commit 93a38f893b
3 changed files with 31 additions and 44 deletions

View file

@ -4,7 +4,6 @@
package marks
import (
"github.com/hashicorp/hcl/v2"
"github.com/zclconf/go-cty/cty"
)
@ -94,9 +93,10 @@ const Ephemeral = valueMark("Ephemeral")
// `type` function.
const TypeType = valueMark("TypeType")
// DeprecationMark is a mark indicating that a value is deprecated. It is a struct
// rather than a primitive type so that it can carry a deprecation message.
type DeprecationMark struct {
Message string
Origin *hcl.Range
}
func (d DeprecationMark) GoString() string {
@ -104,11 +104,10 @@ func (d DeprecationMark) GoString() string {
}
// Empty deprecation mark for usage in marks.Has / Contains / etc
var Deprecation = NewDeprecation("", nil)
var Deprecation = NewDeprecation("")
func NewDeprecation(message string, origin *hcl.Range) DeprecationMark {
func NewDeprecation(message string) DeprecationMark {
return DeprecationMark{
Message: message,
Origin: origin,
}
}

View file

@ -6,45 +6,34 @@ package marks
import (
"testing"
"github.com/hashicorp/hcl/v2"
"github.com/zclconf/go-cty/cty"
)
func TestDeprecationMark(t *testing.T) {
deprecationWithoutRange := cty.StringVal("OldValue").Mark(NewDeprecation("This is outdated", nil))
deprecationWithRange := cty.StringVal("OldValue").Mark(NewDeprecation("This is outdated", &hcl.Range{Filename: "example.tf", Start: hcl.Pos{Line: 1, Column: 1}, End: hcl.Pos{Line: 1, Column: 10}}))
deprecation := cty.StringVal("OldValue").Mark(NewDeprecation("This is outdated"))
composite := cty.ObjectVal(map[string]cty.Value{
"foo": deprecationWithRange,
"bar": deprecationWithoutRange,
"foo": deprecation,
"bar": deprecation,
"baz": cty.StringVal("Not deprecated"),
})
if !deprecationWithRange.IsMarked() {
t.Errorf("Expected deprecationWithRange to be marked")
}
if !deprecationWithoutRange.IsMarked() {
t.Errorf("Expected deprecationWithoutRange to be marked")
if !deprecation.IsMarked() {
t.Errorf("Expected deprecation to be marked")
}
if composite.IsMarked() {
t.Errorf("Expected composite to be marked")
}
if !Has(deprecationWithRange, Deprecation) {
t.Errorf("Expected deprecationWithRange to be marked with Deprecation")
}
if !Has(deprecationWithoutRange, Deprecation) {
t.Errorf("Expected deprecationWithoutRange to be marked with Deprecation")
if !Has(deprecation, Deprecation) {
t.Errorf("Expected deprecation to be marked with Deprecation")
}
if Has(composite, Deprecation) {
t.Errorf("Expected composite to be marked with Deprecation")
}
if !Contains(deprecationWithRange, Deprecation) {
t.Errorf("Expected deprecationWithRange to be contain Deprecation Mark")
}
if !Contains(deprecationWithoutRange, Deprecation) {
t.Errorf("Expected deprecationWithoutRange to be contain Deprecation Mark")
if !Contains(deprecation, Deprecation) {
t.Errorf("Expected deprecation to be contain Deprecation Mark")
}
if !Contains(composite, Deprecation) {
t.Errorf("Expected composite to be contain Deprecation Mark")

View file

@ -8,7 +8,6 @@ import (
"testing"
"github.com/google/go-cmp/cmp"
"github.com/hashicorp/hcl/v2"
"github.com/zclconf/go-cty-debug/ctydebug"
"github.com/zclconf/go-cty/cty"
)
@ -33,15 +32,15 @@ func TestPathsWithMark(t *testing.T) {
},
{
Path: cty.GetAttrPath("deprecated"),
Marks: cty.NewValueMarks(NewDeprecation("this is deprecated", nil)),
Marks: cty.NewValueMarks(NewDeprecation("this is deprecated")),
},
{
Path: cty.GetAttrPath("multipleDeprecations"),
Marks: cty.NewValueMarks(NewDeprecation("this is deprecated", nil), NewDeprecation("this is also deprecated", nil)),
Marks: cty.NewValueMarks(NewDeprecation("this is deprecated"), NewDeprecation("this is also deprecated")),
},
{
Path: cty.GetAttrPath("multipleDeprecationsAndSensitive"),
Marks: cty.NewValueMarks(NewDeprecation("this is deprecated", nil), NewDeprecation("this is also deprecated", nil), "sensitive"),
Marks: cty.NewValueMarks(NewDeprecation("this is deprecated"), NewDeprecation("this is also deprecated"), "sensitive"),
},
}
@ -72,15 +71,15 @@ func TestPathsWithMark(t *testing.T) {
},
{
Path: cty.GetAttrPath("deprecated"),
Marks: cty.NewValueMarks(NewDeprecation("this is deprecated", nil)),
Marks: cty.NewValueMarks(NewDeprecation("this is deprecated")),
},
{
Path: cty.GetAttrPath("multipleDeprecations"),
Marks: cty.NewValueMarks(NewDeprecation("this is deprecated", nil), NewDeprecation("this is also deprecated", nil)),
Marks: cty.NewValueMarks(NewDeprecation("this is deprecated"), NewDeprecation("this is also deprecated")),
},
{
Path: cty.GetAttrPath("multipleDeprecationsAndSensitive"),
Marks: cty.NewValueMarks(NewDeprecation("this is deprecated", nil), NewDeprecation("this is also deprecated", nil), "sensitive"),
Marks: cty.NewValueMarks(NewDeprecation("this is deprecated"), NewDeprecation("this is also deprecated"), "sensitive"),
},
}
@ -117,7 +116,7 @@ func TestPathsWithMark(t *testing.T) {
},
{
Path: cty.GetAttrPath("multipleDeprecationsAndSensitive"),
Marks: cty.NewValueMarks(NewDeprecation("this is deprecated", nil), NewDeprecation("this is also deprecated", nil), "sensitive"),
Marks: cty.NewValueMarks(NewDeprecation("this is deprecated"), NewDeprecation("this is also deprecated"), "sensitive"),
},
}
@ -167,15 +166,15 @@ func TestRemoveAll_dataMarks(t *testing.T) {
input := []cty.PathValueMarks{
{
Path: cty.GetAttrPath("deprecated"),
Marks: cty.NewValueMarks(NewDeprecation("this is deprecated", nil)),
Marks: cty.NewValueMarks(NewDeprecation("this is deprecated")),
},
{
Path: cty.GetAttrPath("multipleDeprecations"),
Marks: cty.NewValueMarks(NewDeprecation("this is deprecated", nil), NewDeprecation("this is also deprecated", nil)),
Marks: cty.NewValueMarks(NewDeprecation("this is deprecated"), NewDeprecation("this is also deprecated")),
},
{
Path: cty.GetAttrPath("multipleDeprecationsAndSensitive"),
Marks: cty.NewValueMarks(NewDeprecation("this is deprecated", nil), NewDeprecation("this is also deprecated", nil), "sensitive"),
Marks: cty.NewValueMarks(NewDeprecation("this is deprecated"), NewDeprecation("this is also deprecated"), "sensitive"),
},
}
@ -251,7 +250,7 @@ func TestMarkPaths(t *testing.T) {
cty.GetAttrPath("o").GetAttr("b"),
cty.GetAttrPath("t").IndexInt(0),
}
deprecationMark := NewDeprecation("this is deprecated", nil)
deprecationMark := NewDeprecation("this is deprecated")
got = MarkPaths(value, deprecationMark, deprecatedPaths)
want = cty.ObjectVal(map[string]cty.Value{
"s": cty.StringVal(".s").Mark(deprecationMark),
@ -366,30 +365,30 @@ func TestMarksEqual(t *testing.T) {
},
{
[]cty.PathValueMarks{
{Path: cty.Path{cty.GetAttrStep{Name: "a"}}, Marks: cty.NewValueMarks(NewDeprecation("same message", nil))},
{Path: cty.Path{cty.GetAttrStep{Name: "a"}}, Marks: cty.NewValueMarks(NewDeprecation("same message"))},
},
[]cty.PathValueMarks{
{Path: cty.Path{cty.GetAttrStep{Name: "a"}}, Marks: cty.NewValueMarks(NewDeprecation("same message", nil))},
{Path: cty.Path{cty.GetAttrStep{Name: "a"}}, Marks: cty.NewValueMarks(NewDeprecation("same message"))},
},
true,
},
{
[]cty.PathValueMarks{
{Path: cty.Path{cty.GetAttrStep{Name: "a"}}, Marks: cty.NewValueMarks(NewDeprecation("different", nil))},
{Path: cty.Path{cty.GetAttrStep{Name: "a"}}, Marks: cty.NewValueMarks(NewDeprecation("different"))},
},
[]cty.PathValueMarks{
{Path: cty.Path{cty.GetAttrStep{Name: "a"}}, Marks: cty.NewValueMarks(NewDeprecation("message", nil))},
{Path: cty.Path{cty.GetAttrStep{Name: "a"}}, Marks: cty.NewValueMarks(NewDeprecation("message"))},
},
false,
},
{
[]cty.PathValueMarks{
{Path: cty.Path{cty.GetAttrStep{Name: "a"}}, Marks: cty.NewValueMarks(NewDeprecation("same message", &hcl.Range{Filename: "test.tf", Start: hcl.Pos{Line: 1, Column: 1}, End: hcl.Pos{Line: 1, Column: 1}}))},
{Path: cty.Path{cty.GetAttrStep{Name: "a"}}, Marks: cty.NewValueMarks(NewDeprecation("same message"))},
},
[]cty.PathValueMarks{
{Path: cty.Path{cty.GetAttrStep{Name: "a"}}, Marks: cty.NewValueMarks(NewDeprecation("same message", &hcl.Range{Filename: "otherFile.tf", Start: hcl.Pos{Line: 1, Column: 1}, End: hcl.Pos{Line: 1, Column: 1}}))},
{Path: cty.Path{cty.GetAttrStep{Name: "a"}}, Marks: cty.NewValueMarks(NewDeprecation("same message"))},
},
false, // TODO: Should this really be different?
true,
},
} {
t.Run(fmt.Sprint(i), func(t *testing.T) {