[fix] tests
git-svn-id: file:///srv/svn/repo/yukari/trunk@94 f3bd38d9-da89-464d-a02a-eb04e43141b5
This commit is contained in:
parent
998df87028
commit
f2c037d6da
12
.travis.yml
12
.travis.yml
@ -1,14 +1,12 @@
|
|||||||
language: go
|
language: go
|
||||||
|
sudo: false
|
||||||
go:
|
go:
|
||||||
- 1.10.3
|
- 1.12.x
|
||||||
|
|
||||||
script:
|
script:
|
||||||
# static checks
|
|
||||||
- test -z "$(gofmt -l ./)"
|
|
||||||
- test -z "$(go vet -v ./...)"
|
|
||||||
|
|
||||||
# run tests on a standard platform
|
# 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 ./...
|
- go test -v ./...
|
||||||
|
|
||||||
# build test for supported platforms
|
# build test for supported platforms
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
package contenttype
|
package contenttype
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
|
"fmt"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -72,6 +74,7 @@ var contentTypeEqualsTestCases []ContentTypeEqualsTestCase = []ContentTypeEquals
|
|||||||
}
|
}
|
||||||
|
|
||||||
type FilterTestCase struct {
|
type FilterTestCase struct {
|
||||||
|
Description string
|
||||||
Input Filter
|
Input Filter
|
||||||
TrueValues []ContentType
|
TrueValues []ContentType
|
||||||
FalseValues []ContentType
|
FalseValues []ContentType
|
||||||
@ -79,6 +82,7 @@ type FilterTestCase struct {
|
|||||||
|
|
||||||
var filterTestCases []FilterTestCase = []FilterTestCase{
|
var filterTestCases []FilterTestCase = []FilterTestCase{
|
||||||
FilterTestCase{
|
FilterTestCase{
|
||||||
|
"contains xml",
|
||||||
NewFilterContains("xml"),
|
NewFilterContains("xml"),
|
||||||
[]ContentType{
|
[]ContentType{
|
||||||
ContentType{"xml", "", "", Map_Empty},
|
ContentType{"xml", "", "", Map_Empty},
|
||||||
@ -91,6 +95,7 @@ var filterTestCases []FilterTestCase = []FilterTestCase{
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
FilterTestCase{
|
FilterTestCase{
|
||||||
|
"equals applications/xhtml",
|
||||||
NewFilterEquals("application", "xhtml", "*"),
|
NewFilterEquals("application", "xhtml", "*"),
|
||||||
[]ContentType{
|
[]ContentType{
|
||||||
ContentType{"application", "xhtml", "xml", Map_Empty},
|
ContentType{"application", "xhtml", "xml", Map_Empty},
|
||||||
@ -104,6 +109,7 @@ var filterTestCases []FilterTestCase = []FilterTestCase{
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
FilterTestCase{
|
FilterTestCase{
|
||||||
|
"equals application/*",
|
||||||
NewFilterEquals("application", "*", ""),
|
NewFilterEquals("application", "*", ""),
|
||||||
[]ContentType{
|
[]ContentType{
|
||||||
ContentType{"application", "xhtml", "", Map_Empty},
|
ContentType{"application", "xhtml", "", Map_Empty},
|
||||||
@ -115,6 +121,7 @@ var filterTestCases []FilterTestCase = []FilterTestCase{
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
FilterTestCase{
|
FilterTestCase{
|
||||||
|
"equals applications */javascript",
|
||||||
NewFilterEquals("*", "javascript", ""),
|
NewFilterEquals("*", "javascript", ""),
|
||||||
[]ContentType{
|
[]ContentType{
|
||||||
ContentType{"application", "javascript", "", Map_Empty},
|
ContentType{"application", "javascript", "", Map_Empty},
|
||||||
@ -126,6 +133,7 @@ var filterTestCases []FilterTestCase = []FilterTestCase{
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
FilterTestCase{
|
FilterTestCase{
|
||||||
|
"equals applications/* or */javascript",
|
||||||
NewFilterOr([]Filter{
|
NewFilterOr([]Filter{
|
||||||
NewFilterEquals("application", "*", ""),
|
NewFilterEquals("application", "*", ""),
|
||||||
NewFilterEquals("*", "javascript", ""),
|
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) {
|
func TestFilters(t *testing.T) {
|
||||||
for _, testCase := range filterTestCases {
|
for _, testCase := range filterTestCases {
|
||||||
for _, contentType := range testCase.TrueValues {
|
for _, contentType := range testCase.TrueValues {
|
||||||
if !testCase.Input(contentType) {
|
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 {
|
for _, contentType := range testCase.FalseValues {
|
||||||
if testCase.Input(contentType) {
|
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
|
// test
|
||||||
contentTypeOutput := ContentType{"", "", "", testCase.Output}
|
contentTypeOutput := ContentType{"", "", "", testCase.Output}
|
||||||
if !contentTypeOutput.Equals(contentType) {
|
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))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
6
morty.go
6
morty.go
@ -995,9 +995,9 @@ func main() {
|
|||||||
if *key != "" {
|
if *key != "" {
|
||||||
var err error
|
var err error
|
||||||
p.Key, err = base64.StdEncoding.DecodeString(*key)
|
p.Key, err = base64.StdEncoding.DecodeString(*key)
|
||||||
if (err != nil) {
|
if err != nil {
|
||||||
log.Fatal("Error parsing -key", err.Error())
|
log.Fatal("Error parsing -key", err.Error())
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user