aboutsummaryrefslogtreecommitdiff
path: root/pkg/job/utils_test.go
blob: 250ae2ca23627310d776f9fc74656a513ce85432 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package job

import (
	"reflect"
	"testing"
)

func TestKeepOldestOnly(t *testing.T) {
	emptyList := []Job{}
	oneJob := []Job{{Name: "a", Timestamp: 10, Success: true}}
	twoJobs := []Job{
		{Name: "a", Timestamp: 5, Success: true},
		{Name: "a", Timestamp: 10, Success: true},
	}
	threeJobs := []Job{
		{Name: "a", Timestamp: 5, Success: true},
		{Name: "a", Timestamp: 10, Success: true},
		{Name: "a", Timestamp: 8, Success: false},
	}
	type args struct {
		jobs []Job
	}
	tests := []struct {
		name string
		args args
		want []Job
	}{
		{"empty list", args{emptyList}, nil},
		{"one job", args{oneJob}, oneJob},
		{"two jobs", args{twoJobs}, oneJob},
		{"three jobs", args{threeJobs}, oneJob},
	}
	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			if got := KeepOldestOnly(tt.args.jobs); !reflect.DeepEqual(got, tt.want) {
				t.Errorf("KeepOldestOnly() = %v, want %v", got, tt.want)
			}
		})
	}
}

func TestKeepSuccessOnly(t *testing.T) {
	emptyList := []Job{}
	oneJob := []Job{{Name: "a", Timestamp: 10, Success: true}}
	twoJobs := []Job{
		{Name: "a", Timestamp: 10, Success: true},
		{Name: "a", Timestamp: 5, Success: false},
	}
	type args struct {
		jobs []Job
	}
	tests := []struct {
		name       string
		args       args
		wantResult []Job
	}{
		{"empty list", args{emptyList}, emptyList},
		{"one job", args{oneJob}, oneJob},
		{"two jobs", args{twoJobs}, oneJob},
	}
	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			if gotResult := KeepSuccessOnly(tt.args.jobs); !reflect.DeepEqual(gotResult, tt.wantResult) {
				t.Errorf("KeepSuccessOnly() = %v, want %v", gotResult, tt.wantResult)
			}
		})
	}
}