@@ -17,28 +17,7 @@ import (
1717type mockType struct {}
1818
1919func TestNewResource (t * testing.T ) {
20- res := resource .NewWithAttributes (semconv .SchemaURL ,
21- semconv .ServiceName ("service-a" ),
22- )
2320 other := mockType {}
24- resWithAttrs := resource .NewWithAttributes (semconv .SchemaURL ,
25- semconv .ServiceName ("service-a" ),
26- attribute .Bool ("attr-bool" , true ),
27- attribute .String ("attr-uint64" , fmt .Sprintf ("%d" , 164 )),
28- attribute .Int64 ("attr-int64" , int64 (- 164 )),
29- attribute .Float64 ("attr-float64" , float64 (64.0 )),
30- attribute .Int64 ("attr-int8" , int64 (- 18 )),
31- attribute .Int64 ("attr-uint8" , int64 (18 )),
32- attribute .Int64 ("attr-int16" , int64 (- 116 )),
33- attribute .Int64 ("attr-uint16" , int64 (116 )),
34- attribute .Int64 ("attr-int32" , int64 (- 132 )),
35- attribute .Int64 ("attr-uint32" , int64 (132 )),
36- attribute .Float64 ("attr-float32" , float64 (32.0 )),
37- attribute .Int64 ("attr-int" , int64 (- 1 )),
38- attribute .String ("attr-uint" , fmt .Sprintf ("%d" , 1 )),
39- attribute .String ("attr-string" , "string-val" ),
40- attribute .String ("attr-default" , fmt .Sprintf ("%v" , other )),
41- )
4221 tests := []struct {
4322 name string
4423 config * Resource
@@ -53,6 +32,24 @@ func TestNewResource(t *testing.T) {
5332 config : & Resource {},
5433 wantResource : resource .Default (),
5534 },
35+ {
36+ name : "resource-with-schema" ,
37+ config : & Resource {
38+ SchemaUrl : ptr (semconv .SchemaURL ),
39+ },
40+ wantResource : resource .NewWithAttributes (semconv .SchemaURL ),
41+ },
42+ {
43+ name : "resource-with-attributes" ,
44+ config : & Resource {
45+ Attributes : []AttributeNameValue {
46+ {Name : "service.name" , Value : "service-a" },
47+ },
48+ },
49+ wantResource : resource .NewWithAttributes ("" ,
50+ semconv .ServiceName ("service-a" ),
51+ ),
52+ },
5653 {
5754 name : "resource-with-attributes-and-schema" ,
5855 config : & Resource {
@@ -61,7 +58,9 @@ func TestNewResource(t *testing.T) {
6158 },
6259 SchemaUrl : ptr (semconv .SchemaURL ),
6360 },
64- wantResource : res ,
61+ wantResource : resource .NewWithAttributes (semconv .SchemaURL ,
62+ semconv .ServiceName ("service-a" ),
63+ ),
6564 },
6665 {
6766 name : "resource-with-additional-attributes-and-schema" ,
@@ -86,7 +85,23 @@ func TestNewResource(t *testing.T) {
8685 },
8786 SchemaUrl : ptr (semconv .SchemaURL ),
8887 },
89- wantResource : resWithAttrs ,
88+ wantResource : resource .NewWithAttributes (semconv .SchemaURL ,
89+ semconv .ServiceName ("service-a" ),
90+ attribute .Bool ("attr-bool" , true ),
91+ attribute .String ("attr-uint64" , fmt .Sprintf ("%d" , 164 )),
92+ attribute .Int64 ("attr-int64" , int64 (- 164 )),
93+ attribute .Float64 ("attr-float64" , float64 (64.0 )),
94+ attribute .Int64 ("attr-int8" , int64 (- 18 )),
95+ attribute .Int64 ("attr-uint8" , int64 (18 )),
96+ attribute .Int64 ("attr-int16" , int64 (- 116 )),
97+ attribute .Int64 ("attr-uint16" , int64 (116 )),
98+ attribute .Int64 ("attr-int32" , int64 (- 132 )),
99+ attribute .Int64 ("attr-uint32" , int64 (132 )),
100+ attribute .Float64 ("attr-float32" , float64 (32.0 )),
101+ attribute .Int64 ("attr-int" , int64 (- 1 )),
102+ attribute .String ("attr-uint" , fmt .Sprintf ("%d" , 1 )),
103+ attribute .String ("attr-string" , "string-val" ),
104+ attribute .String ("attr-default" , fmt .Sprintf ("%v" , other ))),
90105 },
91106 }
92107 for _ , tt := range tests {
0 commit comments