@@ -1847,3 +1847,87 @@ func TestParseConfigComplete(t *testing.T) {
18471847 })
18481848 }
18491849}
1850+
1851+ func TestParseConfig_LogDrops (t * testing.T ) {
1852+ testCases := []struct {
1853+ name string
1854+ stdin []byte
1855+ args string
1856+ expectError bool
1857+ expectDryRun bool
1858+ expectLogDrops bool
1859+ }{
1860+ {
1861+ name : "Config with dryRun and logDrops enabled" ,
1862+ stdin : []byte (`{
1863+ "cniVersion": "1.0.0",
1864+ "name": "test-net",
1865+ "type": "outbound",
1866+ "dryRun": true,
1867+ "logDrops": true,
1868+ "mainChainName": "TEST-OUTBOUND",
1869+ "defaultAction": "DROP"
1870+ }` ),
1871+ args : "" ,
1872+ expectDryRun : true ,
1873+ expectLogDrops : true ,
1874+ },
1875+ {
1876+ name : "Config with only logDrops enabled" ,
1877+ stdin : []byte (`{
1878+ "cniVersion": "1.0.0",
1879+ "name": "test-net",
1880+ "type": "outbound",
1881+ "logDrops": true,
1882+ "mainChainName": "TEST-OUTBOUND",
1883+ "defaultAction": "DROP"
1884+ }` ),
1885+ args : "" ,
1886+ expectDryRun : false ,
1887+ expectLogDrops : true ,
1888+ },
1889+ {
1890+ name : "Config with only dryRun enabled" ,
1891+ stdin : []byte (`{
1892+ "cniVersion": "1.0.0",
1893+ "name": "test-net",
1894+ "type": "outbound",
1895+ "dryRun": true,
1896+ "mainChainName": "TEST-OUTBOUND",
1897+ "defaultAction": "DROP"
1898+ }` ),
1899+ args : "" ,
1900+ expectDryRun : true ,
1901+ expectLogDrops : false ,
1902+ },
1903+ {
1904+ name : "Config with both disabled" ,
1905+ stdin : []byte (`{
1906+ "cniVersion": "1.0.0",
1907+ "name": "test-net",
1908+ "type": "outbound",
1909+ "mainChainName": "TEST-OUTBOUND",
1910+ "defaultAction": "DROP"
1911+ }` ),
1912+ args : "" ,
1913+ expectDryRun : false ,
1914+ expectLogDrops : false ,
1915+ },
1916+ }
1917+
1918+ for _ , tc := range testCases {
1919+ t .Run (tc .name , func (t * testing.T ) {
1920+ conf , err := parseConfig (tc .stdin , tc .args , "test-container" )
1921+
1922+ if tc .expectError {
1923+ assert .Error (t , err )
1924+ return
1925+ }
1926+
1927+ assert .NoError (t , err )
1928+ assert .NotNil (t , conf )
1929+ assert .Equal (t , tc .expectDryRun , conf .DryRun )
1930+ assert .Equal (t , tc .expectLogDrops , conf .LogDrops )
1931+ })
1932+ }
1933+ }
0 commit comments