dotfiles

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | Submodules | README | LICENSE

commit 4d075a8653027dbae0df35159bf9e6f795d5cf7b (tree)
parent 04184e6b608841395c05a5c3120f20d1105921ff
Author: Motiejus Jakštys <desired.mta@gmail.com>
Date:   Thu,  4 Jun 2020 19:43:03 +0300

tests

Diffstat:
Msrc/joplin2site/go.mod | 5++++-
Msrc/joplin2site/go.sum | 12++++++++++++
Msrc/joplin2site/internal/cli/cli.go | 5++---
Asrc/joplin2site/internal/cli/cli_test.go | 44++++++++++++++++++++++++++++++++++++++++++++
Msrc/joplin2site/main.go | 1+
5 files changed, 63 insertions(+), 4 deletions(-)

diff --git a/src/joplin2site/go.mod b/src/joplin2site/go.mod @@ -2,4 +2,7 @@ module github.com/motiejus/dotfiles/joplin2site go 1.13 -require github.com/jessevdk/go-flags v1.4.0 +require ( + github.com/jessevdk/go-flags v1.4.0 + github.com/stretchr/testify v1.6.0 +) diff --git a/src/joplin2site/go.sum b/src/joplin2site/go.sum @@ -1,2 +1,14 @@ +github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/jessevdk/go-flags v1.4.0 h1:4IU2WS7AumrZ/40jfhf4QVDMsQwqA7VEHozFRrGARJA= github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.6.0 h1:jlIyCplCJFULU/01vCkhKuTyc3OorI3bJFuw6obfgho= +github.com/stretchr/testify v1.6.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/src/joplin2site/internal/cli/cli.go b/src/joplin2site/internal/cli/cli.go @@ -14,6 +14,7 @@ type flags struct { } type App struct { + Args []string Stdin io.Reader Stdout io.Writer Stderr io.Writer @@ -21,14 +22,12 @@ type App struct { func (a *App) Run() error { var opts flags - args, err := goflags.Parse(&opts) + args, err := goflags.ParseArgs(&opts, a.Args) if err != nil { return err } if len(args) != 0 { return fmt.Errorf("Got unexpected arguments: %q", args) } - fmt.Printf("opts: %+v\n", opts) - return nil } diff --git a/src/joplin2site/internal/cli/cli_test.go b/src/joplin2site/internal/cli/cli_test.go @@ -0,0 +1,44 @@ +package cli + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestFlags(t *testing.T) { + tests := []struct { + name string + args []string + wantErr string + }{ + { + name: "ok", + args: []string{"dir1"}, + }, + { + name: "missing arg1", + args: []string{}, + wantErr: "the required argument `Dir` was not provided", + }, + { + name: "unexpected arguments", + args: []string{"dir1", "bar1"}, + wantErr: `Got unexpected arguments: ["bar1"]`, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + a := &App{ + Args: tt.args, + } + err := a.Run() + if tt.wantErr != "" { + assert.EqualError(t, err, tt.wantErr) + } else { + assert.NoError(t, err) + } + }) + } +} diff --git a/src/joplin2site/main.go b/src/joplin2site/main.go @@ -9,6 +9,7 @@ import ( func main() { a := &cli.App{ + Args: os.Args[1:], Stdin: os.Stdin, Stdout: os.Stdout, Stderr: os.Stderr,