generated from clevergo/pkg-template
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathstore_test.go
60 lines (50 loc) · 1.16 KB
/
store_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// Copyright 2020 CleverGo. All rights reserved.
// Use of this source code is governed by a MIT style license that can be found
// in the LICENSE file.
package mysqlstore
import (
"context"
"database/sql"
"fmt"
"os"
"testing"
_ "github.com/go-sql-driver/mysql"
)
var testDB *sql.DB
func TestMain(m *testing.M) {
psw := os.Getenv("MYSQL_PASSWORD")
var err error
testDB, err = sql.Open("mysql", fmt.Sprintf("root:%s@tcp(localhost:3306)/test?multiStatements=true", psw))
if err != nil {
panic(err)
}
m.Run()
}
func TestStoreGet(t *testing.T) {
s := New(testDB)
ctx := context.TODO()
_, err := s.Get(ctx, "foo", true)
if err == nil {
t.Error("expected a non-nil error, got nil")
}
err = s.Set(ctx, "foo", "bar")
if err != nil {
t.Fatalf("failed to set: %s", err)
}
for _, clear := range []bool{false, true} {
value, err := s.Get(ctx, "foo", clear)
if err != nil {
t.Fatalf("expected non error, got %s", err)
}
if value != "bar" {
t.Errorf("expected value %q, got %q", "bar", value)
}
}
_, err = s.Get(ctx, "foo", true)
if err == nil {
t.Error("expected a non-nil error, got nil")
}
}
func TestStoreSet(t *testing.T) {
// TBD
}