Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhangKai committed Dec 22, 2017
1 parent 0f1b2e5 commit a6bb5f6
Showing 1 changed file with 69 additions and 2 deletions.
71 changes: 69 additions & 2 deletions gocron_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
// Tests for gocron
package gocron

import (
"fmt"
"testing"
"time"
"fmt"
)

var err = 1
Expand All @@ -23,3 +22,71 @@ func TestSecond(*testing.T) {
defaultScheduler.Start()
time.Sleep(10 * time.Second)
}

func Test_formatTime(t *testing.T) {
tests := []struct {
name string
args string
wantHour int
wantMin int
wantErr bool
}{
{
name: "normal",
args: "16:18",
wantHour: 16,
wantMin: 18,
wantErr: false,
},
{
name: "normal",
args: "6:18",
wantHour: 6,
wantMin: 18,
wantErr: false,
},
{
name: "notnumber",
args: "e:18",
wantHour: 0,
wantMin: 0,
wantErr: true,
},
{
name: "outofrange",
args: "25:18",
wantHour: 25,
wantMin: 18,
wantErr: true,
},
{
name: "wrongformat",
args: "19:18:17",
wantHour: 0,
wantMin: 0,
wantErr: true,
},
{
name: "wrongminute",
args: "19:1e",
wantHour: 19,
wantMin: 0,
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
gotHour, gotMin, err := formatTime(tt.args)
if (err != nil) != tt.wantErr {
t.Errorf("formatTime() error = %v, wantErr %v", err, tt.wantErr)
return
}
if gotHour != tt.wantHour {
t.Errorf("formatTime() gotHour = %v, want %v", gotHour, tt.wantHour)
}
if gotMin != tt.wantMin {
t.Errorf("formatTime() gotMin = %v, want %v", gotMin, tt.wantMin)
}
})
}
}

0 comments on commit a6bb5f6

Please sign in to comment.