Skip to content

Commit

Permalink
Merge pull request #192 from yoyofx/dev
Browse files Browse the repository at this point in the history
v1.7.11
  • Loading branch information
yoyofx authored Nov 10, 2021
2 parents b2a1398 + e1c3528 commit 5d15243
Show file tree
Hide file tree
Showing 6 changed files with 614 additions and 720 deletions.
2 changes: 1 addition & 1 deletion examples/console/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ module console
go 1.16

require (
github.com/yoyofxteam/dependencyinjection v1.0.0
github.com/yoyofx/yoyogo v0.0.0
github.com/yoyofxteam/dependencyinjection v1.0.1
)

replace github.com/yoyofx/yoyogo => ../../
10 changes: 5 additions & 5 deletions examples/simpleweb/config_dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ yoyogo:
strategy: "round-robin" # round-robin , weight-time , random
type: "nacos"
metadata:
url: "120.53.133.30"
url: "nacos.yoyogo.run"
port: 80
namespace: "public"
group: "DEFAULT_GROUP"
Expand All @@ -55,8 +55,8 @@ yoyogo:
dataId: "simple_demo"
auth:
enable: true
username: "root"
password: "1234"
username: "nacos"
password: "nacos"
endpoint: ""
regionId: ""
accessKey: ""
Expand Down Expand Up @@ -103,6 +103,6 @@ yoyogo:
debug: false
redis:
name: reids1
url: 62.234.6.120:31379
password:
url: m.yoyogo.run:6379
password: 123.com
db: 0
245 changes: 123 additions & 122 deletions tests/goredis_test.go
Original file line number Diff line number Diff line change
@@ -1,124 +1,125 @@
package tests

import (
"context"
"fmt"
"github.com/go-redis/redis/v8"
"github.com/stretchr/testify/assert"
_ "github.com/stretchr/testify/assert"
cache "github.com/yoyofx/yoyogo/pkg/cache/redis"

"testing"
"time"
)

func newClient() *redis.Client {
client := redis.NewClient(&redis.Options{
Addr: "62.234.6.120:31379",
Password: "",
DB: 0,
})
return client
}

var ctx = context.Background()

func TestRedisConn(t *testing.T) {
client := newClient()
//defer client.Close()

//ping
pong, err := client.Ping(ctx).Result()
if err != nil {
fmt.Println("ping error", err.Error())
return
}
assert.Equal(t, pong, "PONG")
}

type Doctor struct {
Name string
Age int
}

func TestRedisStringValue(t *testing.T) {
client := newClient()
defer client.Close()

// string
client.Set(ctx, "yoyogo:version", "v1.6.1", 15*time.Minute)
version, _ := client.Get(ctx, "yoyogo:version").Result()
assert.Equal(t, version, "v1.6.1")

// json 序列化
doctor := Doctor{Name: "钟南山", Age: 83}

serializer := cache.JsonSerializer{}

doctorJson, _ := serializer.Serialization(doctor)
client.Set(ctx, "doctor2", doctorJson, time.Hour)
var doctor2 Doctor
doctorResult, _ := client.Get(ctx, "doctor2").Bytes()
_ = serializer.Deserialization(doctorResult, &doctor2)
assert.Equal(t, doctor2.Name, "钟南山")
assert.Equal(t, doctor2.Age, 83)

//client.SetNX()
}

func TestRedisList(t *testing.T) {
client := newClient()
defer client.Close()
listKey := "go2list"
_, _ = client.Del(ctx, listKey).Result()

client.RPush(ctx, listKey, 1, 2, 3)

first, _ := client.LPop(ctx, listKey).Int()
assert.Equal(t, first, 1)

i1, _ := client.LIndex(ctx, listKey, 1).Int64()
assert.Equal(t, i1, int64(3))

values, _ := client.LRange(ctx, listKey, 0, 1).Result()
assert.Equal(t, len(values), 2)
}

