Skip to content

Commit

Permalink
add TestDeleteBranch (#108)
Browse files Browse the repository at this point in the history
  • Loading branch information
JunNishimura committed Jun 13, 2023
1 parent ccb6c49 commit e93e96a
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions internal/log/logger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,3 +287,55 @@ func TestWriteBranch(t *testing.T) {
})
}
}

func TestDeleteBranch(t *testing.T) {
type args struct {
branchName string
}
type fields struct {
rec *record
}
type test struct {
name string
args args
fields fields
wantErr bool
}
tests := []*test{
func() *test {
hash, _ := hex.DecodeString("87f3c49bccf2597484ece08746d3ee5defaba335")
now := time.Now()
rec := NewRecord(CommitRecord, hash, hash, "Test Taro", "test@example.com", now, "test")

return &test{
name: "success",
args: args{
branchName: "test",
},
fields: fields{
rec: rec,
},
wantErr: false,
}
}(),
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
tmpDir := t.TempDir()

gLogger := NewGoitLogger(tmpDir)
if err := gLogger.WriteBranch(tt.fields.rec, tt.args.branchName); err != nil {
t.Log(err)
}

if err := gLogger.DeleteBranch(tt.args.branchName); (err != nil) != tt.wantErr {
t.Errorf("got = %v, want = %v", err, tt.wantErr)
}

branchPath := filepath.Join(tmpDir, "logs", "refs", "heads", tt.args.branchName)
if _, err := os.Stat(branchPath); !os.IsNotExist(err) {
t.Errorf("fail to delete '%s'", tt.args.branchName)
}
})
}
}

0 comments on commit e93e96a

Please sign in to comment.