package logic

import (
	"testing"
	"time"
)

func TestReg1(t *testing.T) {
	itmes := []string{
		`<86>Jan 27 16:00:53 admin02 sftp-server[3761842]: rename old "/tmp/X680G55_9800195108886297_20251230-012816_bmcblackinfo.tar.tabby-upload" new "/tmp/X680G55_9800195108886297_20251230-012816_bmcblackinfo.tar"`,
	}
	for _, v := range itmes {
		if ReMatch.MatchString(v) {
			t.Logf("match: %s", v)
			fields := ReMatch.FindStringSubmatch(v)

			tt, err := time.Parse("Jan _2 15:04:05", fields[1])
			if err != nil {
				t.Log("parse time error!")
			} else {
				tn := time.Date(time.Now().Year(), tt.Month(), tt.Day(), tt.Hour(), tt.Minute(), tt.Second(), 0, time.Local)
				t.Logf("time is %v", tn)
			}
			for ki, vi := range fields {
				t.Logf("    %d: %v", ki, vi)
			}
		} else {
			t.Logf("not match: %s", v)
		}
	}
}

func TestParseItem(t *testing.T) {
	itmes := []string{
		`<86>Jan 27 16:00:53 admin02 sftp-server[3761842]: rename old "/tmp/X680G55_9800195108886297_20251230-012816_bmcblackinfo.tar.tabby-upload" new "/tmp/X680G55_9800195108886297_20251230-012816_bmcblackinfo.tar"`,
		`<86>Jan 27 16:00:53 admin02 sftp-server[3761842]: open "/tmp/X680G55_9800195108886297_20251230-012816_bmcblackinfo.tar.tabby-upload" flags WRITE,CREATE mode 0666`,
		`<86>Jan 27 16:00:53 admin02 sftp-server[3761842]: close "/tmp/X680G55_9800195108886297_20251230-012816_bmcblackinfo.tar.tabby-upload" bytes read 0 written 1412082`,
	}
	for _, v := range itmes {
		i, err := ParseItem(v)
		if err != nil {
			t.Error(err)
		}
		if i != nil {
			t.Logf("%+v", i)
		} else {
			t.Logf("not match: %s", v)
		}
	}
}