func TestAddTodoList(t *testing.T) {
client := newClient()
defer client.Close()

json := `[{
"id": 0,
"status": "STATUS_TODO",
"content": "每周七天阅读五次,每次阅读完要做100字的读书笔记",
"editable": false
}, {
"id": 1,
"status": "STATUS_TODO",
"content": "每周七天健身4次,每次健身时间需要大于20分钟",
"editable": false
}, {
"id": 2,
"status": "STATUS_TODO",
"content": "单词*100",
"editable": false
}, {
"id": 3,
"status": "STATUS_TODO",
"content": "单词*150",
"editable": false
}, {
"id": 4,
"status": "STATUS_TODO",
"content": "单词*200",
"editable": false
}, {
"id": 5,
"status": "STATUS_TODO",
"content": "单词*250",
"editable": false
}]`
//client.Set(ctx, "yoyogo:todolist", json, 0)
_ = json
}
//
//import (
// "context"
// "fmt"
// "github.com/go-redis/redis/v8"
// "github.com/stretchr/testify/assert"
// _ "github.com/stretchr/testify/assert"
// cache "github.com/yoyofx/yoyogo/pkg/cache/redis"
//
// "testing"
// "time"
//)
//
//func newClient() *redis.Client {
// client := redis.NewClient(&redis.Options{
// Addr: "m.yoyogo.run:6379",
// Password: "123.com",
// DB: 0,
// })
// return client
//}
//
//var ctx = context.Background()
//
//func TestRedisConn(t *testing.T) {
// client := newClient()
// //defer client.Close()
//
// //ping
// pong, err := client.Ping(ctx).Result()
// if err != nil {
// fmt.Println("ping error", err.Error())
// return
// }
// assert.Equal(t, pong, "PONG")
//}
//
//type Doctor struct {
// Name string
// Age int
//}
//
//func TestRedisStringValue(t *testing.T) {
// client := newClient()
// defer client.Close()
//
// // string
// client.Set(ctx, "yoyogo:version", "v1.6.1", 15*time.Minute)
// version, _ := client.Get(ctx, "yoyogo:version").Result()
// assert.Equal(t, version, "v1.6.1")
//
// // json 序列化
// doctor := Doctor{Name: "钟南山", Age: 83}
//
// serializer := cache.JsonSerializer{}
//
// doctorJson, _ := serializer.Serialization(doctor)
// client.Set(ctx, "doctor2", doctorJson, time.Hour)
// var doctor2 Doctor
// doctorResult, _ := client.Get(ctx, "doctor2").Bytes()
// _ = serializer.Deserialization(doctorResult, &doctor2)
// assert.Equal(t, doctor2.Name, "钟南山")
// assert.Equal(t, doctor2.Age, 83)
//
// //client.SetNX()
//}
//
//func TestRedisList(t *testing.T) {
// client := newClient()
// defer client.Close()
// listKey := "go2list"
// _, _ = client.Del(ctx, listKey).Result()
//
// client.RPush(ctx, listKey, 1, 2, 3)
//
// first, _ := client.LPop(ctx, listKey).Int()
// assert.Equal(t, first, 1)
//
// i1, _ := client.LIndex(ctx, listKey, 1).Int64()
// assert.Equal(t, i1, int64(3))
//
// values, _ := client.LRange(ctx, listKey, 0, 1).Result()
// assert.Equal(t, len(values), 2)
//}
//
//func TestAddTodoList(t *testing.T) {
// client := newClient()
// defer client.Close()
//
// json := `[{
// "id": 0,
// "status": "STATUS_TODO",
// "content": "每周七天阅读五次,每次阅读完要做100字的读书笔记",
// "editable": false
//}, {
// "id": 1,
// "status": "STATUS_TODO",
// "content": "每周七天健身4次,每次健身时间需要大于20分钟",
// "editable": false
//}, {
// "id": 2,
// "status": "STATUS_TODO",
// "content": "单词*100",
// "editable": false
//}, {
// "id": 3,
// "status": "STATUS_TODO",
// "content": "单词*150",
// "editable": false
//}, {
// "id": 4,
// "status": "STATUS_TODO",
// "content": "单词*200",
// "editable": false
//}, {
// "id": 5,
// "status": "STATUS_TODO",
// "content": "单词*250",
// "editable": false
//}]`
// //client.Set(ctx, "yoyogo:todolist", json, 0)
// _ = json
//}
40 changes: 20 additions & 20 deletions tests/httpclient_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,26 +98,26 @@ func TestHttpCleintFactoryCreateServiceDiscoveryCleint(t *testing.T) {
assert.Equal(t, string(res.Body), "ok")
}

func TestHttpClientFactoryBaseUrl(t *testing.T) {
httpServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(200)
_, _ = w.Write([]byte("ok"))
}))
fmt.Print(httpServer.URL)
//httpServer.URL = "http://127.0.0.1:8080"
defer httpServer.Close()
factory := httpclient.NewFactory()
client, err := factory.Create(httpServer.URL)
if err != nil {
panic(err)
}
req := httpclient.WithRequest()
req.GET("")
req.SetTimeout(10)
res, err := client.Do(req)
fmt.Print(string(res.Body))
assert.Equal(t, string(res.Body), "ok")
}
//func TestHttpClientFactoryBaseUrl(t *testing.T) {
// httpServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// w.WriteHeader(200)
// _, _ = w.Write([]byte("ok"))
// }))
// fmt.Print(httpServer.URL)
// //httpServer.URL = "http://127.0.0.1:8080"
// defer httpServer.Close()
// factory := httpclient.NewFactory()
// client, err := factory.Create(httpServer.URL)
// if err != nil {
// panic(err)
// }
// req := httpclient.WithRequest()
// req.GET("")
// req.SetTimeout(10)
// res, err := client.Do(req)
// fmt.Print(string(res.Body))
// assert.Equal(t, string(res.Body), "ok")
//}

func TestBaseUrlSplicingUrl(t *testing.T) {
factory := httpclient.NewFactory()
Expand Down
Loading

0 comments on commit 5d15243

Please sign in to comment.