Skip to content

Commit

Permalink
add ResetRecord to logger (#128)
Browse files Browse the repository at this point in the history
  • Loading branch information
JunNishimura committed Jun 17, 2023
1 parent ffd3384 commit 124f594
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
5 changes: 5 additions & 0 deletions internal/log/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const (
CommitRecord
CheckoutRecord
BranchRecord
ResetRecord
)

func NewRecordType(typeString string) RecordType {
Expand All @@ -27,6 +28,8 @@ func NewRecordType(typeString string) RecordType {
return CheckoutRecord
case "branch":
return BranchRecord
case "reset":
return ResetRecord
default:
return UndefinedRecord
}
Expand All @@ -40,6 +43,8 @@ func (t RecordType) String() string {
return "checkout"
case BranchRecord:
return "branch"
case ResetRecord:
return "reset"
default:
return "undefined"
}
Expand Down
60 changes: 60 additions & 0 deletions internal/log/logger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,37 @@ func TestNewRecord(t *testing.T) {
},
}
}(),
func() *test {
hash, _ := hex.DecodeString("87f3c49bccf2597484ece08746d3ee5defaba335")
now := time.Now()
unixtime := fmt.Sprint(now.Unix())
_, offset := now.Zone()
offsetMinutes := offset / 60
timeDiff := fmt.Sprintf("%+03d%02d", offsetMinutes/60, offsetMinutes%60)

return &test{
name: "success: reset record",
args: args{
recType: ResetRecord,
from: sha.SHA1(hash),
to: sha.SHA1(hash),
name: "Test Taro",
email: "test@example.com",
t: now,
message: "test",
},
want: &record{
recType: ResetRecord,
from: sha.SHA1(hash),
to: sha.SHA1(hash),
name: "Test Taro",
email: "test@example.com",
unixtime: unixtime,
timeDiff: timeDiff,
message: "test",
},
}
}(),
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down Expand Up @@ -185,6 +216,20 @@ func TestWriteHEAD(t *testing.T) {
wantErr: false,
}
}(),
func() *test {
hash, _ := hex.DecodeString("87f3c49bccf2597484ece08746d3ee5defaba335")
now := time.Now()
rec := NewRecord(ResetRecord, hash, hash, "Test Taro", "test@example.com", now, "test")

return &test{
name: "success: reset record",
args: args{
rec: rec,
},
want: fmt.Sprintf("%s %s %s <%s> %s %s\t%s: %s\n", rec.from, rec.to, rec.name, rec.email, rec.unixtime, rec.timeDiff, rec.recType, rec.message),
wantErr: false,
}
}(),
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down Expand Up @@ -265,6 +310,21 @@ func TestWriteBranch(t *testing.T) {
wantErr: false,
}
}(),
func() *test {
hash, _ := hex.DecodeString("87f3c49bccf2597484ece08746d3ee5defaba335")
now := time.Now()
rec := NewRecord(ResetRecord, hash, hash, "Test Taro", "test@example.com", now, "test")

return &test{
name: "success: reset record",
args: args{
rec: rec,
branchName: "test",
},
want: fmt.Sprintf("%s %s %s <%s> %s %s\t%s: %s\n", rec.from, rec.to, rec.name, rec.email, rec.unixtime, rec.timeDiff, rec.recType, rec.message),
wantErr: false,
}
}(),
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down

0 comments on commit 124f594

Please sign in to comment.