Skip to content

Commit

Permalink
Add tests for nil *Resource (#2227)
Browse files Browse the repository at this point in the history
* Add tests for nil *Resource

* Update sdk/resource/resource_test.go

Co-authored-by: Tyler Yahn <[email protected]>

Co-authored-by: Tyler Yahn <[email protected]>
  • Loading branch information
jmacd and MrAlias authored Sep 10, 2021
1 parent 9e7812d commit 360d130
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
3 changes: 3 additions & 0 deletions sdk/resource/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ func (r *Resource) Attributes() []attribute.KeyValue {
}

func (r *Resource) SchemaURL() string {
if r == nil {
return ""
}
return r.schemaURL
}

Expand Down
11 changes: 11 additions & 0 deletions sdk/resource/resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,17 @@ func TestMerge(t *testing.T) {
}
}

func TestEmpty(t *testing.T) {
var res *resource.Resource
assert.Equal(t, "", res.SchemaURL())
assert.Equal(t, "", res.String())
assert.Equal(t, []attribute.KeyValue(nil), res.Attributes())

it := res.Iter()
assert.Equal(t, 0, it.Len())
assert.True(t, res.Equal(res))
}

func TestDefault(t *testing.T) {
res := resource.Default()
require.False(t, res.Equal(resource.Empty()))
Expand Down

0 comments on commit 360d130

Please sign in to comment.