Files
tavern/core/tavern_test.go

78 lines
2.0 KiB
Go
Raw Permalink Normal View History

2023-07-16 02:51:41 +09:00
// warroom project main.go
package core
import (
"context"
2023-07-19 09:37:02 +09:00
"fmt"
2023-07-16 02:51:41 +09:00
"testing"
2023-07-19 09:37:02 +09:00
"time"
2023-07-16 02:51:41 +09:00
"github.com/go-redis/redis/v8"
"go.mongodb.org/mongo-driver/bson/primitive"
2023-07-19 09:37:02 +09:00
"repositories.action2quare.com/ayo/gocommon"
2023-07-16 02:51:41 +09:00
"repositories.action2quare.com/ayo/gocommon/logger"
)
2023-07-19 09:37:02 +09:00
func TestPubSub(t *testing.T) {
opt0, _ := redis.ParseURL("redis://192.168.8.94:6380/0")
opt1, _ := redis.ParseURL("redis://192.168.8.94:6380/1")
rc0 := redis.NewClient(opt0)
rc1 := redis.NewClient(opt1)
go func() {
time.Sleep(time.Second)
rc1.Publish(context.Background(), "__testchan", "real???")
fmt.Println("published")
}()
pubsub := rc0.Subscribe(context.Background(), "__testchan")
msg, err := pubsub.ReceiveMessage(context.Background())
fmt.Println(msg.Payload, err)
}
2023-07-16 02:51:41 +09:00
func TestReJSON(t *testing.T) {
rc := redis.NewClient(&redis.Options{Addr: "192.168.8.94:6380"})
2023-07-19 09:37:02 +09:00
rh := gocommon.NewRedisonHandler(context.Background(), rc)
2023-07-16 02:51:41 +09:00
testDoc := map[string]any{
"members": map[string]any{
"mid2": map[string]any{
"key": "val",
"exp": 20202020,
},
"mid1": map[string]any{
"key": "val",
"exp": 10101010,
},
},
}
gd := groupDoc{
id: primitive.NewObjectID(),
}
midin := primitive.NewObjectID()
tid := gd.tid(midin)
midout := gd.mid(tid)
logger.Println(midin, tid, midout)
2023-07-16 15:36:20 +09:00
logger.Println(rh.JSONSet("jsontest", "$", testDoc))
logger.Println(rh.JSONGet("jsontest", "$"))
logger.Println(rh.JSONResp("jsontest", "$.members"))
logger.Println(rh.JSONGetString("jsontest", "$.members..key"))
logger.Println(rh.JSONGetInt64("jsontest", "$.members..exp"))
logger.Println(rh.JSONObjKeys("jsontest", "$.members"))
2023-07-16 02:51:41 +09:00
2023-07-16 15:36:20 +09:00
err := rh.JSONMSet("jsontest", map[string]any{
2023-07-16 02:51:41 +09:00
"$.members.mid1.key": "newval",
"$.members.mid2.key": "newval",
})
logger.Println(err)
2023-07-16 15:36:20 +09:00
logger.Println(rh.JSONGet("jsontest", "$"))
logger.Println(rh.JSONMDel("jsontest", []string{"$.members.mid1", "$.members.mid2"}))
logger.Println(rh.JSONGet("jsontest", "$"))
logger.Println(rh.JSONObjLen("jsontest", "$.members"))
2023-07-16 02:51:41 +09:00
}