[fix] tests

git-svn-id: file:///srv/svn/repo/yukari/trunk@94 f3bd38d9-da89-464d-a02a-eb04e43141b5
This commit is contained in:
alex 2019-08-11 08:28:28 +00:00
parent 998df87028
commit f2c037d6da
3 changed files with 31 additions and 13 deletions

View File

@ -1,14 +1,12 @@
language: go
sudo: false
go:
- 1.10.3
- 1.12.x
script:
# static checks
- test -z "$(gofmt -l ./)"
- test -z "$(go vet -v ./...)"
# run tests on a standard platform
- OUT="$(go get -a)"; test -z "$OUT" || (echo "$OUT" && return 1)
- OUT="$(gofmt -l -d ./)"; test -z "$OUT" || (echo "$OUT" && return 1)
- go vet -v ./...
- go test -v ./...
# build test for supported platforms

View File

@ -1,6 +1,8 @@
package contenttype
import (
"bytes"
"fmt"
"testing"
)
@ -72,6 +74,7 @@ var contentTypeEqualsTestCases []ContentTypeEqualsTestCase = []ContentTypeEquals
}
type FilterTestCase struct {
Description string
Input Filter
TrueValues []ContentType
FalseValues []ContentType
@ -79,6 +82,7 @@ type FilterTestCase struct {
var filterTestCases []FilterTestCase = []FilterTestCase{
FilterTestCase{
"contains xml",
NewFilterContains("xml"),
[]ContentType{
ContentType{"xml", "", "", Map_Empty},
@ -91,6 +95,7 @@ var filterTestCases []FilterTestCase = []FilterTestCase{
},
},
FilterTestCase{
"equals applications/xhtml",
NewFilterEquals("application", "xhtml", "*"),
[]ContentType{
ContentType{"application", "xhtml", "xml", Map_Empty},
@ -104,6 +109,7 @@ var filterTestCases []FilterTestCase = []FilterTestCase{
},
},
FilterTestCase{
"equals application/*",
NewFilterEquals("application", "*", ""),
[]ContentType{
ContentType{"application", "xhtml", "", Map_Empty},
@ -115,6 +121,7 @@ var filterTestCases []FilterTestCase = []FilterTestCase{
},
},
FilterTestCase{
"equals applications */javascript",
NewFilterEquals("*", "javascript", ""),
[]ContentType{
ContentType{"application", "javascript", "", Map_Empty},
@ -126,6 +133,7 @@ var filterTestCases []FilterTestCase = []FilterTestCase{
},
},
FilterTestCase{
"equals applications/* or */javascript",
NewFilterOr([]Filter{
NewFilterEquals("application", "*", ""),
NewFilterEquals("*", "javascript", ""),
@ -213,16 +221,28 @@ func TestParseContentType(t *testing.T) {
}
}
func FilterToString(m map[string]bool) string {
b := new(bytes.Buffer)
for key, value := range m {
if value {
fmt.Fprintf(b, "'%s'=true;", key)
} else {
fmt.Fprintf(b, "'%s'=false;", key)
}
}
return b.String()
}
func TestFilters(t *testing.T) {
for _, testCase := range filterTestCases {
for _, contentType := range testCase.TrueValues {
if !testCase.Input(contentType) {
t.Errorf(`Filter "%s" must accept the value "%s"`, testCase.Input, contentType)
t.Errorf(`Filter "%s" must accept the value "%s"`, testCase.Description, contentType)
}
}
for _, contentType := range testCase.FalseValues {
if testCase.Input(contentType) {
t.Errorf(`Filter "%s" mustn't accept the value "%s"`, testCase.Input, contentType)
t.Errorf(`Filter "%s" mustn't accept the value "%s"`, testCase.Description, contentType)
}
}
}
@ -241,7 +261,7 @@ func TestFilterParameters(t *testing.T) {
// test
contentTypeOutput := ContentType{"", "", "", testCase.Output}
if !contentTypeOutput.Equals(contentType) {
t.Errorf(`FilterParameters error : %s becomes %s with this filter %s`, testCase.Input, contentType.Parameters, testCase.Filter)
t.Errorf(`FilterParameters error : %s becomes %s with this filter %s`, testCase.Input, contentType.Parameters, FilterToString(testCase.Filter))
}
}
}

View File

@ -995,7 +995,7 @@ func main() {
if *key != "" {
var err error
p.Key, err = base64.StdEncoding.DecodeString(*key)
if (err != nil) {
if err != nil {
log.Fatal("Error parsing -key", err.Error())
os.Exit(1)
}