convert seen service to use store

This commit is contained in:
Asim Aslam
2021-05-02 14:24:05 +01:00
parent ac62b8b35b
commit eb82bebd03
3 changed files with 88 additions and 86 deletions

View File

@@ -2,13 +2,13 @@ package handler_test
import (
"context"
"database/sql"
"os"
"testing"
"time"
"github.com/google/uuid"
"github.com/micro/micro/v3/service/auth"
"github.com/micro/micro/v3/service/store"
"github.com/micro/micro/v3/service/store/memory"
"github.com/micro/services/seen/handler"
pb "github.com/micro/services/seen/proto"
"github.com/stretchr/testify/assert"
@@ -16,24 +16,8 @@ import (
)
func testHandler(t *testing.T) *handler.Seen {
// connect to the database
addr := os.Getenv("POSTGRES_URL")
if len(addr) == 0 {
addr = "postgresql://postgres@localhost:5432/postgres?sslmode=disable"
}
sqlDB, err := sql.Open("pgx", addr)
if err != nil {
t.Fatalf("Failed to open connection to DB %s", err)
}
// clean any data from a previous run
if _, err := sqlDB.Exec("DROP TABLE IF EXISTS micro_seen_instances CASCADE"); err != nil {
t.Fatalf("Error cleaning database: %v", err)
}
h := &handler.Seen{}
h.DBConn(sqlDB).Migrations(&handler.SeenInstance{})
return h
store.DefaultStore = memory.NewStore()
return &handler.Seen{}
}
func TestSet(t *testing.T) {