go-micro.dev/v5@v5.12.0/store/mysql/mysql_test.go (about) 1 //go:build integration 2 // +build integration 3 4 package mysql 5 6 import ( 7 "encoding/json" 8 "os" 9 "testing" 10 "time" 11 12 _ "github.com/go-sql-driver/mysql" 13 "go-micro.dev/v5/store" 14 ) 15 16 var ( 17 sqlStoreT store.Store 18 ) 19 20 func TestMain(m *testing.M) { 21 if tr := os.Getenv("TRAVIS"); len(tr) > 0 { 22 os.Exit(0) 23 } 24 25 sqlStoreT = NewMysqlStore( 26 store.Database("testMicro"), 27 store.Nodes("root:123@(127.0.0.1:3306)/test?charset=utf8&parseTime=true&loc=Asia%2FShanghai"), 28 ) 29 os.Exit(m.Run()) 30 } 31 32 func TestWrite(t *testing.T) { 33 err := sqlStoreT.Write( 34 &store.Record{ 35 Key: "test", 36 Value: []byte("foo2"), 37 Expiry: time.Second * 200, 38 }, 39 ) 40 if err != nil { 41 t.Error(err) 42 } 43 } 44 45 func TestDelete(t *testing.T) { 46 err := sqlStoreT.Delete("test") 47 if err != nil { 48 t.Error(err) 49 } 50 } 51 52 func TestRead(t *testing.T) { 53 records, err := sqlStoreT.Read("test") 54 if err != nil { 55 t.Error(err) 56 } 57 58 t.Log(string(records[0].Value)) 59 } 60 61 func TestList(t *testing.T) { 62 records, err := sqlStoreT.List() 63 if err != nil { 64 t.Error(err) 65 } else { 66 beauty, _ := json.Marshal(records) 67 t.Log(string(beauty)) 68 } 69 }