@@ -507,7 +507,7 @@ func TestNginxConfigParser_Parse(t *testing.T) {
507507 allowedDirectories : []string {dir },
508508 },
509509 {
510- name : "Test 10: Check with multiple syslog servers " ,
510+ name : "Test 10: Available NAP syslog server " ,
511511 instance : protos .NginxPlusInstance ([]string {}),
512512 content : testconfig .NginxConfigWithMultipleSysLogs (errorLog .Name (), accessLog .Name (),
513513 "192.168.12.34:1517" , "my.domain.com:1517" , "127.0.0.1:1515" ),
@@ -521,7 +521,7 @@ func TestNginxConfigParser_Parse(t *testing.T) {
521521 expectedLog : "Found valid NAP syslog server" ,
522522 },
523523 {
524- name : "Test 10: Check with multiple syslog servers " ,
524+ name : "Test 11: Unavailable NAP syslog server " ,
525525 instance : protos .NginxPlusInstance ([]string {}),
526526 content : testconfig .NginxConfigWithMultipleSysLogs (errorLog .Name (), accessLog .Name (),
527527 "192.168.12.34:1517" , "my.domain.com:1517" , "not.allowed:1515" ),
@@ -1521,6 +1521,62 @@ func TestNginxConfigParser_checkDuplicate(t *testing.T) {
15211521 }
15221522}
15231523
1524+ func TestNginxConfigParser_parseIncludeDirective (t * testing.T ) {
1525+ parser := NewNginxConfigParser (types .AgentConfig ())
1526+
1527+ tests := []struct {
1528+ name string
1529+ confFile string
1530+ expected string
1531+ args []string
1532+ }{
1533+ {
1534+ name : "Test 1: relative path" ,
1535+ args : []string {"test.conf" },
1536+ confFile : "/etc/nginx/nginx.conf" ,
1537+ expected : "/etc/nginx/test.conf" ,
1538+ },
1539+ {
1540+ name : "Test 2: absolute path" ,
1541+ args : []string {"/usr/local/nginx/conf/vhost.conf" },
1542+ confFile : "/etc/nginx/nginx.conf" ,
1543+ expected : "/usr/local/nginx/conf/vhost.conf" ,
1544+ },
1545+ {
1546+ name : "Test 3: wildcard" ,
1547+ args : []string {"/etc/nginx/conf.d/*.conf" },
1548+ confFile : "/etc/nginx/nginx.conf" ,
1549+ expected : "/etc/nginx/conf.d/*.conf" ,
1550+ },
1551+ {
1552+ name : "Test 4: relative path with subdirectory" ,
1553+ args : []string {"conf.d/default.conf" },
1554+ confFile : "/etc/nginx/nginx.conf" ,
1555+ expected : "/etc/nginx/conf.d/default.conf" ,
1556+ },
1557+ {
1558+ name : "Test 5: parent directory reference" ,
1559+ args : []string {"../sites-enabled/*.conf" },
1560+ confFile : "/etc/nginx/conf.d/nginx.conf" ,
1561+ expected : "/etc/nginx/sites-enabled/*.conf" ,
1562+ },
1563+ }
1564+
1565+ for _ , tc := range tests {
1566+ t .Run (tc .name , func (t * testing.T ) {
1567+ include := parser .parseIncludeDirective (
1568+ & crossplane.Directive {
1569+ Args : tc .args ,
1570+ },
1571+ & crossplane.Config {
1572+ File : tc .confFile ,
1573+ },
1574+ )
1575+ assert .Equal (t , tc .expected , include )
1576+ })
1577+ }
1578+ }
1579+
15241580func protoListEqual (protoListA , protoListB []* mpi.File ) bool {
15251581 for i := range protoListA {
15261582 res := proto .Equal (protoListA [i ], protoListB [i ])
0 commit comments