mirror of
https://github.com/kovetskiy/mark.git
synced 2025-06-06 14:12:39 +08:00
fix go vet errors, tests skeleton
This commit is contained in:
parent
e27dd44bfa
commit
9ae125cea1
2
.gitignore
vendored
2
.gitignore
vendored
@ -1 +1,3 @@
|
|||||||
/mark
|
/mark
|
||||||
|
.last-testcase
|
||||||
|
.cover
|
||||||
|
3
.gitmodules
vendored
Normal file
3
.gitmodules
vendored
Normal file
@ -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
|
13
api.go
13
api.go
@ -5,6 +5,7 @@ import (
|
|||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
|
||||||
"github.com/bndr/gopencils"
|
"github.com/bndr/gopencils"
|
||||||
|
"github.com/reconquest/karma-go"
|
||||||
)
|
)
|
||||||
|
|
||||||
type RestrictionOperation string
|
type RestrictionOperation string
|
||||||
@ -16,7 +17,7 @@ const (
|
|||||||
|
|
||||||
type Restriction struct {
|
type Restriction struct {
|
||||||
User string `json:"userName"`
|
User string `json:"userName"`
|
||||||
Group string `json:"groupName",omitempty`
|
Group string `json:"groupName,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type API struct {
|
type API struct {
|
||||||
@ -28,7 +29,10 @@ type API struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewAPI(baseURL string, username string, password string) *API {
|
func NewAPI(baseURL string, username string, password string) *API {
|
||||||
auth := &gopencils.BasicAuth{username, password}
|
auth := &gopencils.BasicAuth{
|
||||||
|
Username: username,
|
||||||
|
Password: password,
|
||||||
|
}
|
||||||
|
|
||||||
return &API{
|
return &API{
|
||||||
rest: gopencils.Api(baseURL+"/rest/api", auth),
|
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) {
|
func (api *API) findRootPage(space string) (*PageInfo, error) {
|
||||||
page, err := api.findPage(space, ``)
|
page, err := api.findPage(space, ``)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf(
|
return nil, karma.Format(err,
|
||||||
`can't obtain first page from space '%s': %s`,
|
`can't obtain first page from space '%s'`,
|
||||||
space,
|
space,
|
||||||
err,
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
31
main.go
31
main.go
@ -12,7 +12,7 @@ import (
|
|||||||
"github.com/kovetskiy/godocs"
|
"github.com/kovetskiy/godocs"
|
||||||
"github.com/kovetskiy/lorg"
|
"github.com/kovetskiy/lorg"
|
||||||
"github.com/reconquest/colorgful"
|
"github.com/reconquest/colorgful"
|
||||||
"github.com/reconquest/ser-go"
|
"github.com/reconquest/karma-go"
|
||||||
"github.com/russross/blackfriday"
|
"github.com/russross/blackfriday"
|
||||||
"github.com/zazab/zhash"
|
"github.com/zazab/zhash"
|
||||||
)
|
)
|
||||||
@ -107,6 +107,7 @@ type PageInfo struct {
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
logger = lorg.NewLog()
|
logger = lorg.NewLog()
|
||||||
|
exit = os.Exit
|
||||||
)
|
)
|
||||||
|
|
||||||
func initLogger(trace bool) {
|
func initLogger(trace bool) {
|
||||||
@ -287,9 +288,9 @@ func compileMarkdown(markdown []byte) []byte {
|
|||||||
func resolvePage(api *API, meta *Meta) (*PageInfo, error) {
|
func resolvePage(api *API, meta *Meta) (*PageInfo, error) {
|
||||||
page, err := api.findPage(meta.Space, meta.Title)
|
page, err := api.findPage(meta.Space, meta.Title)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, ser.Errorf(
|
return nil, karma.Format(
|
||||||
err,
|
err,
|
||||||
"error during finding page '%s': %s",
|
"error during finding page '%s'",
|
||||||
meta.Title,
|
meta.Title,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -331,9 +332,9 @@ func resolvePage(api *API, meta *Meta) (*PageInfo, error) {
|
|||||||
meta.Parents,
|
meta.Parents,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, ser.Errorf(
|
return nil, karma.Format(
|
||||||
err,
|
err,
|
||||||
"can't create ancestry tree: %s; error: %s",
|
"can't create ancestry tree: %s",
|
||||||
strings.Join(meta.Parents, ` > `),
|
strings.Join(meta.Parents, ` > `),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -354,9 +355,9 @@ func resolvePage(api *API, meta *Meta) (*PageInfo, error) {
|
|||||||
if page == nil {
|
if page == nil {
|
||||||
page, err := api.createPage(meta.Space, parent, meta.Title, ``)
|
page, err := api.createPage(meta.Space, parent, meta.Title, ``)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, ser.Errorf(
|
return nil, karma.Format(
|
||||||
err,
|
err,
|
||||||
"can't create page '%s': %s",
|
"can't create page '%s'",
|
||||||
meta.Title,
|
meta.Title,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -379,9 +380,9 @@ func ensureAncestry(
|
|||||||
for i, title := range ancestry {
|
for i, title := range ancestry {
|
||||||
page, err := api.findPage(space, title)
|
page, err := api.findPage(space, title)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, ser.Errorf(
|
return nil, karma.Format(
|
||||||
err,
|
err,
|
||||||
`error during finding parent page with title '%s': %s`,
|
"error during finding parent page with title '%s'",
|
||||||
title,
|
title,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -401,9 +402,10 @@ func ensureAncestry(
|
|||||||
} else {
|
} else {
|
||||||
page, err := api.findRootPage(space)
|
page, err := api.findRootPage(space)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, ser.Errorf(
|
return nil, karma.Format(
|
||||||
err,
|
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 {
|
for _, title := range rest {
|
||||||
page, err := api.createPage(space, parent, title, ``)
|
page, err := api.createPage(space, parent, title, ``)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, ser.Errorf(
|
return nil, karma.Format(
|
||||||
err,
|
err,
|
||||||
`error during creating parent page with title '%s': %s`,
|
"error during creating parent page with title '%s'",
|
||||||
title,
|
title,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -486,9 +488,10 @@ func getConfig(path string) (zhash.Hash, error) {
|
|||||||
return zhash.NewHash(), err
|
return zhash.NewHash(), err
|
||||||
}
|
}
|
||||||
|
|
||||||
return zhash.NewHash(), ser.Errorf(
|
return zhash.NewHash(), karma.Format(
|
||||||
err,
|
err,
|
||||||
"can't decode toml file: %s",
|
"can't decode toml file: %s",
|
||||||
|
path,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
30
tests/run_tests
Executable file
30
tests/run_tests
Executable file
@ -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 "${@}"
|
3
tests/setup.sh
Normal file
3
tests/setup.sh
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
:run() {
|
||||||
|
go-test:run mark
|
||||||
|
}
|
0
tests/teardown.sh
Normal file
0
tests/teardown.sh
Normal file
1
tests/testcases/print-version.test.sh
Normal file
1
tests/testcases/print-version.test.sh
Normal file
@ -0,0 +1 @@
|
|||||||
|
tests:ensure :run -v
|
6
vendor/.gitignore
vendored
Normal file
6
vendor/.gitignore
vendored
Normal file
@ -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
|
1
vendor/github.com/reconquest/import.bash
generated
vendored
Submodule
1
vendor/github.com/reconquest/import.bash
generated
vendored
Submodule
@ -0,0 +1 @@
|
|||||||
|
Subproject commit b8d543eadad8fc21b80e512aff83f2c7502e9ef0
|
Loading…
x
Reference in New Issue
Block a user