diff --git a/entities/profile.go b/entities/profile.go index d05907a..576d9e2 100644 --- a/entities/profile.go +++ b/entities/profile.go @@ -1,6 +1,10 @@ package entities -import "time" +import ( + "time" + + "github.com/Songmu/flextime" +) type Profile struct { Job string `json:"job"` @@ -12,5 +16,5 @@ type Profile struct { } func NewProfile(job, description string, skillDescription, licenses []string, pr string) *Profile { - return &Profile{job, description, skillDescription, licenses, pr, time.Now()} + return &Profile{job, description, skillDescription, licenses, pr, flextime.Now()} } diff --git a/entities/skill.go b/entities/skill.go index aa00bdf..f9ac1f6 100644 --- a/entities/skill.go +++ b/entities/skill.go @@ -4,6 +4,8 @@ import ( "fmt" "strings" "time" + + "github.com/Songmu/flextime" ) type SkillCategory int @@ -32,7 +34,7 @@ func NewSkill(name string, lv int, description string, category SkillCategory) * lv, description, category, - time.Now(), + flextime.Now(), } } diff --git a/go.mod b/go.mod index d051658..cf2f665 100644 --- a/go.mod +++ b/go.mod @@ -6,6 +6,7 @@ require ( cloud.google.com/go/firestore v1.14.0 firebase.google.com/go v3.13.0+incompatible github.com/GoogleCloudPlatform/functions-framework-go v1.8.1 + github.com/Songmu/flextime v0.1.0 github.com/google/go-cmp v0.6.0 google.golang.org/api v0.170.0 ) diff --git a/go.sum b/go.sum index 25eb624..e69ed0e 100644 --- a/go.sum +++ b/go.sum @@ -778,6 +778,8 @@ github.com/GoogleCloudPlatform/functions-framework-go v1.8.1 h1:wMO6lE8uR68ReG+/ github.com/GoogleCloudPlatform/functions-framework-go v1.8.1/go.mod h1:kKqAKLm08tjDVs37IG/Dl4hC1/go4E85Udn1LeSdAEI= github.com/JohnCGriffin/overflow v0.0.0-20211019200055-46fa312c352c/go.mod h1:X0CRv0ky0k6m906ixxpzmDRLvX58TFUKS2eePweuyxk= github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= +github.com/Songmu/flextime v0.1.0 h1:sss5IALl84LbvU/cS5D1cKNd5ffT94N2BZwC+esgAJI= +github.com/Songmu/flextime v0.1.0/go.mod h1:ofUSZ/qj7f1BfQQ6rEH4ovewJ0SZmLOjBF1xa8iE87Q= github.com/ajstarks/deck v0.0.0-20200831202436-30c9fc6549a9/go.mod h1:JynElWSGnm/4RlzPXRlREEwqTHAN3T56Bv2ITsFT3gY= github.com/ajstarks/deck/generate v0.0.0-20210309230005-c3f852c02e19/go.mod h1:T13YZdzov6OU0A1+RfKZiZN9ca6VeKdBdyDV+BY97Tk= github.com/ajstarks/svgo v0.0.0-20180226025133-644b8db467af/go.mod h1:K08gAheRH3/J6wwsYMMT4xOr94bZjxIelGM0+d/wbFw= diff --git a/usecase/skill_interactor_test.go b/usecase/skill_interactor_test.go index 88884eb..4329116 100644 --- a/usecase/skill_interactor_test.go +++ b/usecase/skill_interactor_test.go @@ -4,7 +4,10 @@ import ( "fmt" "reflect" "testing" + "time" + "github.com/Songmu/flextime" + "github.com/google/go-cmp/cmp" "github.com/meriy100/portfolio-api/entities" "github.com/meriy100/portfolio-api/usecase/ports" ) @@ -96,16 +99,8 @@ func TestSkillInteractor_IndexSkills(t *testing.T) { } } -func findSkill(name string, skills []*entities.Skill) *entities.Skill { - for _, s := range skills { - if s.Name == name { - return s - } - } - - return nil -} func TestSkillInteractor_UpdateSkills(t *testing.T) { + now := time.Date(2021, 1, 1, 0, 0, 0, 0, time.UTC) type fields struct { outputPort ports.SkillOutputPort postRepository ports.PostRepository @@ -132,6 +127,7 @@ func TestSkillInteractor_UpdateSkills(t *testing.T) { Lv: 2, Description: "testD", Category: entities.Os, + Timestamp: now, }, }, false, @@ -139,6 +135,9 @@ func TestSkillInteractor_UpdateSkills(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { + flextime.Fix(now) + defer flextime.Restore() + s := &SkillInteractor{ outputPort: tt.fields.outputPort, postRepository: tt.fields.postRepository, @@ -151,22 +150,8 @@ func TestSkillInteractor_UpdateSkills(t *testing.T) { if len(tt.want) != len(tt.fields.skillRepository.insert) { t.Errorf("UdateSkills() saved value = %v, want %v", tt.fields.skillRepository.insert, tt.want) } - - for _, wantSkill := range tt.want { - expect := findSkill(wantSkill.Name, tt.fields.skillRepository.insert) - if expect == nil { - t.Fatalf("UpdateSkills() saved value = %v, want %v", tt.fields.skillRepository.insert, tt.want) - } - - if expect.Lv != wantSkill.Lv { - t.Errorf("UpdateSkills() %v's Lv = %v, want %v", expect.Name, expect.Lv, wantSkill.Lv) - } - if expect.Category != wantSkill.Category { - t.Errorf("UpdateSkills() %v's Category = %v, want %v", expect.Name, expect.Category, wantSkill.Category) - } - if expect.Description != wantSkill.Description { - t.Errorf("UpdateSkills() %v's Description = %v, want %v", expect.Name, expect.Description, wantSkill.Description) - } + if diff := cmp.Diff(tt.want, tt.fields.skillRepository.insert); diff != "" { + t.Errorf("UpdateSkills() mismatch (-want +got):\n%s", diff) } }) }