@@ -907,13 +907,15 @@ func TestParseYAML(t *testing.T) {
907907 input : "v1.0.0_invalid_nil_name.yaml" ,
908908 wantErr : errors .New (`unmarshal error in *otelconf.BatchSpanProcessor
909909unmarshal error in *otelconf.SpanExporter
910+ unmarshal error in *otelconf.OTLPHttpExporter
910911cannot unmarshal field name in NameStringValuePair required` ),
911912 },
912913 {
913914 name : "invalid nil value" ,
914915 input : "v1.0.0_invalid_nil_value.yaml" ,
915916 wantErr : errors .New (`unmarshal error in *otelconf.BatchLogRecordProcessor
916917unmarshal error in *otelconf.LogRecordExporter
918+ unmarshal error in *otelconf.OTLPHttpExporter
917919cannot unmarshal field value in NameStringValuePair required` ),
918920 },
919921 {
@@ -1467,94 +1469,6 @@ func TestCreateHeadersConfig(t *testing.T) {
14671469 }
14681470}
14691471
1470- func TestCreateHeadersConfig (t * testing.T ) {
1471- tests := []struct {
1472- name string
1473- headers []NameStringValuePair
1474- headersList * string
1475- wantHeaders map [string ]string
1476- wantErr error
1477- }{
1478- {
1479- name : "no headers" ,
1480- headers : []NameStringValuePair {},
1481- headersList : nil ,
1482- wantHeaders : map [string ]string {},
1483- },
1484- {
1485- name : "headerslist only" ,
1486- headers : []NameStringValuePair {},
1487- headersList : ptr ("a=b,c=d" ),
1488- wantHeaders : map [string ]string {
1489- "a" : "b" ,
1490- "c" : "d" ,
1491- },
1492- },
1493- {
1494- name : "headers only" ,
1495- headers : []NameStringValuePair {
1496- {
1497- Name : "a" ,
1498- Value : ptr ("b" ),
1499- },
1500- {
1501- Name : "c" ,
1502- Value : ptr ("d" ),
1503- },
1504- },
1505- headersList : nil ,
1506- wantHeaders : map [string ]string {
1507- "a" : "b" ,
1508- "c" : "d" ,
1509- },
1510- },
1511- {
1512- name : "both headers and headerslist" ,
1513- headers : []NameStringValuePair {
1514- {
1515- Name : "a" ,
1516- Value : ptr ("b" ),
1517- },
1518- },
1519- headersList : ptr ("c=d" ),
1520- wantHeaders : map [string ]string {
1521- "a" : "b" ,
1522- "c" : "d" ,
1523- },
1524- },
1525- {
1526- name : "headers supersedes headerslist" ,
1527- headers : []NameStringValuePair {
1528- {
1529- Name : "a" ,
1530- Value : ptr ("b" ),
1531- },
1532- {
1533- Name : "c" ,
1534- Value : ptr ("override" ),
1535- },
1536- },
1537- headersList : ptr ("c=d" ),
1538- wantHeaders : map [string ]string {
1539- "a" : "b" ,
1540- "c" : "override" ,
1541- },
1542- },
1543- {
1544- name : "invalid headerslist" ,
1545- headersList : ptr ("===" ),
1546- wantErr : newErrInvalid ("invalid headers_list" ),
1547- },
1548- }
1549- for _ , tt := range tests {
1550- t .Run (tt .name , func (t * testing.T ) {
1551- headersMap , err := createHeadersConfig (tt .headers , tt .headersList )
1552- require .ErrorIs (t , err , tt .wantErr )
1553- require .Equal (t , tt .wantHeaders , headersMap )
1554- })
1555- }
1556- }
1557-
15581472func TestUnmarshalSpanLimits (t * testing.T ) {
15591473 for _ , tt := range []struct {
15601474 name string
@@ -1843,223 +1757,3 @@ func TestUnmarshalOTLPGrpcMetricExporter(t *testing.T) {
18431757 })
18441758 }
18451759}
1846-
1847- func TestUnmarshalCardinalityLimits (t * testing.T ) {
1848- for _ , tt := range []struct {
1849- name string
1850- yamlConfig []byte
1851- jsonConfig []byte
1852- wantErr string
1853- }{
1854- {
1855- name : "valid with all fields positive" ,
1856- jsonConfig : []byte (`{"counter":100,"default":200,"gauge":300,"histogram":400,"observable_counter":500,"observable_gauge":600,"observable_up_down_counter":700,"up_down_counter":800}` ),
1857- yamlConfig : []byte ("counter: 100\n default: 200\n gauge: 300\n histogram: 400\n observable_counter: 500\n observable_gauge: 600\n observable_up_down_counter: 700\n up_down_counter: 800" ),
1858- },
1859- {
1860- name : "valid with single field" ,
1861- jsonConfig : []byte (`{"default":2000}` ),
1862- yamlConfig : []byte ("default: 2000" ),
1863- },
1864- {
1865- name : "valid empty" ,
1866- jsonConfig : []byte (`{}` ),
1867- yamlConfig : []byte ("{}" ),
1868- },
1869- {
1870- name : "invalid counter zero" ,
1871- jsonConfig : []byte (`{"counter":0}` ),
1872- yamlConfig : []byte ("counter: 0" ),
1873- wantErr : "field counter: must be > 0" ,
1874- },
1875- {
1876- name : "invalid counter negative" ,
1877- jsonConfig : []byte (`{"counter":-1}` ),
1878- yamlConfig : []byte ("counter: -1" ),
1879- wantErr : "field counter: must be > 0" ,
1880- },
1881- {
1882- name : "invalid default zero" ,
1883- jsonConfig : []byte (`{"default":0}` ),
1884- yamlConfig : []byte ("default: 0" ),
1885- wantErr : "field default: must be > 0" ,
1886- },
1887- {
1888- name : "invalid default negative" ,
1889- jsonConfig : []byte (`{"default":-1}` ),
1890- yamlConfig : []byte ("default: -1" ),
1891- wantErr : "field default: must be > 0" ,
1892- },
1893- {
1894- name : "invalid gauge zero" ,
1895- jsonConfig : []byte (`{"gauge":0}` ),
1896- yamlConfig : []byte ("gauge: 0" ),
1897- wantErr : "field gauge: must be > 0" ,
1898- },
1899- {
1900- name : "invalid gauge negative" ,
1901- jsonConfig : []byte (`{"gauge":-1}` ),
1902- yamlConfig : []byte ("gauge: -1" ),
1903- wantErr : "field gauge: must be > 0" ,
1904- },
1905- {
1906- name : "invalid histogram zero" ,
1907- jsonConfig : []byte (`{"histogram":0}` ),
1908- yamlConfig : []byte ("histogram: 0" ),
1909- wantErr : "field histogram: must be > 0" ,
1910- },
1911- {
1912- name : "invalid histogram negative" ,
1913- jsonConfig : []byte (`{"histogram":-1}` ),
1914- yamlConfig : []byte ("histogram: -1" ),
1915- wantErr : "field histogram: must be > 0" ,
1916- },
1917- {
1918- name : "invalid observable_counter zero" ,
1919- jsonConfig : []byte (`{"observable_counter":0}` ),
1920- yamlConfig : []byte ("observable_counter: 0" ),
1921- wantErr : "field observable_counter: must be > 0" ,
1922- },
1923- {
1924- name : "invalid observable_counter negative" ,
1925- jsonConfig : []byte (`{"observable_counter":-1}` ),
1926- yamlConfig : []byte ("observable_counter: -1" ),
1927- wantErr : "field observable_counter: must be > 0" ,
1928- },
1929- {
1930- name : "invalid observable_gauge zero" ,
1931- jsonConfig : []byte (`{"observable_gauge":0}` ),
1932- yamlConfig : []byte ("observable_gauge: 0" ),
1933- wantErr : "field observable_gauge: must be > 0" ,
1934- },
1935- {
1936- name : "invalid observable_gauge negative" ,
1937- jsonConfig : []byte (`{"observable_gauge":-1}` ),
1938- yamlConfig : []byte ("observable_gauge: -1" ),
1939- wantErr : "field observable_gauge: must be > 0" ,
1940- },
1941- {
1942- name : "invalid observable_up_down_counter zero" ,
1943- jsonConfig : []byte (`{"observable_up_down_counter":0}` ),
1944- yamlConfig : []byte ("observable_up_down_counter: 0" ),
1945- wantErr : "field observable_up_down_counter: must be > 0" ,
1946- },
1947- {
1948- name : "invalid observable_up_down_counter negative" ,
1949- jsonConfig : []byte (`{"observable_up_down_counter":-1}` ),
1950- yamlConfig : []byte ("observable_up_down_counter: -1" ),
1951- wantErr : "field observable_up_down_counter: must be > 0" ,
1952- },
1953- {
1954- name : "invalid up_down_counter zero" ,
1955- jsonConfig : []byte (`{"up_down_counter":0}` ),
1956- yamlConfig : []byte ("up_down_counter: 0" ),
1957- wantErr : "field up_down_counter: must be > 0" ,
1958- },
1959- {
1960- name : "invalid up_down_counter negative" ,
1961- jsonConfig : []byte (`{"up_down_counter":-1}` ),
1962- yamlConfig : []byte ("up_down_counter: -1" ),
1963- wantErr : "field up_down_counter: must be > 0" ,
1964- },
1965- } {
1966- t .Run (tt .name , func (t * testing.T ) {
1967- cl := CardinalityLimits {}
1968- err := cl .UnmarshalJSON (tt .jsonConfig )
1969- if tt .wantErr != "" {
1970- require .Error (t , err )
1971- require .Contains (t , err .Error (), tt .wantErr )
1972- } else {
1973- require .NoError (t , err )
1974- }
1975- cl = CardinalityLimits {}
1976- err = yaml .Unmarshal (tt .yamlConfig , & cl )
1977- if tt .wantErr != "" {
1978- require .Error (t , err )
1979- require .Contains (t , err .Error (), tt .wantErr )
1980- } else {
1981- require .NoError (t , err )
1982- }
1983- })
1984- }
1985- }
1986-
1987- func TestUnmarshalSpanLimits (t * testing.T ) {
1988- for _ , tt := range []struct {
1989- name string
1990- yamlConfig []byte
1991- jsonConfig []byte
1992- wantErr string
1993- }{
1994- {
1995- name : "valid with all fields positive" ,
1996- jsonConfig : []byte (`{"attribute_count_limit":100,"attribute_value_length_limit":200,"event_attribute_count_limit":300,"event_count_limit":400,"link_attribute_count_limit":500,"link_count_limit":600}` ),
1997- yamlConfig : []byte ("attribute_count_limit: 100\n attribute_value_length_limit: 200\n event_attribute_count_limit: 300\n event_count_limit: 400\n link_attribute_count_limit: 500\n link_count_limit: 600" ),
1998- },
1999- {
2000- name : "valid with single field" ,
2001- jsonConfig : []byte (`{"attribute_value_length_limit":2000}` ),
2002- yamlConfig : []byte ("attribute_value_length_limit: 2000" ),
2003- },
2004- {
2005- name : "valid empty" ,
2006- jsonConfig : []byte (`{}` ),
2007- yamlConfig : []byte ("{}" ),
2008- },
2009- {
2010- name : "invalid attribute_count_limit negative" ,
2011- jsonConfig : []byte (`{"attribute_count_limit":-1}` ),
2012- yamlConfig : []byte ("attribute_count_limit: -1" ),
2013- wantErr : "field attribute_count_limit: must be >= 0" ,
2014- },
2015- {
2016- name : "invalid attribute_value_length_limit negative" ,
2017- jsonConfig : []byte (`{"attribute_value_length_limit":-1}` ),
2018- yamlConfig : []byte ("attribute_value_length_limit: -1" ),
2019- wantErr : "field attribute_value_length_limit: must be >= 0" ,
2020- },
2021- {
2022- name : "invalid event_attribute_count_limit negative" ,
2023- jsonConfig : []byte (`{"event_attribute_count_limit":-1}` ),
2024- yamlConfig : []byte ("event_attribute_count_limit: -1" ),
2025- wantErr : "field event_attribute_count_limit: must be >= 0" ,
2026- },
2027- {
2028- name : "invalid event_count_limit negative" ,
2029- jsonConfig : []byte (`{"event_count_limit":-1}` ),
2030- yamlConfig : []byte ("event_count_limit: -1" ),
2031- wantErr : "field event_count_limit: must be >= 0" ,
2032- },
2033- {
2034- name : "invalid link_attribute_count_limit negative" ,
2035- jsonConfig : []byte (`{"link_attribute_count_limit":-1}` ),
2036- yamlConfig : []byte ("link_attribute_count_limit: -1" ),
2037- wantErr : "field link_attribute_count_limit: must be >= 0" ,
2038- },
2039- {
2040- name : "invalid link_count_limit negative" ,
2041- jsonConfig : []byte (`{"link_count_limit":-1}` ),
2042- yamlConfig : []byte ("link_count_limit: -1" ),
2043- wantErr : "field link_count_limit: must be >= 0" ,
2044- },
2045- } {
2046- t .Run (tt .name , func (t * testing.T ) {
2047- cl := SpanLimits {}
2048- err := cl .UnmarshalJSON (tt .jsonConfig )
2049- if tt .wantErr != "" {
2050- require .Error (t , err )
2051- require .Contains (t , err .Error (), tt .wantErr )
2052- } else {
2053- require .NoError (t , err )
2054- }
2055- cl = SpanLimits {}
2056- err = yaml .Unmarshal (tt .yamlConfig , & cl )
2057- if tt .wantErr != "" {
2058- require .Error (t , err )
2059- require .Contains (t , err .Error (), tt .wantErr )
2060- } else {
2061- require .NoError (t , err )
2062- }
2063- })
2064- }
2065- }
0 commit comments