From 9ae125cea1b1ea242db9aded03d00b33985211d7 Mon Sep 17 00:00:00 2001 From: Egor Kovetskiy Date: Wed, 10 Apr 2019 09:44:52 +0300 Subject: [PATCH] fix go vet errors, tests skeleton --- .gitignore | 2 ++ .gitmodules | 3 +++ api.go | 13 ++++++---- main.go | 31 +++++++++++++----------- tests/run_tests | 30 +++++++++++++++++++++++ tests/setup.sh | 3 +++ tests/teardown.sh | 0 tests/testcases/print-version.test.sh | 1 + vendor/.gitignore | 6 +++++ vendor/github.com/reconquest/import.bash | 1 + 10 files changed, 71 insertions(+), 19 deletions(-) create mode 100644 .gitmodules create mode 100755 tests/run_tests create mode 100644 tests/setup.sh create mode 100644 tests/teardown.sh create mode 100644 tests/testcases/print-version.test.sh create mode 100644 vendor/.gitignore create mode 160000 vendor/github.com/reconquest/import.bash diff --git a/.gitignore b/.gitignore index 13c9cd3..bcd3b9d 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ /mark +.last-testcase +.cover diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..89308aa --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "vendor/github.com/reconquest/import.bash"] + path = vendor/github.com/reconquest/import.bash + url = https://github.com/reconquest/import.bash diff --git a/api.go b/api.go index 8709074..0840b24 100644 --- a/api.go +++ b/api.go @@ -5,6 +5,7 @@ import ( "io/ioutil" "github.com/bndr/gopencils" + "github.com/reconquest/karma-go" ) type RestrictionOperation string @@ -16,7 +17,7 @@ const ( type Restriction struct { User string `json:"userName"` - Group string `json:"groupName",omitempty` + Group string `json:"groupName,omitempty"` } type API struct { @@ -28,7 +29,10 @@ type API struct { } func NewAPI(baseURL string, username string, password string) *API { - auth := &gopencils.BasicAuth{username, password} + auth := &gopencils.BasicAuth{ + Username: username, + Password: password, + } return &API{ rest: gopencils.Api(baseURL+"/rest/api", auth), @@ -43,10 +47,9 @@ func NewAPI(baseURL string, username string, password string) *API { func (api *API) findRootPage(space string) (*PageInfo, error) { page, err := api.findPage(space, ``) if err != nil { - return nil, fmt.Errorf( - `can't obtain first page from space '%s': %s`, + return nil, karma.Format(err, + `can't obtain first page from space '%s'`, space, - err, ) } diff --git a/main.go b/main.go index 8c93333..c049d68 100644 --- a/main.go +++ b/main.go @@ -12,7 +12,7 @@ import ( "github.com/kovetskiy/godocs" "github.com/kovetskiy/lorg" "github.com/reconquest/colorgful" - "github.com/reconquest/ser-go" + "github.com/reconquest/karma-go" "github.com/russross/blackfriday" "github.com/zazab/zhash" ) @@ -107,6 +107,7 @@ type PageInfo struct { var ( logger = lorg.NewLog() + exit = os.Exit ) func initLogger(trace bool) { @@ -287,9 +288,9 @@ func compileMarkdown(markdown []byte) []byte { func resolvePage(api *API, meta *Meta) (*PageInfo, error) { page, err := api.findPage(meta.Space, meta.Title) if err != nil { - return nil, ser.Errorf( + return nil, karma.Format( err, - "error during finding page '%s': %s", + "error during finding page '%s'", meta.Title, ) } @@ -331,9 +332,9 @@ func resolvePage(api *API, meta *Meta) (*PageInfo, error) { meta.Parents, ) if err != nil { - return nil, ser.Errorf( + return nil, karma.Format( err, - "can't create ancestry tree: %s; error: %s", + "can't create ancestry tree: %s", strings.Join(meta.Parents, ` > `), ) } @@ -354,9 +355,9 @@ func resolvePage(api *API, meta *Meta) (*PageInfo, error) { if page == nil { page, err := api.createPage(meta.Space, parent, meta.Title, ``) if err != nil { - return nil, ser.Errorf( + return nil, karma.Format( err, - "can't create page '%s': %s", + "can't create page '%s'", meta.Title, ) } @@ -379,9 +380,9 @@ func ensureAncestry( for i, title := range ancestry { page, err := api.findPage(space, title) if err != nil { - return nil, ser.Errorf( + return nil, karma.Format( err, - `error during finding parent page with title '%s': %s`, + "error during finding parent page with title '%s'", title, ) } @@ -401,9 +402,10 @@ func ensureAncestry( } else { page, err := api.findRootPage(space) if err != nil { - return nil, ser.Errorf( + return nil, karma.Format( err, - "can't find root page for space '%s': %s", space, + "can't find root page for space '%s'", + space, ) } @@ -423,9 +425,9 @@ func ensureAncestry( for _, title := range rest { page, err := api.createPage(space, parent, title, ``) if err != nil { - return nil, ser.Errorf( + return nil, karma.Format( err, - `error during creating parent page with title '%s': %s`, + "error during creating parent page with title '%s'", title, ) } @@ -486,9 +488,10 @@ func getConfig(path string) (zhash.Hash, error) { return zhash.NewHash(), err } - return zhash.NewHash(), ser.Errorf( + return zhash.NewHash(), karma.Format( err, "can't decode toml file: %s", + path, ) } diff --git a/tests/run_tests b/tests/run_tests new file mode 100755 index 0000000..94d96ed --- /dev/null +++ b/tests/run_tests @@ -0,0 +1,30 @@ +#!/bin/bash + +set -euo pipefail + +cd "$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")" +source ../vendor/github.com/reconquest/import.bash/import.bash + +import:use "github.com/reconquest/test-runner.bash" +import:use "github.com/reconquest/go-test.bash" + +:cleanup() { + : +} + +:main() { + trap :cleanup EXIT + + cd .. + + go-test:set-output-dir "$(pwd)" + go-test:build mark + + test-runner:set-local-setup tests/setup.sh + test-runner:set-local-teardown tests/teardown.sh + test-runner:set-testcases-dir tests/testcases + + test-runner:run "${@}" +} + +:main "${@}" diff --git a/tests/setup.sh b/tests/setup.sh new file mode 100644 index 0000000..a9afe89 --- /dev/null +++ b/tests/setup.sh @@ -0,0 +1,3 @@ +:run() { + go-test:run mark +} diff --git a/tests/teardown.sh b/tests/teardown.sh new file mode 100644 index 0000000..e69de29 diff --git a/tests/testcases/print-version.test.sh b/tests/testcases/print-version.test.sh new file mode 100644 index 0000000..e9fd8ba --- /dev/null +++ b/tests/testcases/print-version.test.sh @@ -0,0 +1 @@ +tests:ensure :run -v diff --git a/vendor/.gitignore b/vendor/.gitignore new file mode 100644 index 0000000..c3f1e41 --- /dev/null +++ b/vendor/.gitignore @@ -0,0 +1,6 @@ +/github.com/reconquest/types.bash +/github.com/reconquest/opts.bash +/github.com/reconquest/test-runner.bash +/github.com/reconquest/tests.sh +/github.com/reconquest/coproc.bash +/github.com/reconquest/go-test.bash diff --git a/vendor/github.com/reconquest/import.bash b/vendor/github.com/reconquest/import.bash new file mode 160000 index 0000000..b8d543e --- /dev/null +++ b/vendor/github.com/reconquest/import.bash @@ -0,0 +1 @@ +Subproject commit b8d543eadad8fc21b80e512aff83f2c7502e9ef0