forked from gopasspw/gopass
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_test.go
38 lines (32 loc) · 866 Bytes
/
main_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
package main
import (
"bytes"
"context"
"flag"
"fmt"
"runtime"
"testing"
"github.com/blang/semver"
"github.com/gopasspw/gopass/pkg/ctxutil"
"github.com/stretchr/testify/assert"
"github.com/urfave/cli"
)
func TestGlobalFlags(t *testing.T) {
ctx := context.Background()
app := cli.NewApp()
fs := flag.NewFlagSet("default", flag.ContinueOnError)
sf := cli.BoolFlag{
Name: "yes",
Usage: "yes",
}
assert.NoError(t, sf.ApplyWithError(fs))
assert.NoError(t, fs.Parse([]string{"--yes"}))
c := cli.NewContext(app, fs, nil)
assert.Equal(t, true, ctxutil.IsAlwaysYes(withGlobalFlags(ctx, c)))
}
func TestVersionPrinter(t *testing.T) {
buf := &bytes.Buffer{}
vp := makeVersionPrinter(buf, semver.Version{Major: 1})
vp(nil)
assert.Equal(t, fmt.Sprintf("gopass 1.0.0 %s %s %s\n", runtime.Version(), runtime.GOOS, runtime.GOARCH), buf.String())
}