From 14b3a985f545b507d12981fed4f951f0dbc452c9 Mon Sep 17 00:00:00 2001 From: Yuri Shkuro Date: Tue, 15 Aug 2023 10:48:44 -0400 Subject: [PATCH] [baggage] Remove unused private field (#4318) Signed-off-by: Yuri Shkuro --- baggage/baggage.go | 14 ++------------ baggage/baggage_test.go | 31 ++++++++++++++----------------- 2 files changed, 16 insertions(+), 29 deletions(-) diff --git a/baggage/baggage.go b/baggage/baggage.go index 46e523a80..9e6b3b7b5 100644 --- a/baggage/baggage.go +++ b/baggage/baggage.go @@ -61,11 +61,6 @@ type Property struct { // hasValue indicates if a zero-value value means the property does not // have a value or if it was the zero-value. hasValue bool - - // hasData indicates whether the created property contains data or not. - // Properties that do not contain data are invalid with no other check - // required. - hasData bool } // NewKeyProperty returns a new Property for key. @@ -76,7 +71,7 @@ func NewKeyProperty(key string) (Property, error) { return newInvalidProperty(), fmt.Errorf("%w: %q", errInvalidKey, key) } - p := Property{key: key, hasData: true} + p := Property{key: key} return p, nil } @@ -95,7 +90,6 @@ func NewKeyValueProperty(key, value string) (Property, error) { key: key, value: value, hasValue: true, - hasData: true, } return p, nil } @@ -117,7 +111,7 @@ func parseProperty(property string) (Property, error) { return newInvalidProperty(), fmt.Errorf("%w: %q", errInvalidProperty, property) } - p := Property{hasData: true} + var p Property if match[1] != "" { p.key = match[1] } else { @@ -136,10 +130,6 @@ func (p Property) validate() error { return fmt.Errorf("invalid property: %w", err) } - if !p.hasData { - return errFunc(fmt.Errorf("%w: %q", errInvalidProperty, p)) - } - if !keyRe.MatchString(p.key) { return errFunc(fmt.Errorf("%w: %q", errInvalidKey, p.key)) } diff --git a/baggage/baggage_test.go b/baggage/baggage_test.go index 46cf7b90a..2b98beace 100644 --- a/baggage/baggage_test.go +++ b/baggage/baggage_test.go @@ -138,7 +138,7 @@ func TestNewKeyProperty(t *testing.T) { p, err = NewKeyProperty("key") assert.NoError(t, err) - assert.Equal(t, Property{key: "key", hasData: true}, p) + assert.Equal(t, Property{key: "key"}, p) } func TestNewKeyValueProperty(t *testing.T) { @@ -152,14 +152,11 @@ func TestNewKeyValueProperty(t *testing.T) { p, err = NewKeyValueProperty("key", "value") assert.NoError(t, err) - assert.Equal(t, Property{key: "key", value: "value", hasValue: true, hasData: true}, p) + assert.Equal(t, Property{key: "key", value: "value", hasValue: true}, p) } func TestPropertyValidate(t *testing.T) { p := Property{} - assert.ErrorIs(t, p.validate(), errInvalidProperty) - - p.hasData = true assert.ErrorIs(t, p.validate(), errInvalidKey) p.key = "k" @@ -562,7 +559,7 @@ func TestBaggageSetMember(t *testing.T) { assert.Equal(t, 1, len(b1.list)) assert.Equal(t, 1, len(b2.list)) - p := properties{{key: "p", hasData: true}} + p := properties{{key: "p"}} m.properties = p b3, err := b2.SetMember(m) assert.NoError(t, err) @@ -573,10 +570,10 @@ func TestBaggageSetMember(t *testing.T) { // The returned baggage needs to be immutable and should use a copy of the // properties slice. - p[0] = Property{key: "different", hasData: true} + p[0] = Property{key: "different"} assert.Equal(t, baggage.Item{Value: "v", Properties: []baggage.Property{{Key: "p"}}}, b3.list[key]) // Reset for below. - p[0] = Property{key: "p", hasData: true} + p[0] = Property{key: "p"} m = Member{key: "another", hasData: true} b4, err := b3.SetMember(m) @@ -630,7 +627,7 @@ func TestBaggageSetFalseMembers(t *testing.T) { assert.Equal(t, 1, len(b1.list)) assert.Equal(t, 1, len(b2.list)) - p := properties{{key: "p", hasData: false}} + p := properties{{key: "p"}} m.properties = p b3, err := b2.SetMember(m) assert.NoError(t, err) @@ -641,12 +638,12 @@ func TestBaggageSetFalseMembers(t *testing.T) { // The returned baggage needs to be immutable and should use a copy of the // properties slice. - p[0] = Property{key: "different", hasData: false} + p[0] = Property{key: "different"} assert.Equal(t, baggage.Item{Value: "v", Properties: []baggage.Property{{Key: "p"}}}, b3.list[key]) // Reset for below. - p[0] = Property{key: "p", hasData: false} + p[0] = Property{key: "p"} - m = Member{key: "another", hasData: false} + m = Member{key: "another"} b4, err := b3.SetMember(m) assert.Error(t, err) assert.Equal(t, baggage.Item{Value: "v", Properties: []baggage.Property{{Key: "p"}}}, b3.list[key]) @@ -757,13 +754,13 @@ func TestNewMember(t *testing.T) { assert.Equal(t, Member{hasData: false}, m) key, val := "k", "v" - p := Property{key: "foo", hasData: true} + p := Property{key: "foo"} m, err = NewMember(key, val, p) assert.NoError(t, err) expected := Member{ key: key, value: val, - properties: properties{{key: "foo", hasData: true}}, + properties: properties{{key: "foo"}}, hasData: true, } assert.Equal(t, expected, m) @@ -779,7 +776,7 @@ func TestNewMember(t *testing.T) { expected = Member{ key: key, value: ";", - properties: properties{{key: "foo", hasData: true}}, + properties: properties{{key: "foo"}}, hasData: true, } assert.NoError(t, err) @@ -791,13 +788,13 @@ func TestNewMember(t *testing.T) { } func TestPropertiesValidate(t *testing.T) { - p := properties{{hasData: true}} + p := properties{{}} assert.ErrorIs(t, p.validate(), errInvalidKey) p[0].key = "foo" assert.NoError(t, p.validate()) - p = append(p, Property{key: "bar", hasData: true}) + p = append(p, Property{key: "bar"}) assert.NoError(t, p.validate()) }