Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
29922dba51 |
@@ -23,7 +23,6 @@ tests for the extraction, verification, and atomic-publish paths.
|
|||||||
parsing) from `cmd/bsdaily` into `internal/cli`, with unit tests for the flag
|
parsing) from `cmd/bsdaily` into `internal/cli`, with unit tests for the flag
|
||||||
rules and the dates; `cmd/bsdaily/main.go` is now a single call into it
|
rules and the dates; `cmd/bsdaily/main.go` is now a single call into it
|
||||||
(https://git.eeqj.de/sneak/bsdaily/issues/8).
|
(https://git.eeqj.de/sneak/bsdaily/issues/8).
|
||||||
|
|
||||||
- 2026-10-06: A plain `docker build .` and a host `make` build stamp the git tag
|
- 2026-10-06: A plain `docker build .` and a host `make` build stamp the git tag
|
||||||
or short commit into the binary, which `bsdaily` logs on the first line of
|
or short commit into the binary, which `bsdaily` logs on the first line of
|
||||||
every run and prints with `--version`
|
every run and prints with `--version`
|
||||||
|
|||||||
+33
-15
@@ -54,14 +54,18 @@ func TestParseTargetDates(t *testing.T) {
|
|||||||
func TestParseTargetDatesErrors(t *testing.T) {
|
func TestParseTargetDatesErrors(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
// wantErr is how the error message starts: for a malformed date, the
|
const dateExclusive = "--date and --from/--to are mutually exclusive"
|
||||||
// date parser's own explanation follows it.
|
|
||||||
|
// wantErr is the whole error message. With startsWith set it is only how
|
||||||
|
// the message starts: for a malformed date, the date parser's own
|
||||||
|
// explanation follows it.
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
date string
|
date string
|
||||||
from string
|
from string
|
||||||
to string
|
to string
|
||||||
wantErr string
|
wantErr string
|
||||||
|
startsWith bool
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "from after to", from: "2026-03-02", to: "2026-03-01",
|
name: "from after to", from: "2026-03-02", to: "2026-03-01",
|
||||||
@@ -71,28 +75,36 @@ func TestParseTargetDatesErrors(t *testing.T) {
|
|||||||
{name: "to without from", to: "2026-04-02", wantErr: "--to requires --from"},
|
{name: "to without from", to: "2026-04-02", wantErr: "--to requires --from"},
|
||||||
{
|
{
|
||||||
name: "date with from", date: "2026-01-05", from: "2026-01-06",
|
name: "date with from", date: "2026-01-05", from: "2026-01-06",
|
||||||
wantErr: "--date and --from/--to are mutually exclusive",
|
wantErr: dateExclusive,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "date with to", date: "2026-01-13", to: "2026-01-14",
|
||||||
|
wantErr: dateExclusive,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "date with from and to", date: "2026-01-07",
|
name: "date with from and to", date: "2026-01-07",
|
||||||
from: "2026-01-08", to: "2026-01-09",
|
from: "2026-01-08", to: "2026-01-09",
|
||||||
wantErr: "--date and --from/--to are mutually exclusive",
|
wantErr: dateExclusive,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "malformed date", date: "27.06.2026",
|
name: "malformed date", date: "27.06.2026",
|
||||||
wantErr: `invalid --date "27.06.2026" (expected YYYY-MM-DD): `,
|
wantErr: `invalid --date "27.06.2026" (expected YYYY-MM-DD): `,
|
||||||
|
startsWith: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "date that does not exist", date: "2026-02-30",
|
name: "date that does not exist", date: "2026-02-30",
|
||||||
wantErr: `invalid --date "2026-02-30" (expected YYYY-MM-DD): `,
|
wantErr: `invalid --date "2026-02-30" (expected YYYY-MM-DD): `,
|
||||||
|
startsWith: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "malformed from", from: "2026-1-10", to: "2026-01-11",
|
name: "malformed from", from: "2026-1-10", to: "2026-01-11",
|
||||||
wantErr: `invalid --from "2026-1-10" (expected YYYY-MM-DD): `,
|
wantErr: `invalid --from "2026-1-10" (expected YYYY-MM-DD): `,
|
||||||
|
startsWith: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "malformed to", from: "2026-01-12", to: "tomorrow",
|
name: "malformed to", from: "2026-01-12", to: "tomorrow",
|
||||||
wantErr: `invalid --to "tomorrow" (expected YYYY-MM-DD): `,
|
wantErr: `invalid --to "tomorrow" (expected YYYY-MM-DD): `,
|
||||||
|
startsWith: true,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -101,8 +113,14 @@ func TestParseTargetDatesErrors(t *testing.T) {
|
|||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
_, err := cli.ParseTargetDates(tt.date, tt.from, tt.to)
|
_, err := cli.ParseTargetDates(tt.date, tt.from, tt.to)
|
||||||
if err == nil || !strings.HasPrefix(err.Error(), tt.wantErr) {
|
|
||||||
t.Errorf("error = %v, want one starting %q", err, tt.wantErr)
|
switch {
|
||||||
|
case err == nil:
|
||||||
|
t.Errorf("no error, want %q", tt.wantErr)
|
||||||
|
case tt.startsWith && !strings.HasPrefix(err.Error(), tt.wantErr):
|
||||||
|
t.Errorf("error = %q, want one starting %q", err, tt.wantErr)
|
||||||
|
case !tt.startsWith && err.Error() != tt.wantErr:
|
||||||
|
t.Errorf("error = %q, want %q", err, tt.wantErr)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user