Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add go report badge #5

Merged
merged 1 commit into from
Feb 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

[![Build Status](https://travis-ci.com/inabyte/embed.svg?branch=master)](https://travis-ci.com/inabyte/embed)
[![Coverage Status](https://coveralls.io/repos/github/inabyte/embed/badge.svg?branch=master)](https://coveralls.io/github/inabyte/embed?branch=master)
[![Go Report Card](https://goreportcard.com/badge/github.com/inabyte/embed)](https://goreportcard.com/report/github.com/inabyte/embed)
![GitHub](https://img.shields.io/github/license/inabyte/embed)

Takes a list for file or folders (likely at `go generate` time) and
generates Go code that statically implements the a http.FileSystem.
Expand Down
2 changes: 1 addition & 1 deletion doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ generates Go code that statically implements the a http.FileSystem.

Features:

- Efficient generated code without unneccessary overhead.
- Efficient generated code without unnecessary overhead.

- Minimizes html css and js files.

Expand Down
2 changes: 1 addition & 1 deletion embedded/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ type FileInfo interface {
os.FileInfo
Compressed() bool // Is this file compressed
Tag() string // Etag for the file contents
MimeType() string // file contens mimetype
MimeType() string // Mimetype for file contents
String() string // file contents as string
Bytes() []byte // file contents as byte array
}
Expand Down
61 changes: 38 additions & 23 deletions embedded/fs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,30 +183,13 @@ func TestFiles(t *testing.T) {
}

if !test.isDir {
testSeeking(t, test.file, file, test.expect)
testSeekStart(t, test.file, file, test.expect)
testSeekCurrent(t, test.file, file, test.expect)
testSeekEnd(t, test.file, file, test.expect)
testSeekBad(t, test.file, file, test.expect)
}

if _, err = file.Readdir(-1); err != nil {
if test.isDir {
t.Errorf("Got error Readdir for %s %v", test.file, err)
}
} else {
if !test.isDir {
t.Errorf("Did no get error Readdir for %s", test.file)
} else {
if _, err := file.Readdir(1); err == nil {
t.Errorf("Did not get error recall Readdir for %s", test.file)
}

if _, err := file.Seek(10, io.SeekCurrent); err == nil {
t.Errorf("Seek on folder did no return an err for %s", test.file)
}

if _, err := file.Seek(0, io.SeekStart); err != nil {
t.Errorf("Seek to begining of folder return error for %s %v", test.file, err)
}
}
}
testReadDir(t, test.file, file, test.isDir)

file.Close()
testClosed(t, test.file, file)
Expand Down Expand Up @@ -265,7 +248,7 @@ func makeFs() (string, FileSystem) {
return tmpdir, f
}

func testSeeking(t *testing.T, name string, file http.File, expect []byte) {
func testSeekStart(t *testing.T, name string, file http.File, expect []byte) {
// Test SeekStart
if n, err := file.Seek(10, io.SeekStart); err == nil {
if b, err := ioutil.ReadAll(file); err == nil {
Expand All @@ -282,7 +265,9 @@ func testSeeking(t *testing.T, name string, file http.File, expect []byte) {
} else {
t.Errorf("Seek io.SeekStart on file return error for %s %v", name, err)
}
}

func testSeekCurrent(t *testing.T, name string, file http.File, expect []byte) {
// Test SeekCurrent
if _, err := file.Seek(0, io.SeekStart); err == nil {
if n, err := file.Seek(10, io.SeekCurrent); err == nil {
Expand All @@ -300,6 +285,9 @@ func testSeeking(t *testing.T, name string, file http.File, expect []byte) {
t.Errorf("Seek io.SeekCurrent on file return error for %s %v", name, err)
}
}
}

func testSeekEnd(t *testing.T, name string, file http.File, expect []byte) {

// Test SeekEnd
if n, err := file.Seek(-10, io.SeekEnd); err == nil {
Expand All @@ -318,6 +306,9 @@ func testSeeking(t *testing.T, name string, file http.File, expect []byte) {
t.Errorf("Seek io.SeekCurrent on file return error for %s %v", name, err)
}

}

func testSeekBad(t *testing.T, name string, file http.File, expect []byte) {
// test seek before start of file
if _, err := file.Seek(-10, io.SeekStart); err == nil {
t.Errorf("Did no get error for seek before start of file %s", name)
Expand Down Expand Up @@ -375,6 +366,30 @@ func testStat(t *testing.T, name string, file http.File, isDir bool, local bool)
}
}

func testReadDir(t *testing.T, name string, file http.File, isDir bool) {
if _, err := file.Readdir(-1); err != nil {
if isDir {
t.Errorf("Got error Readdir for %s %v", name, err)
}
} else {
if !isDir {
t.Errorf("Did no get error Readdir for %s", name)
} else {
if _, err := file.Readdir(1); err == nil {
t.Errorf("Did not get error recall Readdir for %s", name)
}

if _, err := file.Seek(10, io.SeekCurrent); err == nil {
t.Errorf("Seek on folder did no return an err for %s", name)
}

if _, err := file.Seek(0, io.SeekStart); err != nil {
t.Errorf("Seek to beginning of folder return error for %s %v", name, err)
}
}
}
}

func testInfo(t *testing.T, name string, file http.File, compressed bool, local bool) {
if info, ok := file.(FileInfo); ok {
if compress := info.Compressed(); compress != compressed {
Expand Down
1 change: 0 additions & 1 deletion embedded/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ func (s *server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
defer ff.Close()
dd, err := ff.Stat()
if err == nil {
name = index
d = dd
f = ff
}
Expand Down
6 changes: 4 additions & 2 deletions generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ type Config struct {
// Include is the regexp for files to include. If provided, only files that
// match will be included.
Include string
// Minify is comma seperated list of mime type to minify.
// Minify is comma separated list of mime type to minify.
Minify string
// ModifyTime is the Unix timestamp to override as modification time for all files.
ModifyTime string
Expand Down Expand Up @@ -409,7 +409,9 @@ func (gen *generate) appendFiles(out *os.File, tests bool) {
for s, err = read.ReadString('\n'); err == nil && !strings.HasPrefix(s, "import"); s, err = read.ReadString('\n') {
}

for s, err = read.ReadString('\n'); err == nil && !strings.HasPrefix(s, ")"); s, err = read.ReadString('\n') {
if err == nil {
for s, err = read.ReadString('\n'); err == nil && !strings.HasPrefix(s, ")"); s, err = read.ReadString('\n') {
}
}

if err == nil {
Expand Down
76 changes: 38 additions & 38 deletions internal/templates/templates.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading