-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
152 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#!/bin/sh | ||
|
||
# 参考URL: http://www.songmu.jp/riji/entry/2015-01-15-goveralls-multi-package.html | ||
|
||
set -e | ||
|
||
# 中断した時とかにゴミが残らないようにcleanupする | ||
cleanup() { | ||
retval=$? | ||
if [ $tmpprof != "" ] && [ -f $tmpprof ]; then | ||
rm -f $tmpprof | ||
fi | ||
exit $retval | ||
} | ||
trap cleanup INT QUIT TERM EXIT | ||
|
||
# メインの処理 | ||
prof=${1:-".profile.cov"} | ||
echo "mode: count" > $prof | ||
gopath1=$(echo $GOPATH | cut -d: -f3) | ||
echo "mode: count" > $prof | ||
for pkg in $(go list ./...); do | ||
tmpprof=$gopath1/src/$pkg/profile.tmp | ||
go test -covermode=count -coverprofile=$tmpprof $pkg | ||
if [ -f $tmpprof ]; then | ||
cat $tmpprof | tail -n +2 >> $prof | ||
rm $tmpprof | ||
fi | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package testcase | ||
|
||
import ( | ||
"fmt" | ||
"net/http/httptest" | ||
) | ||
|
||
type contentLengthTestCase struct { | ||
contentLength int | ||
} | ||
|
||
func ContentLength(contentLength int) HandlerTestCase { | ||
return &contentLengthTestCase{ | ||
contentLength: contentLength, | ||
} | ||
} | ||
|
||
var _ HandlerTestCase = (*contentLengthTestCase)(nil) | ||
|
||
func (t *contentLengthTestCase) Execute(resp *httptest.ResponseRecorder) error { | ||
if t.contentLength != resp.Body.Len() { | ||
return fmt.Errorf("should Content-Length %d ≠ %d", t.contentLength, resp.Body.Len()) | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package testcase | ||
|
||
import ( | ||
"fmt" | ||
"net/http/httptest" | ||
) | ||
|
||
type contentTypeTestCase struct { | ||
contentType string | ||
} | ||
|
||
func ContentType(contentType string) HandlerTestCase { | ||
return &contentTypeTestCase{ | ||
contentType: contentType, | ||
} | ||
} | ||
|
||
var _ HandlerTestCase = (*contentTypeTestCase)(nil) | ||
|
||
func (t *contentTypeTestCase) Execute(resp *httptest.ResponseRecorder) error { | ||
contentType := resp.Header().Get("Content-Type") | ||
if contentType != t.contentType { | ||
return fmt.Errorf("should Content-Type %s ≠ %s", contentType, t.contentType) | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package testcase | ||
|
||
import ( | ||
"fmt" | ||
"net/http/httptest" | ||
) | ||
|
||
type statusCodeTestCase struct { | ||
statusCode int | ||
} | ||
|
||
func StatusCode(statusCode int) HandlerTestCase { | ||
return &statusCodeTestCase{ | ||
statusCode: statusCode, | ||
} | ||
} | ||
|
||
var _ HandlerTestCase = (*statusCodeTestCase)(nil) | ||
|
||
func (t *statusCodeTestCase) Execute(resp *httptest.ResponseRecorder) error { | ||
if resp.Code != t.statusCode { | ||
return fmt.Errorf("should return HTTP OK %d ≠ %d", resp.Code, t.statusCode) | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package testcase | ||
|
||
import ( | ||
"net/http/httptest" | ||
) | ||
|
||
type HandlerTestCase interface { | ||
Execute(resp *httptest.ResponseRecorder) error | ||
} |