Skip to content

Commit

Permalink
Import errs package
Browse files Browse the repository at this point in the history
  • Loading branch information
spiegel-im-spiegel committed Oct 29, 2019
1 parent 07781e7 commit c7a9744
Show file tree
Hide file tree
Showing 15 changed files with 94 additions and 268 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,3 @@
# Other folders and files
vendor/
dist/
go.sum
12 changes: 6 additions & 6 deletions cli/mklink/facade/facade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func TestStyleMarkdown(t *testing.T) {
outBuf := new(bytes.Buffer)
outErrBuf := new(bytes.Buffer)
ui := rwi.New(rwi.WithWriter(outBuf), rwi.WithErrorWriter(outErrBuf))
args := []string{"http://text.baldanders.info"}
args := []string{"https://text.baldanders.info"}

exit := Execute(ui, args)
if exit != exitcode.Normal {
Expand All @@ -37,7 +37,7 @@ func TestStyleMarkdown(t *testing.T) {
t.Errorf("Execute(markdown) = \"%v\", want \"%v\".", str, "")
}
str = outBuf.String()
res := "[text.Baldanders.info](http://text.baldanders.info)\n"
res := "[text.Baldanders.info](https://text.baldanders.info)\n"
if str != res {
t.Errorf("Execute(markdown) = \"%v\", want \"%v\".", str, res)
}
Expand All @@ -59,7 +59,7 @@ func TestStyleWiki(t *testing.T) {
outBuf := new(bytes.Buffer)
outErrBuf := new(bytes.Buffer)
ui := rwi.New(rwi.WithWriter(outBuf), rwi.WithErrorWriter(outErrBuf))
args := []string{"-s", "wiki", "http://text.baldanders.info"}
args := []string{"-s", "wiki", "https://text.baldanders.info"}

exit := Execute(ui, args)
if exit != exitcode.Normal {
Expand All @@ -70,14 +70,14 @@ func TestStyleWiki(t *testing.T) {
t.Errorf("Execute(wiki) = \"%v\", want \"%v\".", str, "")
}
str = outBuf.String()
res := "[http://text.baldanders.info text.Baldanders.info]\n"
res := "[https://text.baldanders.info text.Baldanders.info]\n"
if str != res {
t.Errorf("Execute(wiki) = \"%v\", want \"%v\".", str, res)
}
}

func TestPipe(t *testing.T) {
inData := bytes.NewBufferString("http://text.baldanders.info")
inData := bytes.NewBufferString("https://text.baldanders.info")
outBuf := new(bytes.Buffer)
outErrBuf := new(bytes.Buffer)
ui := rwi.New(rwi.WithReader(inData), rwi.WithWriter(outBuf), rwi.WithErrorWriter(outErrBuf))
Expand All @@ -92,7 +92,7 @@ func TestPipe(t *testing.T) {
t.Errorf("Execute(pipe) = \"%v\", want \"%v\".", str, "")
}
str = outBuf.String()
res := "[text.Baldanders.info](http://text.baldanders.info)\n"
res := "[text.Baldanders.info](https://text.baldanders.info)\n"
if str != res {
t.Errorf("Execute(pipe) = \"%v\", want \"%v\".", str, res)
}
Expand Down
2 changes: 1 addition & 1 deletion cli/mklink/facade/interactive.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import (
"io"

"github.com/atotto/clipboard"
"github.com/spiegel-im-spiegel/errs"
"github.com/spiegel-im-spiegel/gocli/rwi"
"github.com/spiegel-im-spiegel/gprompt"
"github.com/spiegel-im-spiegel/mklink/cli/mklink/makelink"
"github.com/spiegel-im-spiegel/mklink/errs"
)

func interactiveMode(ui *rwi.RWI, cxt *makelink.Context) error {
Expand Down
4 changes: 2 additions & 2 deletions cli/mklink/makelink/makelink.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"fmt"
"io"

"github.com/spiegel-im-spiegel/errs"
"github.com/spiegel-im-spiegel/mklink"
"github.com/spiegel-im-spiegel/mklink/errs"
)

//Context class is context for making link
Expand All @@ -23,7 +23,7 @@ func New(s mklink.Style, log io.Writer) *Context {
//MakeLink is making link
func (c *Context) MakeLink(url string) (io.Reader, error) {
if c == nil {
return nil, errs.Wrap(errs.ErrNullPointer, "reference error")
return nil, errs.Wrap(mklink.ErrNullPointer, "reference error")
}
lnk, err := mklink.New(url)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion errs/errs.go → errs.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package errs
package mklink

import "fmt"

Expand Down
30 changes: 0 additions & 30 deletions errs/cause.go

This file was deleted.

136 changes: 0 additions & 136 deletions errs/errs_test.go

This file was deleted.

67 changes: 0 additions & 67 deletions errs/wrapper.go

This file was deleted.

23 changes: 13 additions & 10 deletions errs/cause_test.go → errs_test.go
Original file line number Diff line number Diff line change
@@ -1,24 +1,27 @@
package errs
package mklink

import (
"fmt"
"testing"
)

func TestCause(t *testing.T) {
func TestNumError(t *testing.T) {
testCases := []struct {
err error
cause error
err error
str string
}{
{err: nil, cause: nil},
{err: ErrNoImplement, cause: ErrNoImplement},
{err: Wrap(ErrNoImplement, "wrapping error"), cause: ErrNoImplement},
{err: Num(0), str: "unknown error (0)"},
{err: ErrNoImplement, str: "This style is not implementation"},
{err: ErrNullPointer, str: "Null reference instance"},
{err: Num(3), str: "unknown error (3)"},
}

for _, tc := range testCases {
res := Cause(tc.err)
if res != tc.cause {
t.Errorf("Cause in \"%v\" == \"%v\", want \"%v\"", tc.err, res, tc.cause)
errStr := tc.err.Error()
if errStr != tc.str {
t.Errorf("\"%v\" != \"%v\"", errStr, tc.str)
}
fmt.Printf("Info(TestNumError): %+v\n", tc.err)
}
}

Expand Down
11 changes: 5 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
module github.com/spiegel-im-spiegel/mklink

go 1.12
go 1.13

require (
github.com/PuerkitoBio/goquery v1.5.0
github.com/atotto/clipboard v0.1.2
github.com/mattn/go-encoding v0.0.2
github.com/spf13/cobra v0.0.3
github.com/spf13/pflag v1.0.3 // indirect
github.com/spiegel-im-spiegel/gocli v0.9.5
github.com/spf13/cobra v0.0.5
github.com/spiegel-im-spiegel/errs v0.3.2
github.com/spiegel-im-spiegel/gocli v0.10.1
github.com/spiegel-im-spiegel/gprompt v0.9.5
golang.org/x/net v0.0.0-20190503192946-f4e77d36d62c
golang.org/x/xerrors v0.0.0-20190410155217-1f06c39b4373
golang.org/x/net v0.0.0-20191028085509-fe3aa8a45271
)
Loading

0 comments on commit c7a9744

Please sign in to comment.