boulder/cmd/boulder-janitor/janitor_test.go

97 lines
2.0 KiB
Go

package main
import (
"encoding/json"
"testing"
"github.com/jmhodges/clock"
blog "github.com/letsencrypt/boulder/log"
"github.com/letsencrypt/boulder/test"
)
func TestNewJobs(t *testing.T) {
onlyCertStatusConfig := `{
"janitor": {
"certificates": {
"enabled": false
},
"certificateStatus": {
"enabled": true,
"gracePeriod": "2184h",
"batchSize": 1,
"parallelism": 1
},
"certificatesPerName": {
"enabled": false
}
}
}`
allConfig := `{
"janitor": {
"certificates": {
"enabled": true,
"gracePeriod": "2184h",
"batchSize": 1,
"parallelism": 1
},
"certificateStatus": {
"enabled": true,
"gracePeriod": "2184h",
"batchSize": 1,
"parallelism": 1
},
"certificatesPerName": {
"enabled": true,
"gracePeriod": "2184h",
"batchSize": 1,
"parallelism": 1
}
}
}`
testCases := []struct {
name string
config string
expectedTableJobs []string
expectedError error
}{
{
name: "no jobs enabled",
config: `{}`,
expectedError: errNoJobsConfigured,
},
{
name: "only certificate status enabled",
config: onlyCertStatusConfig,
expectedTableJobs: []string{"certificateStatus"},
},
{
name: "only certificates enabled",
config: allConfig,
expectedTableJobs: []string{"certificates", "certificateStatus", "certificatesPerName"},
},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
var config Config
err := json.Unmarshal([]byte(tc.config), &config)
test.AssertNotError(t, err, "error unmarshaling tc Config")
jobs, err := newJobs(nil, blog.UseMock(), clock.NewFake(), config)
test.AssertEquals(t, err, tc.expectedError)
var tableMap map[string]bool
if err != nil {
for _, j := range jobs {
tableMap[j.table] = true
}
for _, expected := range tc.expectedTableJobs {
if _, present := tableMap[expected]; !present {
t.Errorf("expected batchedDBJob with table %q to be present", expected)
}
}
}
})
}
}