We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent efc8ecc commit 6611843Copy full SHA for 6611843
4 files changed
storage/dsn_test.go
@@ -43,5 +43,24 @@ func TestDSN(t *testing.T) {
43
44
dsn.AddParam("key", "value")
45
t.Logf("Test set add param: formatted = %s", dsn.Format())
46
+
47
+ dsn.AddParam("key", "")
48
+ t.Logf("Test delete param by set empty to add param: formatted = %s", dsn.Format())
49
+ if _, ok := dsn.GetParam("key"); ok {
50
+ t.Errorf("Should not have deleted key")
51
+ }
52
53
54
+ invalidString1 := "file:test.db?p1"
55
+ dsn, err := NewDSN(invalidString1)
56
+ if err == nil {
57
+ t.Errorf("Should occurred unrecognized parameter error: %v", dsn)
58
59
60
+ dsn = &DSN{}
61
+ dsn.AddParam("clone", "true")
62
+ clone := dsn.Clone()
63
+ if _, ok := clone.GetParam("clone"); !ok {
64
+ t.Errorf("Should cloned params")
65
}
66
storage/storage_test.go
@@ -53,13 +53,26 @@ func newNamedQuery(query string, args map[string]interface{}) (q Query) {
func TestBadType(t *testing.T) {
- fl, err := ioutil.TempFile("", "sqlite3-")
+ // invalid storage
- if err != nil {
- t.Fatalf("error occurred: %v", err)
+ st, err := New(invalidString1)
+ defer st.Close()
+ t.Fatalf("should occurred error: %v", st)
- st, err := New(fmt.Sprintf("file:%s", fl.Name()))
+ st = &Storage{
+ dsn: invalidString1,
67
+ db: nil,
68
69
+ err = st.Close()
70
71
72
73
74
+ // valid storage
75
+ st, err = New("file::memory:")
76
defer st.Close()
77
78
if err != nil {
@@ -83,6 +96,16 @@ func TestBadType(t *testing.T) {
83
96
} else {
84
97
t.Logf("Error occurred as expected: %v", err)
85
98
99
100
+ // empty query
101
+ _, _, _, err = st.Query(context.Background(), []Query{})
102
+ if err != nil {
103
+ t.Fatal("empty query should be successed")
104
105
+ _, err = st.Exec(context.Background(), []Query{})
106
107
+ t.Fatal("empty exec should be successed")
108
86
109
87
110
88
111
func TestStorage(t *testing.T) {
types/account_test.go
@@ -33,7 +33,7 @@ func TestUserPermissionFromRole(t *testing.T) {
33
err = json.Unmarshal([]byte(`"Write"`), &r)
34
So(err, ShouldBeNil)
35
So(r, ShouldEqual, Write)
36
- err = json.Unmarshal([]byte(`"Read,Write"`), &r)
+ err = r.UnmarshalJSON([]byte(`"Read,Write"`))
37
38
So(r, ShouldEqual, ReadWrite)
39
})
@@ -42,8 +42,18 @@ func TestUserPermissionFromRole(t *testing.T) {
42
So(r, ShouldEqual, Void)
r.FromString(Read.String())
So(r, ShouldEqual, Read)
+ r.FromString(Void.String())
+ So(r, ShouldEqual, Void)
r.FromString(ReadWrite.String())
+ r.FromString(Admin.String())
+ So(r, ShouldEqual, Admin)
+ // tricky case
+ trickyStr := "Write,Super"
+ r.FromString(trickyStr)
+ So(r, ShouldEqual, Write|Super)
+ So(r.String(), ShouldEqual, trickyStr)
utils/log/logwrapper_test.go
@@ -102,6 +102,7 @@ func TestWithField(t *testing.T) {
call0()
+ WithError(errors.New("new")).WithField("newfieldkey", "newfieldvalue").WithTime(time.Now()).Debug("debug")
f := new(Fields)
WithError(errors.New("new")).WithFields(*f).WithTime(time.Now()).Debug("debug")
@@ -179,10 +180,23 @@ func TestSimpleLog(t *testing.T) {
179
180
Debug("Debug")
181
Debugln("Debugln")
182
Debugf("Debugf %d", 1)
183
+}
184
185
+func TestFatalLog(t *testing.T) {
186
+ SetStringLevel("willusenextparam", ErrorLevel)
187
+ if GetLevel() != ErrorLevel {
188
+ t.Fail()
189
190
191
logrus.StandardLogger().ExitFunc = func(code int) {}
192
Fatal("Fatal")
193
Fatalln("Fatalln")
194
Fatalf("Fatalf %d", 1)
195
196
+ entry := WithError(errors.New("new"))
197
+ entry.Fatal("entry Fatal")
198
+ entry.Fatalln("entry Fatalln")
199
+ entry.Fatalf("entry Fatal %d", 1)
200
201
logrus.StandardLogger().ExitFunc = nil
202
0 commit comments