package openldaplog import ( "fmt" "time" "strings" "testing" ) var ( gOlog = NewOpenldapLog(false) ) const ( ) func TestParseAccept(t *testing.T) { line := `2022-07-18T09:23:20.160516+02:00 ldap.domain.org slapd[82581] conn=1512 fd=10 ACCEPT from IP=10.11.12.16:64482 (IP=0.0.0.0:389)` loc,_ := time.LoadLocation("CET") wt := time.Date(2022, 7, 18, 9, 23, 20, 160516*1000, loc) lf, err := gOlog.Parse([]byte(line)) if err != nil { t.Error(err) } if false == lf.Time.Equal(wt) { fmt.Printf("Got : %v\n", lf.Time) fmt.Printf("Wanted: %v\n", wt) t.Error("Parsing time") } if false == strings.EqualFold(lf.Hostname, "ldap.domain.org") { fmt.Printf("Got : %v\n", lf.Hostname) fmt.Printf("Wanted: ldap.domain.org\n") t.Error("Parsing hostname") } if false == strings.EqualFold(lf.Process, "slapd[82581]") { fmt.Printf("Got : %v\n", lf.Process) fmt.Printf("Wanted: slapd[82581]\n") t.Error("Parsing process") } if lf.ConnId != 1512 { fmt.Printf("Got : %v\n", lf.ConnId) fmt.Printf("Wanted: 1512\n") t.Error("Parsing ConnId") } if lf.ConnFd != 10 { fmt.Printf("Got : %v\n", lf.ConnFd) fmt.Printf("Wanted: 10\n") t.Error("Parsing ConnFd") } if false == strings.EqualFold(lf.OpType, "accept") { fmt.Printf("Got : %v\n", lf.OpType) fmt.Printf("Wanted: accept\n") t.Error("Parsing OpType") } if false == strings.EqualFold(lf.ClientIp, "10.11.12.16") { fmt.Printf("Got : %v\n", lf.ClientIp) fmt.Printf("Wanted: 10.11.12.16\n") t.Error("Parsing ClientIp") } if lf.ClientPort != 64482 { fmt.Printf("Got : %v\n", lf.ClientPort) fmt.Printf("Wanted: 64482\n") t.Error("Parsing ClientPort") } if false == strings.EqualFold(lf.ServerIp, "0.0.0.0") { fmt.Printf("Got : %v\n", lf.ServerIp) fmt.Printf("Wanted: 0.0.0.0\n") t.Error("Parsing ServerIp") } if lf.ServerPort != 389 { fmt.Printf("Got : %v\n", lf.ServerPort) fmt.Printf("Wanted: 389\n") t.Error("Parsing ServerPort") } } func TestParseStartTLS(t *testing.T) { line := `2022-07-18T22:57:50.184389+02:00 ldap.domain.org slapd[82581] conn=1623 op=0 STARTTLS` loc,_ := time.LoadLocation("CET") wt := time.Date(2022, 7, 18, 22, 57, 50, 184389*1000, loc) lf, err := gOlog.Parse([]byte(line)) if err != nil { t.Error(err) } if false == lf.Time.Equal(wt) { fmt.Printf("Got : %v\n", lf.Time) fmt.Printf("Wanted: %v\n", wt) t.Error("Parsing time") } if false == strings.EqualFold(lf.Hostname, "ldap.domain.org") { fmt.Printf("Got : %v\n", lf.Hostname) fmt.Printf("Wanted: ldap.domain.org\n") t.Error("Parsing hostname") } if false == strings.EqualFold(lf.Process, "slapd[82581]") { fmt.Printf("Got : %v\n", lf.Process) fmt.Printf("Wanted: slapd[82581]\n") t.Error("Parsing process") } if lf.ConnId != 1623 { fmt.Printf("Got : %v\n", lf.ConnId) fmt.Printf("Wanted: 1512\n") t.Error("Parsing ConnId") } if lf.ConnFd != 0 { fmt.Printf("Got : %v\n", lf.ConnFd) fmt.Printf("Wanted: 0\n") t.Error("Parsing ConnFd") } if lf.OpId != 0 { fmt.Printf("Got : %v\n", lf.OpId) fmt.Printf("Wanted: 0\n") t.Error("Parsing OpId") } if false == strings.EqualFold(lf.OpType, "starttls") { fmt.Printf("Got : %v\n", lf.OpType) fmt.Printf("Wanted: \n") t.Error("Parsing OpType") } } func TestParseBindMethod(t *testing.T) { line := `2022-07-18T09:25:35.224296+02:00 ldap.domain.org slapd[82581] conn=1512 op=1 BIND dn="cn=coincoin,dc=domain,dc=org" method=128` loc,_ := time.LoadLocation("CET") wt := time.Date(2022, 7, 18, 9, 25, 35, 224296*1000, loc) lf, err := gOlog.Parse([]byte(line)) if err != nil { t.Error(err) } if false == lf.Time.Equal(wt) { fmt.Printf("Got : %v\n", lf.Time) fmt.Printf("Wanted: %v\n", wt) t.Error("Parsing time") } if false == strings.EqualFold(lf.Hostname, "ldap.domain.org") { fmt.Printf("Got : %v\n", lf.Hostname) fmt.Printf("Wanted: ldap.domain.org\n") t.Error("Parsing hostname") } if false == strings.EqualFold(lf.Process, "slapd[82581]") { fmt.Printf("Got : %v\n", lf.Process) fmt.Printf("Wanted: slapd[82581]\n") t.Error("Parsing process") } if lf.ConnId != 1512 { fmt.Printf("Got : %v\n", lf.ConnId) fmt.Printf("Wanted: 1512\n") t.Error("Parsing ConnId") } if lf.ConnFd != 0 { fmt.Printf("Got : %v\n", lf.ConnFd) fmt.Printf("Wanted: 0\n") t.Error("Parsing ConnFd") } if lf.OpId != 1 { fmt.Printf("Got : %v\n", lf.OpId) fmt.Printf("Wanted: 1\n") t.Error("Parsing OpId") } if false == strings.EqualFold(lf.OpType, "bind") { fmt.Printf("Got : %v\n", lf.OpType) fmt.Printf("Wanted: accept\n") t.Error("Parsing OpType") } if false == strings.EqualFold(lf.BindDN, "cn=coincoin,dc=domain,dc=org") { fmt.Printf("Got : %v\n", lf.BindDN) fmt.Printf("Wanted: cn=coincoin,dc=domain,dc=org\n") t.Error("Parsing BindDN") } if false == strings.EqualFold(lf.BindMethod, "128") { fmt.Printf("Got : %v\n", lf.BindMethod) fmt.Printf("Wanted: 128\n") t.Error("Parsing BindMethod") } } func TestParseBindMech(t *testing.T) { line := `2022-07-18T09:25:35.224329+02:00 ldap.domain.org slapd[82581] conn=1512 op=1 BIND dn="cn=coincoin,dc=domain,dc=org" mech=SIMPLE ssf=0` loc,_ := time.LoadLocation("CET") wt := time.Date(2022, 7, 18, 9, 25, 35, 224329*1000, loc) lf, err := gOlog.Parse([]byte(line)) if err != nil { t.Error(err) } if false == lf.Time.Equal(wt) { fmt.Printf("Got : %v\n", lf.Time) fmt.Printf("Wanted: %v\n", wt) t.Error("Parsing time") } if false == strings.EqualFold(lf.Hostname, "ldap.domain.org") { fmt.Printf("Got : %v\n", lf.Hostname) fmt.Printf("Wanted: ldap.domain.org\n") t.Error("Parsing hostname") } if false == strings.EqualFold(lf.Process, "slapd[82581]") { fmt.Printf("Got : %v\n", lf.Process) fmt.Printf("Wanted: slapd[82581]\n") t.Error("Parsing process") } if lf.ConnId != 1512 { fmt.Printf("Got : %v\n", lf.ConnId) fmt.Printf("Wanted: 1512\n") t.Error("Parsing ConnId") } if lf.ConnFd != 0 { fmt.Printf("Got : %v\n", lf.ConnFd) fmt.Printf("Wanted: 0\n") t.Error("Parsing ConnFd") } if lf.OpId != 1 { fmt.Printf("Got : %v\n", lf.OpId) fmt.Printf("Wanted: 1\n") t.Error("Parsing OpId") } if false == strings.EqualFold(lf.OpType, "bind") { fmt.Printf("Got : %v\n", lf.OpType) fmt.Printf("Wanted: accept\n") t.Error("Parsing OpType") } if false == strings.EqualFold(lf.BindDN, "") { fmt.Printf("Got : %v\n", lf.BindDN) fmt.Printf("Wanted: \n") t.Error("Parsing BindDN") } if false == strings.EqualFold(lf.BindMech, "simple") { fmt.Printf("Got : %v\n", lf.BindMech) fmt.Printf("Wanted: simple\n") t.Error("Parsing BindMech") } } func TestParseResult(t *testing.T) { line := `2022-07-18T09:25:35.224353+02:00 ldap.domain.org slapd[82581] conn=1512 op=1 RESULT tag=97 err=0 text=` loc,_ := time.LoadLocation("CET") wt := time.Date(2022, 7, 18, 9, 25, 35, 224353*1000, loc) lf, err := gOlog.Parse([]byte(line)) if err != nil { t.Error(err) } if false == lf.Time.Equal(wt) { fmt.Printf("Got : %v\n", lf.Time) fmt.Printf("Wanted: %v\n", wt) t.Error("Parsing time") } if false == strings.EqualFold(lf.Hostname, "ldap.domain.org") { fmt.Printf("Got : %v\n", lf.Hostname) fmt.Printf("Wanted: ldap.domain.org\n") t.Error("Parsing hostname") } if false == strings.EqualFold(lf.Process, "slapd[82581]") { fmt.Printf("Got : %v\n", lf.Process) fmt.Printf("Wanted: slapd[82581]\n") t.Error("Parsing process") } if lf.ConnId != 1512 { fmt.Printf("Got : %v\n", lf.ConnId) fmt.Printf("Wanted: 1512\n") t.Error("Parsing ConnId") } if lf.ConnFd != 0 { fmt.Printf("Got : %v\n", lf.ConnFd) fmt.Printf("Wanted: 0\n") t.Error("Parsing ConnFd") } if lf.OpId != 1 { fmt.Printf("Got : %v\n", lf.OpId) fmt.Printf("Wanted: 1\n") t.Error("Parsing OpId") } if lf.Result != true { fmt.Printf("Got : %v\n", lf.Result) fmt.Printf("Wanted: true\n") t.Error("Parsing Result") } if false == strings.EqualFold(lf.OpType, "") { fmt.Printf("Got : %v\n", lf.OpType) fmt.Printf("Wanted: \n") t.Error("Parsing OpType") } if false == strings.EqualFold(lf.ResTag, "97") { fmt.Printf("Got : %v\n", lf.ResTag) fmt.Printf("Wanted: 97\n") t.Error("Parsing ResTag") } if lf.ResErr != 0 { fmt.Printf("Got : %v\n", lf.ResErr) fmt.Printf("Wanted: 0\n") t.Error("Parsing ResErr") } if false == strings.EqualFold(lf.ResText, "") { fmt.Printf("Got : %v\n", lf.ResText) fmt.Printf("Wanted: \n") t.Error("Parsing ResText") } } func TestParseUnbind(t *testing.T) { line := `2022-07-18T09:25:35.225177+02:00 ldap.domain.org slapd[82581] conn=1512 op=2 UNBIND` loc,_ := time.LoadLocation("CET") wt := time.Date(2022, 7, 18, 9, 25, 35, 225177*1000, loc) lf, err := gOlog.Parse([]byte(line)) if err != nil { t.Error(err) } if false == lf.Time.Equal(wt) { fmt.Printf("Got : %v\n", lf.Time) fmt.Printf("Wanted: %v\n", wt) t.Error("Parsing time") } if false == strings.EqualFold(lf.Hostname, "ldap.domain.org") { fmt.Printf("Got : %v\n", lf.Hostname) fmt.Printf("Wanted: ldap.domain.org\n") t.Error("Parsing hostname") } if false == strings.EqualFold(lf.Process, "slapd[82581]") { fmt.Printf("Got : %v\n", lf.Process) fmt.Printf("Wanted: slapd[82581]\n") t.Error("Parsing process") } if lf.ConnId != 1512 { fmt.Printf("Got : %v\n", lf.ConnId) fmt.Printf("Wanted: 1512\n") t.Error("Parsing ConnId") } if lf.ConnFd != 0 { fmt.Printf("Got : %v\n", lf.ConnFd) fmt.Printf("Wanted: 0\n") t.Error("Parsing ConnFd") } if lf.OpId != 2 { fmt.Printf("Got : %v\n", lf.OpId) fmt.Printf("Wanted: 2\n") t.Error("Parsing OpId") } if false == strings.EqualFold(lf.OpType, "unbind") { fmt.Printf("Got : %v\n", lf.OpType) fmt.Printf("Wanted: unbind\n") t.Error("Parsing OpType") } } func TestParseModDN(t *testing.T) { line := `2022-07-18T09:25:35.224767+02:00 ldap.domain.org slapd[82581] conn=1512 op=3 MOD dn="cn=coincoin,dc=domain,dc=org"` loc,_ := time.LoadLocation("CET") wt := time.Date(2022, 7, 18, 9, 25, 35, 224767*1000, loc) lf, err := gOlog.Parse([]byte(line)) if err != nil { t.Error(err) } if false == lf.Time.Equal(wt) { fmt.Printf("Got : %v\n", lf.Time) fmt.Printf("Wanted: %v\n", wt) t.Error("Parsing time") } if false == strings.EqualFold(lf.Hostname, "ldap.domain.org") { fmt.Printf("Got : %v\n", lf.Hostname) fmt.Printf("Wanted: ldap.domain.org\n") t.Error("Parsing hostname") } if false == strings.EqualFold(lf.Process, "slapd[82581]") { fmt.Printf("Got : %v\n", lf.Process) fmt.Printf("Wanted: slapd[82581]\n") t.Error("Parsing process") } if lf.ConnId != 1512 { fmt.Printf("Got : %v\n", lf.ConnId) fmt.Printf("Wanted: 1512\n") t.Error("Parsing ConnId") } if lf.ConnFd != 0 { fmt.Printf("Got : %v\n", lf.ConnFd) fmt.Printf("Wanted: 0\n") t.Error("Parsing ConnFd") } if lf.OpId != 3 { fmt.Printf("Got : %v\n", lf.OpId) fmt.Printf("Wanted: 3\n") t.Error("Parsing OpId") } if false == strings.EqualFold(lf.ModDN, "cn=coincoin,dc=domain,dc=org") { fmt.Printf("Got : %v\n", lf.ModDN) fmt.Printf("Wanted: cn=coincoin,dc=domain,dc=org\n") t.Error("Parsing ModDN") } } func TestParseModAttr(t *testing.T) { line := `2022-07-18T09:25:35.224779+02:00 ldap.domain.org slapd[82581] conn=1512 op=3 MOD attr=description` loc,_ := time.LoadLocation("CET") wt := time.Date(2022, 7, 18, 9, 25, 35, 224779*1000, loc) lf, err := gOlog.Parse([]byte(line)) if err != nil { t.Error(err) } if false == lf.Time.Equal(wt) { fmt.Printf("Got : %v\n", lf.Time) fmt.Printf("Wanted: %v\n", wt) t.Error("Parsing time") } if false == strings.EqualFold(lf.Hostname, "ldap.domain.org") { fmt.Printf("Got : %v\n", lf.Hostname) fmt.Printf("Wanted: ldap.domain.org\n") t.Error("Parsing hostname") } if false == strings.EqualFold(lf.Process, "slapd[82581]") { fmt.Printf("Got : %v\n", lf.Process) fmt.Printf("Wanted: slapd[82581]\n") t.Error("Parsing process") } if lf.ConnId != 1512 { fmt.Printf("Got : %v\n", lf.ConnId) fmt.Printf("Wanted: 1512\n") t.Error("Parsing ConnId") } if lf.ConnFd != 0 { fmt.Printf("Got : %v\n", lf.ConnFd) fmt.Printf("Wanted: 0\n") t.Error("Parsing ConnFd") } if lf.OpId != 3 { fmt.Printf("Got : %v\n", lf.OpId) fmt.Printf("Wanted: 3\n") t.Error("Parsing OpId") } if false == strings.EqualFold(lf.OpType, "mod") { fmt.Printf("Got : %v\n", lf.OpType) fmt.Printf("Wanted: \n") t.Error("Parsing OpType") } if false == strings.EqualFold(lf.ModAttr, "description") { fmt.Printf("Got : %v\n", lf.ModAttr) fmt.Printf("Wanted: description\n") t.Error("Parsing ModAttr") } } func TestParsePassMod(t *testing.T) { line := `2022-07-18T09:25:35.224767+02:00 ldap.domain.org slapd[82581] conn=1512 op=4 PASSMOD id="cn=pika,ou=users,dc=domain,dc=org" new` loc,_ := time.LoadLocation("CET") wt := time.Date(2022, 7, 18, 9, 25, 35, 224767*1000, loc) lf, err := gOlog.Parse([]byte(line)) if err != nil { t.Error(err) } if false == lf.Time.Equal(wt) { fmt.Printf("Got : %v\n", lf.Time) fmt.Printf("Wanted: %v\n", wt) t.Error("Parsing time") } if false == strings.EqualFold(lf.Hostname, "ldap.domain.org") { fmt.Printf("Got : %v\n", lf.Hostname) fmt.Printf("Wanted: ldap.domain.org\n") t.Error("Parsing hostname") } if false == strings.EqualFold(lf.Process, "slapd[82581]") { fmt.Printf("Got : %v\n", lf.Process) fmt.Printf("Wanted: slapd[82581]\n") t.Error("Parsing process") } if lf.ConnId != 1512 { fmt.Printf("Got : %v\n", lf.ConnId) fmt.Printf("Wanted: 1512\n") t.Error("Parsing ConnId") } if lf.ConnFd != 0 { fmt.Printf("Got : %v\n", lf.ConnFd) fmt.Printf("Wanted: 0\n") t.Error("Parsing ConnFd") } if lf.OpId != 4 { fmt.Printf("Got : %v\n", lf.OpId) fmt.Printf("Wanted: 4\n") t.Error("Parsing OpId") } if false == strings.EqualFold(lf.PassModDN, "cn=pika,ou=users,dc=domain,dc=org") { fmt.Printf("Got : %v\n", lf.PassModDN) fmt.Printf("Wanted: cn=pika,ou=users,dc=domain,dc=org\n") t.Error("Parsing PassModDN") } } func TestParseSearchBase(t *testing.T) { line := `2022-07-18T09:25:35.224787+02:00 ldap.domain.org slapd[82581] conn=1512 op=2 SRCH base="ou=users,dc=domain,dc=org" scope=2 deref=0 filter="(&(objectClass=person)(cn=pika))"` loc,_ := time.LoadLocation("CET") wt := time.Date(2022, 7, 18, 9, 25, 35, 224787*1000, loc) lf, err := gOlog.Parse([]byte(line)) if err != nil { t.Error(err) } if false == lf.Time.Equal(wt) { fmt.Printf("Got : %v\n", lf.Time) fmt.Printf("Wanted: %v\n", wt) t.Error("Parsing time") } if false == strings.EqualFold(lf.Hostname, "ldap.domain.org") { fmt.Printf("Got : %v\n", lf.Hostname) fmt.Printf("Wanted: ldap.domain.org\n") t.Error("Parsing hostname") } if false == strings.EqualFold(lf.Process, "slapd[82581]") { fmt.Printf("Got : %v\n", lf.Process) fmt.Printf("Wanted: slapd[82581]\n") t.Error("Parsing process") } if lf.ConnId != 1512 { fmt.Printf("Got : %v\n", lf.ConnId) fmt.Printf("Wanted: 1512\n") t.Error("Parsing ConnId") } if lf.ConnFd != 0 { fmt.Printf("Got : %v\n", lf.ConnFd) fmt.Printf("Wanted: 0\n") t.Error("Parsing ConnFd") } if lf.OpId != 2 { fmt.Printf("Got : %v\n", lf.OpId) fmt.Printf("Wanted: 2\n") t.Error("Parsing OpId") } if false == strings.EqualFold(lf.OpType, "search") { fmt.Printf("Got : %v\n", lf.OpType) fmt.Printf("Wanted: search\n") t.Error("Parsing OpType") } if false == strings.EqualFold(lf.SearchBase, "ou=users,dc=domain,dc=org") { fmt.Printf("Got : %v\n", lf.SearchBase) fmt.Printf("Wanted: ou=users,dc=domain,dc=org\n") t.Error("Parsing SearchBase") } if false == strings.EqualFold(lf.SearchScope, "2") { fmt.Printf("Got : %v\n", lf.SearchScope) fmt.Printf("Wanted: 2\n") t.Error("Parsing SearchScope") } if false == strings.EqualFold(lf.SearchDeref, "0") { fmt.Printf("Got : %v\n", lf.SearchDeref) fmt.Printf("Wanted: 0\n") t.Error("Parsing SearchDeref") } if false == strings.EqualFold(lf.SearchFilter, "(&(objectClass=person)(cn=pika))") { fmt.Printf("Got : %v\n", lf.SearchFilter) fmt.Printf("Wanted: (&(objectClass=person)(cn=pika))\n") t.Error("Parsing SearchFilter") } } func TestParseSearchAttr(t *testing.T) { line := `2022-07-18T09:25:35.224779+02:00 ldap.domain.org slapd[82581] conn=1512 op=2 SRCH attr=objectClass userPrincipalName userAccountControl mail rfc822Mailbox entryUUID uid cn` loc,_ := time.LoadLocation("CET") wt := time.Date(2022, 7, 18, 9, 25, 35, 224779*1000, loc) lf, err := gOlog.Parse([]byte(line)) if err != nil { t.Error(err) } if false == lf.Time.Equal(wt) { fmt.Printf("Got : %v\n", lf.Time) fmt.Printf("Wanted: %v\n", wt) t.Error("Parsing time") } if false == strings.EqualFold(lf.Hostname, "ldap.domain.org") { fmt.Printf("Got : %v\n", lf.Hostname) fmt.Printf("Wanted: ldap.domain.org\n") t.Error("Parsing hostname") } if false == strings.EqualFold(lf.Process, "slapd[82581]") { fmt.Printf("Got : %v\n", lf.Process) fmt.Printf("Wanted: slapd[82581]\n") t.Error("Parsing process") } if lf.ConnId != 1512 { fmt.Printf("Got : %v\n", lf.ConnId) fmt.Printf("Wanted: 1512\n") t.Error("Parsing ConnId") } if lf.ConnFd != 0 { fmt.Printf("Got : %v\n", lf.ConnFd) fmt.Printf("Wanted: 0\n") t.Error("Parsing ConnFd") } if lf.OpId != 2 { fmt.Printf("Got : %v\n", lf.OpId) fmt.Printf("Wanted: 2\n") t.Error("Parsing OpId") } if false == strings.EqualFold(lf.OpType, "") { fmt.Printf("Got : %v\n", lf.OpType) fmt.Printf("Wanted: \n") t.Error("Parsing OpType") } if false == strings.EqualFold(lf.SearchAttr, "objectClass userPrincipalName userAccountControl mail rfc822Mailbox entryUUID uid cn") { fmt.Printf("Got : %v\n", lf.SearchAttr) fmt.Printf("Wanted: objectClass userPrincipalName userAccountControl mail rfc822Mailbox entryUUID uid cn\n") t.Error("Parsing SearchAttr") } if false == strings.EqualFold(lf.SearchScope, "") { fmt.Printf("Got : %v\n", lf.SearchScope) fmt.Printf("Wanted: \n") t.Error("Parsing SearchScope") } if false == strings.EqualFold(lf.SearchDeref, "") { fmt.Printf("Got : %v\n", lf.SearchDeref) fmt.Printf("Wanted: \n") t.Error("Parsing SearchDeref") } if false == strings.EqualFold(lf.SearchFilter, "") { fmt.Printf("Got : %v\n", lf.SearchFilter) fmt.Printf("Wanted: \n") t.Error("Parsing SearchFilter") } } func TestParseSearchResult(t *testing.T) { line := `2022-07-18T09:25:35.224843+02:00 ldap.domain.org slapd[82581] conn=1512 op=2 SEARCH RESULT tag=101 err=0 nentries=0 text=` loc,_ := time.LoadLocation("CET") wt := time.Date(2022, 7, 18, 9, 25, 35, 224843*1000, loc) lf, err := gOlog.Parse([]byte(line)) if err != nil { t.Error(err) } if false == lf.Time.Equal(wt) { fmt.Printf("Got : %v\n", lf.Time) fmt.Printf("Wanted: %v\n", wt) t.Error("Parsing time") } if false == strings.EqualFold(lf.Hostname, "ldap.domain.org") { fmt.Printf("Got : %v\n", lf.Hostname) fmt.Printf("Wanted: ldap.domain.org\n") t.Error("Parsing hostname") } if false == strings.EqualFold(lf.Process, "slapd[82581]") { fmt.Printf("Got : %v\n", lf.Process) fmt.Printf("Wanted: slapd[82581]\n") t.Error("Parsing process") } if lf.ConnId != 1512 { fmt.Printf("Got : %v\n", lf.ConnId) fmt.Printf("Wanted: 1512\n") t.Error("Parsing ConnId") } if lf.ConnFd != 0 { fmt.Printf("Got : %v\n", lf.ConnFd) fmt.Printf("Wanted: 0\n") t.Error("Parsing ConnFd") } if lf.OpId != 2 { fmt.Printf("Got : %v\n", lf.OpId) fmt.Printf("Wanted: 2\n") t.Error("Parsing OpId") } if lf.SearchResult != true { fmt.Printf("Got : %v\n", lf.SearchResult) fmt.Printf("Wanted: true\n") t.Error("Parsing SearchResult") } if false == strings.EqualFold(lf.OpType, "") { fmt.Printf("Got : %v\n", lf.OpType) fmt.Printf("Wanted: \n") t.Error("Parsing OpType") } if false == strings.EqualFold(lf.SearchResTag, "101") { fmt.Printf("Got : %v\n", lf.SearchResTag) fmt.Printf("Wanted: 101\n") t.Error("Parsing SearchResTag") } if lf.SearchResErr != 0 { fmt.Printf("Got : %v\n", lf.SearchResErr) fmt.Printf("Wanted: 0\n") t.Error("Parsing SearchResErr") } if lf.SearchResNEntries != 0 { fmt.Printf("Got : %v\n", lf.SearchResNEntries) fmt.Printf("Wanted: 0\n") t.Error("Parsing SearchResNEntries") } if false == strings.EqualFold(lf.SearchResText, "") { fmt.Printf("Got : %v\n", lf.SearchResText) fmt.Printf("Wanted: \n") t.Error("Parsing SearchResText") } } func TestParseClosed(t *testing.T) { line := `2022-07-18T09:23:20.226352+02:00 ldap.domain.org slapd[82581] conn=1512 fd=10 closed` loc,_ := time.LoadLocation("CET") wt := time.Date(2022, 7, 18, 9, 23, 20, 226352*1000, loc) lf, err := gOlog.Parse([]byte(line)) if err != nil { t.Error(err) } if false == lf.Time.Equal(wt) { fmt.Printf("Got : %v\n", lf.Time) fmt.Printf("Wanted: %v\n", wt) t.Error("Parsing time") } if false == strings.EqualFold(lf.Hostname, "ldap.domain.org") { fmt.Printf("Got : %v\n", lf.Hostname) fmt.Printf("Wanted: ldap.domain.org\n") t.Error("Parsing hostname") } if false == strings.EqualFold(lf.Process, "slapd[82581]") { fmt.Printf("Got : %v\n", lf.Process) fmt.Printf("Wanted: slapd[82581]\n") t.Error("Parsing process") } if lf.ConnId != 1512 { fmt.Printf("Got : %v\n", lf.ConnId) fmt.Printf("Wanted: 1512\n") t.Error("Parsing ConnId") } if lf.ConnFd != 10 { fmt.Printf("Got : %v\n", lf.ConnFd) fmt.Printf("Wanted: 10\n") t.Error("Parsing ConnFd") } if false == strings.EqualFold(lf.OpType, "close") { fmt.Printf("Got : %v\n", lf.OpType) fmt.Printf("Wanted: close\n") t.Error("Parsing OpType") } }