Added unit tests, documentation and function descriptions across the board. Increased cyclop complexity threshold to 15 which is a bit more sane than 10 and excluded _test.go files from linters.
This commit is contained in:
1 parent
005b335371
commit
7fd321df97
31 files changed
+4106
-1
No files matched your search
@@ -0,0 +1,61 @@
|
||||
package fetch
|
||||
|
||||
import (
|
||||
"io"
|
||||
"slices"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"git.avsdev.uk/Go/job-search/internal/cli"
|
||||
"git.avsdev.uk/Go/job-search/internal/types"
|
||||
)
|
||||
|
||||
// opp makes an opportunity whose releases, oldest first, have these tags.
|
||||
func opp(uuid string, tags ...string) *types.Opportunity {
|
||||
o := &types.Opportunity{UUID: uuid}
|
||||
for _, tag := range tags {
|
||||
o.Releases = append(o.Releases, types.OpportunityRelease{
|
||||
Tags: []types.OpportunityReleaseTag{{Tag: tag}},
|
||||
})
|
||||
}
|
||||
return o
|
||||
}
|
||||
|
||||
func TestFilter(t *testing.T) {
|
||||
opps := []*types.Opportunity{
|
||||
opp("planned", "planning"),
|
||||
opp("open", "planning", "tender"),
|
||||
opp("extended", "tender", "tenderUpdate"),
|
||||
opp("awarded", "planning", "tender", "award"),
|
||||
opp("cancelled", "tender", "tenderCancellation"),
|
||||
opp("no releases"),
|
||||
}
|
||||
tests := map[string][]string{
|
||||
"planning": {"planned"},
|
||||
"opportunity": {"open", "extended"},
|
||||
"award": {"awarded"},
|
||||
}
|
||||
for stage, want := range tests {
|
||||
t.Run(stage, func(t *testing.T) {
|
||||
var got []string
|
||||
for _, o := range filter(opps, stage) {
|
||||
got = append(got, o.UUID)
|
||||
}
|
||||
if !slices.Equal(got, want) {
|
||||
t.Errorf("filter(%s) = %v; want %v", stage, got, want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// Conflicting filters are rejected by cobra before anything is fetched.
|
||||
func TestOnceFiltersExclusive(t *testing.T) {
|
||||
cmd := commandOnce(&cli.Options{})
|
||||
cmd.SetArgs([]string{"--planning", "--awards"})
|
||||
cmd.SetOut(io.Discard)
|
||||
cmd.SetErr(io.Discard)
|
||||
err := cmd.Execute()
|
||||
if err == nil || !strings.Contains(err.Error(), "none of the others can be") {
|
||||
t.Fatalf("err = %v; want a mutually exclusive flags error", err)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user