Debian Codegraph @

errors_test.go

raw symbols SCIP
1 // Copyright 2014 Martini Authors
2 // Copyright 2014 The Macaron Authors
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License"): you may
5 // not use this file except in compliance with the License. You may obtain
6 // a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 // License for the specific language governing permissions and limitations
14 // under the License.
15
16 package binding
17
18 import (
19 "fmt"
20 "testing"
21
22 "github.com/stretchr/testify/assert"
23 )
24
25 func Test_ErrorsAdd(t *testing.T) {
26 var actual Errors
27 expected := Errors{
28 Error{
29 FieldNames: []string{"Field1", "Field2"},
30 Classification: "ErrorClass",
31 Message: "Some message",
32 },
33 }
34
35 actual.Add(expected[0].FieldNames, expected[0].Classification, expected[0].Message)
36
37 assert.Len(t, actual, 1)
38 assert.Equal(t, fmt.Sprintf("%#v", expected), fmt.Sprintf("%#v", actual))
39 }
40
41 func Test_ErrorsLen(t *testing.T) {
42 assert.Equal(t, len(errorsTestSet), errorsTestSet.Len())
43 }
44
45 func Test_ErrorsHas(t *testing.T) {
46 assert.True(t, errorsTestSet.Has("ClassA"))
47 assert.False(t, errorsTestSet.Has("ClassQ"))
48 }
49
50 func Test_ErrorGetters(t *testing.T) {
51 err := Error{
52 FieldNames: []string{"field1", "field2"},
53 Classification: "ErrorClass",
54 Message: "The message",
55 }
56
57 fieldsActual := err.Fields()
58
59 assert.Len(t, fieldsActual, 2)
60 assert.Equal(t, "field1", fieldsActual[0])
61 assert.Equal(t, "field2", fieldsActual[1])
62
63 assert.Equal(t, "ErrorClass", err.Kind())
64 assert.Equal(t, "The message", err.Error())
65 }
66
67 var errorsTestSet = Errors{
68 Error{
69 FieldNames: []string{},
70 Classification: "ClassA",
71 Message: "Foobar",
72 },
73 Error{
74 FieldNames: []string{},
75 Classification: "ClassB",
76 Message: "Foo",
77 },
78 Error{
79 FieldNames: []string{"field1", "field2"},
80 Classification: "ClassB",
81 Message: "Foobar",
82 },
83 Error{
84 FieldNames: []string{"field2"},
85 Classification: "ClassA",
86 Message: "Foobar",
87 },
88 Error{
89 FieldNames: []string{"field2"},
90 Classification: "ClassB",
91 Message: "Foobar",
92 },
93 }