Commit eb3aa1c7 authored by Ma_124's avatar Ma_124

improved coverage

parent c30be3a7
Pipeline #46434084 passed with stages
in 2 minutes and 41 seconds
package awesomefw
import (
"errors"
"github.com/stretchr/testify/assert"
"io/ioutil"
"strings"
"testing"
)
......@@ -22,6 +24,22 @@ awesome-sysadmin https://github.com/kahun/awesome-sysadmin Backups, configuratio
"For contributing, [open an issue](https://github.com/emijrp/awesome-awesome/issues) and/or a [pull request](https://github.com/emijrp/awesome-awesome/pulls). Above there are some ideas for missing lists, be bold!
`[1:]
func TestCompile_TabSepTabSepInvalid(t *testing.T) {
defer func() {
r := recover()
assert.Equal(t, "invalid line: \"ghi\"", r)
}()
in := `
"Abc
d e f
ghi
`[1:]
Compile(strings.NewReader(in), len(in), &strings.Builder{}, IFFTabSep, OFFTabSep, nil)
}
func TestCompile_MarkdownTabSep(t *testing.T) {
out := &strings.Builder{}
in := `
......@@ -43,3 +61,49 @@ For contributing, [open an issue](https://github.com/emijrp/awesome-awesome/issu
t.Log(assert.Equal(t, awesomeAwesomeShortOut, out.String()))
}
func TestCompileFile_TmpFile(t *testing.T) {
f, err := ioutil.TempFile("", "awesome-framework-test-*.txt")
if err != nil {
panic(err)
}
defer f.Close()
f.Write([]byte(awesomeAwesomeShortOut[:len(awesomeAwesomeShortOut)-1]))
f.Close()
buf := &strings.Builder{}
CompileFile(f.Name(), buf, IFFTabSep, OFFTabSep, &ApisCfg{&ApiCfg{}})
assert.Equal(t, buf.String(), awesomeAwesomeShortOut)
}
func TestCompileFile_UnknownFile(t *testing.T) {
defer func() {
r := recover()
if _, ok := r.(error); ok {
assert.Equal(t, r.(error).Error(), "stat /unknown: no such file or directory")
} else {
t.Fail()
}
}()
CompileFile("/unknown", nil, IFFTabSep, OFFTabSep, nil)
}
type testCompileFileReadErr struct{}
func (testCompileFileReadErr) Read(p []byte) (n int, err error) {
return 0, errors.New("error by mocked reader")
}
func TestCompileFile_ReadErr(t *testing.T) {
defer func() {
r := recover()
assert.Equal(t, r, errors.New("error by mocked reader"))
}()
Compile(&testCompileFileReadErr{}, 0, &strings.Builder{}, IFFTabSep, OFFTabSep, nil)
}
......@@ -2,7 +2,6 @@ package awesomefw
import (
"io"
"regexp"
)
/* TODO https://gitlab.com/Ma_124/awesome-go/blob/master/repo_test.go
......@@ -25,6 +24,7 @@ func testAlpha(_ io.Writer, name, _, _ string, ctx *Ctx) {
ctx.OutFFCtx["test-alpha-last"] = name
}
/*
// Panics if there is an invalid URL. Nothing is written to out.
// NOTE: Be careful! This isn't yet tested and no algorithm is perfect at this time.
//
......@@ -69,3 +69,4 @@ func testURL(_ io.Writer, _, url, _ string, ctx *Ctx) {
panic("invalid url: " + url)
}
}
*/
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment