Added tests for job package
This commit is contained in:
parent
c84817132d
commit
88757ef736
4 changed files with 54 additions and 1 deletions
|
@ -19,6 +19,11 @@ go is required. Only go version >= 1.13.5 on linux amd64 has been tested.
|
|||
|
||||
## Building
|
||||
|
||||
To run tests, use :
|
||||
```
|
||||
go test -cover ./...
|
||||
```
|
||||
|
||||
For a debug build, use :
|
||||
```
|
||||
go build
|
||||
|
|
|
@ -10,5 +10,5 @@ type Job struct {
|
|||
}
|
||||
|
||||
func (job Job) String() string {
|
||||
return fmt.Sprintf("Name: \"%s\", Timestamp: \"%d\", Success: \"%t\"", job.Name, job.Timestamp, job.Success)
|
||||
return fmt.Sprintf("Job { Name: \"%s\", Timestamp: \"%d\", Success: \"%t\" }", job.Name, job.Timestamp, job.Success)
|
||||
}
|
||||
|
|
10
job/job_test.go
Normal file
10
job/job_test.go
Normal file
|
@ -0,0 +1,10 @@
|
|||
package job
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestString(t *testing.T) {
|
||||
j := Job{Name: "name", Timestamp: 10, Success: true}
|
||||
if j.String() != "Job { Name: \"name\", Timestamp: \"10\", Success: \"true\" }" {
|
||||
t.Errorf("test string error : %s", j.String())
|
||||
}
|
||||
}
|
38
job/utils_test.go
Normal file
38
job/utils_test.go
Normal file
|
@ -0,0 +1,38 @@
|
|||
package job
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestKeepOldestOnly(t *testing.T) {
|
||||
t.Run("test empty list", func(t *testing.T) {
|
||||
var jobs []Job
|
||||
if len(KeepOldestOnly(jobs)) != 0 {
|
||||
t.Error("empty list failed")
|
||||
}
|
||||
})
|
||||
t.Run("test functionality", func(t *testing.T) {
|
||||
var jobs []Job
|
||||
jobs = append(jobs, Job{Name: "a", Timestamp: 10, Success: true})
|
||||
jobs = append(jobs, Job{Name: "a", Timestamp: 20, Success: true})
|
||||
jobs2 := KeepOldestOnly(jobs)
|
||||
if len(jobs2) != 1 || jobs2[0].Timestamp != 20 {
|
||||
t.Error("functionality failed")
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestKeepSuccessOnly(t *testing.T) {
|
||||
t.Run("test empty list", func(t *testing.T) {
|
||||
var jobs []Job
|
||||
if len(KeepSuccessOnly(jobs)) != 0 {
|
||||
t.Error("empty list failed")
|
||||
}
|
||||
})
|
||||
t.Run("test functionality", func(t *testing.T) {
|
||||
var jobs []Job
|
||||
jobs = append(jobs, Job{Name: "a", Timestamp: 10, Success: true})
|
||||
jobs = append(jobs, Job{Name: "b", Timestamp: 20, Success: false})
|
||||
if len(KeepSuccessOnly(jobs)) != 1 || jobs[0].Name != "a" {
|
||||
t.Error("functionality failed")
|
||||
}
|
||||
})
|
||||
}
|
Loading…
Add table
Reference in a new issue