Commit f035125d authored by Ma_124's avatar Ma_124

improved coverage

parent eb3aa1c7
Pipeline #46449981 passed with stages
in 2 minutes and 9 seconds
......@@ -74,6 +74,22 @@ func CompileFile(inpPath string, out io.Writer, inFF *InputFileFormat, outFF *Ou
Compile(f, int(fi.Size()), out, inFF, outFF, apis)
}
func NewCtx(apis *ApisCfg) *Ctx {
return &Ctx{
InFFCtx: make(map[string]interface{}),
OutFFCtx: make(map[string]interface{}),
ApisCfg: apis,
}
}
func NewDebugReqsApisCfg() *ApisCfg {
return &ApisCfg{&ApiCfg{"", 6000}}
}
func NewDebugCtx() *Ctx {
return NewCtx(NewDebugReqsApisCfg())
}
// Parses the file conforming to inFF and writes the output of outFF to out.
// The size argument is used to provide a progressbar.
// The apis config is forwarded to FetchMeta.
......@@ -83,11 +99,7 @@ func Compile(in io.Reader, size int, out io.Writer, inFF *InputFileFormat, outFF
offset := 0
ctx := &Ctx{
InFFCtx: make(map[string]interface{}),
OutFFCtx: make(map[string]interface{}),
ApisCfg: apis,
}
ctx := NewCtx(apis)
if outFF.Start != nil {
outFF.Start(out, ctx)
......
......@@ -8,6 +8,7 @@ import (
"net/http/httptest"
"strings"
"testing"
"github.com/stretchr/testify/assert"
)
type testDefaultClientHandler struct{}
......@@ -28,6 +29,9 @@ func (testDefaultClientHandler) ServeHTTP(resp http.ResponseWriter, req *http.Re
resp.WriteHeader(200)
resp.Write([]byte(ghApiRepoResp))
}
} else if len(path) == 3 && path[1] == "example" && path[2] == "invjson" {
resp.WriteHeader(200)
resp.Write([]byte(`{ "message": "`))
} else {
resp.WriteHeader(200)
resp.Write([]byte(`{ "message": "unknown repo" }`))
......@@ -85,6 +89,7 @@ func TestFetchMeta(t *testing.T) {
{"https://example.com", "na"},
{"http://example.com", "na"},
}
for i, test := range tests {
m := FetchMeta(test.URL, &Ctx{ApisCfg: &ApisCfg{&ApiCfg{"TOK", 6000}}})
if test.Provider == "gh" {
......@@ -102,3 +107,16 @@ func TestFetchMeta(t *testing.T) {
}
}
}
func TestFetchMeta_InvalidJson(t *testing.T) {
defer func() {
r := recover()
if _, ok := r.(error); ok {
assert.Equal(t, "unexpected end of JSON input", r.(error).Error())
} else {
t.Fatal("panic error value has wrong type")
}
}()
FetchMeta("https://github.com/example/invjson", NewDebugCtx())
}
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