Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[baggage] Remove unused private field #4318

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 2 additions & 12 deletions baggage/baggage.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
}

Expand All @@ -95,7 +90,6 @@ func NewKeyValueProperty(key, value string) (Property, error) {
key: key,
value: value,
hasValue: true,
hasData: true,
}
return p, nil
}
Expand All @@ -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 {
Expand All @@ -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))
}
Expand Down
31 changes: 14 additions & 17 deletions baggage/baggage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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)
pellared marked this conversation as resolved.
Show resolved Hide resolved

p.hasData = true
assert.ErrorIs(t, p.validate(), errInvalidKey)

p.key = "k"
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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])
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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())
}

Expand Down