Skip to content

Commit

Permalink
Add tests for nil *Resource
Browse files Browse the repository at this point in the history
  • Loading branch information
Joshua MacDonald committed Sep 8, 2021
1 parent df2bdbb commit 45f7dc6
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
require.Equal(t, "", res.SchemaURL())
require.Equal(t, "", res.String())
require.Equal(t, []attribute.KeyValue(nil), res.Attributes())

it := res.Iter()
require.Equal(t, 0, it.Len())
require.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 45f7dc6

Please sign in to comment.