add sqlite

This commit is contained in:
2023-08-10 22:16:14 +03:00
parent a5a6c683a4
commit 6eb76b1d15
11 changed files with 364 additions and 11 deletions

View File

@@ -7,11 +7,12 @@ import (
pb "go.unistack.org/unistack-org/pkgdash/proto/go_generate"
"go.unistack.org/unistack-org/pkgdash/storage"
"go.unistack.org/unistack-org/pkgdash/storage/postgres"
"go.unistack.org/unistack-org/pkgdash/storage/sqlite"
"google.golang.org/protobuf/types/known/wrapperspb"
"testing"
)
func TestClient(t *testing.T) {
func TestClientPG(t *testing.T) {
dsn := fmt.Sprintf("user=%s password=%s host=%s port=%s dbname=%s sslmode=disable", "test", "123", "localhost", "5432", "postgres")
conn, err := sql.Open("postgres", dsn)
if err != nil {
@@ -47,3 +48,39 @@ func TestClient(t *testing.T) {
<-cli.Done()
}
func TestClientLite(t *testing.T) {
conn, err := sql.Open("sqlite3", "../../identifier.sqlite")
if err != nil {
t.Fatal(err)
}
defer conn.Close()
if err = conn.Ping(); err != nil {
t.Fatal(err)
}
st, err := sqlite.NewStorage(conn)
if err != nil {
t.Fatal(err)
}
s, ok := st.(storage.Storage)
if !ok {
t.Fatal("typecast error")
}
ctx, cancel := context.WithCancel(context.Background())
_ = cancel
cli := NewClient(1)
ch := cli.Run(ctx, s)
data := &pb.AddPackageRsp{
Name: wrapperspb.String("test"),
Url: wrapperspb.String("https://github.com/dantedenis/service_history.git"),
}
ch <- data
<-cli.Done()
}

View File

@@ -56,26 +56,26 @@ func NewService(ctx context.Context) (micro.Service, error) {
h := handler.NewHandler(svc, writer, client_git.NewClient(5))
if err := svc.Init(
if err = svc.Init(
micro.AfterStart(func(_ context.Context) error {
return h.Init(svc.Options().Context)
}),
micro.BeforeStart(func(ctx context.Context) error {
if err := config.Load(ctx, cs, config.LoadOverride(true)); err != nil {
if err = config.Load(ctx, cs, config.LoadOverride(true)); err != nil {
return err
}
if err := config.Validate(ctx, cfg); err != nil {
if err = config.Validate(ctx, cfg); err != nil {
return err
}
if err := svc.Init(
if err = svc.Init(
micro.Name(cfg.Service.Name),
micro.Version(cfg.Service.Version),
); err != nil {
return err
}
if err := svc.Server("http").Init(
if err = svc.Server("http").Init(
server.Address(cfg.App.Address),
server.Name(cfg.Service.Name),
server.Version(cfg.Service.Version),