-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cfe4090
commit 476a301
Showing
1 changed file
with
131 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
package log | ||
|
||
import ( | ||
"encoding/hex" | ||
"fmt" | ||
"reflect" | ||
"testing" | ||
"time" | ||
|
||
"github.com/JunNishimura/Goit/internal/sha" | ||
) | ||
|
||
func TestNewRecord(t *testing.T) { | ||
type args struct { | ||
recType recordType | ||
from sha.SHA1 | ||
to sha.SHA1 | ||
name string | ||
email string | ||
t time.Time | ||
message string | ||
} | ||
type test struct { | ||
name string | ||
args args | ||
want *record | ||
} | ||
tests := []*test{ | ||
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: commit record", | ||
args: args{ | ||
recType: CommitRecord, | ||
from: sha.SHA1(hash), | ||
to: sha.SHA1(hash), | ||
name: "Test Taro", | ||
email: "test@example.com", | ||
t: now, | ||
message: "test", | ||
}, | ||
want: &record{ | ||
recType: CommitRecord, | ||
from: sha.SHA1(hash), | ||
to: sha.SHA1(hash), | ||
name: "Test Taro", | ||
email: "test@example.com", | ||
unixtime: unixtime, | ||
timeDiff: timeDiff, | ||
message: "test", | ||
}, | ||
} | ||
}(), | ||
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: branch record", | ||
args: args{ | ||
recType: BranchRecord, | ||
from: sha.SHA1(hash), | ||
to: sha.SHA1(hash), | ||
name: "Test Taro", | ||
email: "test@example.com", | ||
t: now, | ||
message: "test", | ||
}, | ||
want: &record{ | ||
recType: BranchRecord, | ||
from: sha.SHA1(hash), | ||
to: sha.SHA1(hash), | ||
name: "Test Taro", | ||
email: "test@example.com", | ||
unixtime: unixtime, | ||
timeDiff: timeDiff, | ||
message: "test", | ||
}, | ||
} | ||
}(), | ||
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: checkout record", | ||
args: args{ | ||
recType: CheckoutRecord, | ||
from: sha.SHA1(hash), | ||
to: sha.SHA1(hash), | ||
name: "Test Taro", | ||
email: "test@example.com", | ||
t: now, | ||
message: "test", | ||
}, | ||
want: &record{ | ||
recType: CheckoutRecord, | ||
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) { | ||
got := NewRecord(tt.args.recType, tt.args.from, tt.args.to, tt.args.name, tt.args.email, tt.args.t, tt.args.message) | ||
if !reflect.DeepEqual(got, tt.want) { | ||
t.Errorf("got = %v, want = %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} |