Release 3X-UI for Docker / build (push) Canceled after 0s
Release 3X-UI / build (386) (push) Canceled after 0s
Release 3X-UI / build (amd64) (push) Canceled after 0s
Release 3X-UI / build (arm64) (push) Canceled after 0s
Release 3X-UI / build (armv5) (push) Canceled after 0s
Release 3X-UI / build (armv6) (push) Canceled after 0s
Release 3X-UI / build (armv7) (push) Canceled after 0s
Release 3X-UI / build (s390x) (push) Canceled after 0s
Release 3X-UI / Build for Windows (amd64) (push) Canceled after 0s
Release 3X-UI / Publish rolling dev release (push) Canceled after 0s
46 lines
1.3 KiB
Go
46 lines
1.3 KiB
Go
package service
|
|
|
|
import "testing"
|
|
|
|
func TestParseAccessLogFields(t *testing.T) {
|
|
malformed := []string{
|
|
"",
|
|
"singletoken",
|
|
"2024/01/02",
|
|
"2024/01/02 15:04:05.000000 from",
|
|
"2024/01/02 15:04:05.000000 accepted",
|
|
"2024/01/02 15:04:05.000000 email:",
|
|
}
|
|
for _, line := range malformed {
|
|
func() {
|
|
defer func() {
|
|
if r := recover(); r != nil {
|
|
t.Errorf("parseAccessLogFields panicked on %q: %v", line, r)
|
|
}
|
|
}()
|
|
_ = parseAccessLogFields(line)
|
|
}()
|
|
}
|
|
|
|
line := "2024/01/02 15:04:05.123456 from 1.2.3.4:555 accepted tcp:example.com:443 [inbound-tag >> outbound-tag] email: alice@example.com"
|
|
entry := parseAccessLogFields(line)
|
|
if entry.FromAddress != "1.2.3.4:555" {
|
|
t.Errorf("FromAddress = %q, want %q", entry.FromAddress, "1.2.3.4:555")
|
|
}
|
|
if entry.ToAddress != "tcp:example.com:443" {
|
|
t.Errorf("ToAddress = %q, want %q", entry.ToAddress, "tcp:example.com:443")
|
|
}
|
|
if entry.Inbound != "inbound-tag" {
|
|
t.Errorf("Inbound = %q, want %q", entry.Inbound, "inbound-tag")
|
|
}
|
|
if entry.Outbound != "outbound-tag" {
|
|
t.Errorf("Outbound = %q, want %q", entry.Outbound, "outbound-tag")
|
|
}
|
|
if entry.Email != "alice@example.com" {
|
|
t.Errorf("Email = %q, want %q", entry.Email, "alice@example.com")
|
|
}
|
|
if entry.DateTime.IsZero() {
|
|
t.Error("DateTime was not parsed from a well-formed line")
|
|
}
|
|
}
|