-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain_internal_test.go
66 lines (61 loc) · 1.49 KB
/
main_internal_test.go
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
// Copyright (c) 2020 Hervé Gouchet. All rights reserved.
// Use of this source code is governed by the MIT License
// that can be found in the LICENSE file.
package main
import (
"context"
"errors"
"strings"
"testing"
"github.com/matryer/is"
errup "github.com/rvflash/goup/internal/errors"
"github.com/rvflash/goup/internal/log"
"github.com/rvflash/goup/pkg/goup"
)
func TestPatterns(t *testing.T) {
t.Parallel()
var (
are = is.New(t)
dt = map[string]struct {
in []string
out string
}{
"Default": {},
"Ok": {in: []string{"a", "b", "", "d", " e "}, out: "a,b,d,e"},
}
)
for name, ts := range dt {
tt := ts
t.Run(name, func(t *testing.T) {
t.Parallel()
are.Equal(tt.out, patterns(tt.in...)) // mismatch result
})
}
}
func TestRun(t *testing.T) {
t.Parallel()
var (
are = is.New(t)
stderr = log.New(new(strings.Builder), false)
dt = map[string]struct {
ctx context.Context
cnf goup.Config
args []string
stderr log.Printer
err error
}{
"default": {err: errup.ErrMissing},
"no context": {stderr: stderr, err: errup.ErrMod},
"context only": {ctx: context.Background(), stderr: stderr, err: errup.ErrMod},
"ok": {ctx: context.Background(), cnf: goup.Config{PrintVersion: true}, stderr: stderr},
}
)
for name, ts := range dt {
tt := ts
t.Run(name, func(t *testing.T) {
t.Parallel()
err := run(tt.ctx, tt.cnf, tt.args, tt.stderr)
are.True(errors.Is(err, tt.err)) // mismatch error
})
}
}