@@ -1299,3 +1299,83 @@ func TestUnmarshalCardinalityLimits(t *testing.T) {
12991299 })
13001300 }
13011301}
1302+
1303+ func TestUnmarshalSpanLimits (t * testing.T ) {
1304+ for _ , tt := range []struct {
1305+ name string
1306+ yamlConfig []byte
1307+ jsonConfig []byte
1308+ wantErr string
1309+ }{
1310+ {
1311+ name : "valid with all fields positive" ,
1312+ 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}` ),
1313+ 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" ),
1314+ },
1315+ {
1316+ name : "valid with single field" ,
1317+ jsonConfig : []byte (`{"attribute_value_length_limit":2000}` ),
1318+ yamlConfig : []byte ("attribute_value_length_limit: 2000" ),
1319+ },
1320+ {
1321+ name : "valid empty" ,
1322+ jsonConfig : []byte (`{}` ),
1323+ yamlConfig : []byte ("{}" ),
1324+ },
1325+ {
1326+ name : "invalid attribute_count_limit negative" ,
1327+ jsonConfig : []byte (`{"attribute_count_limit":-1}` ),
1328+ yamlConfig : []byte ("attribute_count_limit: -1" ),
1329+ wantErr : "field attribute_count_limit: must be >= 0" ,
1330+ },
1331+ {
1332+ name : "invalid attribute_value_length_limit negative" ,
1333+ jsonConfig : []byte (`{"attribute_value_length_limit":-1}` ),
1334+ yamlConfig : []byte ("attribute_value_length_limit: -1" ),
1335+ wantErr : "field attribute_value_length_limit: must be >= 0" ,
1336+ },
1337+ {
1338+ name : "invalid event_attribute_count_limit negative" ,
1339+ jsonConfig : []byte (`{"event_attribute_count_limit":-1}` ),
1340+ yamlConfig : []byte ("event_attribute_count_limit: -1" ),
1341+ wantErr : "field event_attribute_count_limit: must be >= 0" ,
1342+ },
1343+ {
1344+ name : "invalid event_count_limit negative" ,
1345+ jsonConfig : []byte (`{"event_count_limit":-1}` ),
1346+ yamlConfig : []byte ("event_count_limit: -1" ),
1347+ wantErr : "field event_count_limit: must be >= 0" ,
1348+ },
1349+ {
1350+ name : "invalid link_attribute_count_limit negative" ,
1351+ jsonConfig : []byte (`{"link_attribute_count_limit":-1}` ),
1352+ yamlConfig : []byte ("link_attribute_count_limit: -1" ),
1353+ wantErr : "field link_attribute_count_limit: must be >= 0" ,
1354+ },
1355+ {
1356+ name : "invalid link_count_limit negative" ,
1357+ jsonConfig : []byte (`{"link_count_limit":-1}` ),
1358+ yamlConfig : []byte ("link_count_limit: -1" ),
1359+ wantErr : "field link_count_limit: must be >= 0" ,
1360+ },
1361+ } {
1362+ t .Run (tt .name , func (t * testing.T ) {
1363+ cl := SpanLimits {}
1364+ err := cl .UnmarshalJSON (tt .jsonConfig )
1365+ if tt .wantErr != "" {
1366+ require .Error (t , err )
1367+ require .Contains (t , err .Error (), tt .wantErr )
1368+ } else {
1369+ require .NoError (t , err )
1370+ }
1371+ cl = SpanLimits {}
1372+ err = yaml .Unmarshal (tt .yamlConfig , & cl )
1373+ if tt .wantErr != "" {
1374+ require .Error (t , err )
1375+ require .Contains (t , err .Error (), tt .wantErr )
1376+ } else {
1377+ require .NoError (t , err )
1378+ }
1379+ })
1380+ }
1381+ }
0 commit comments