|
@@ -0,0 +1,83 @@
|
|
|
+package anonym_del
|
|
|
+
|
|
|
+import (
|
|
|
+ "os"
|
|
|
+ "testing"
|
|
|
+
|
|
|
+ "github.com/gofiber/fiber/v2"
|
|
|
+
|
|
|
+ "git.p78su.freemyip.com/svi/gostore/pkg/mock/mock_service"
|
|
|
+ "git.p78su.freemyip.com/svi/gostore/pkg/mock/mock_web"
|
|
|
+ "git.p78su.freemyip.com/svi/gostore/pkg/types"
|
|
|
+)
|
|
|
+
|
|
|
+type tester struct {
|
|
|
+ t *testing.T
|
|
|
+ serv types.IService
|
|
|
+ web types.IServHttp
|
|
|
+ router fiber.Router
|
|
|
+}
|
|
|
+
|
|
|
+func TestAnonymDel(t *testing.T) {
|
|
|
+ fnClear := func() {
|
|
|
+ _ = os.RemoveAll("./store")
|
|
|
+ }
|
|
|
+ fnClear()
|
|
|
+ defer fnClear()
|
|
|
+ sf := &tester{
|
|
|
+ t: t,
|
|
|
+ }
|
|
|
+ sf.create()
|
|
|
+ // sf.del()
|
|
|
+ // sf.close()
|
|
|
+}
|
|
|
+
|
|
|
+// Создание удалятора анонимных ключей
|
|
|
+func (sf *tester) create() {
|
|
|
+ sf.t.Log("create")
|
|
|
+ sf.createBad1()
|
|
|
+ sf.createBad2()
|
|
|
+ sf.createGood1()
|
|
|
+}
|
|
|
+
|
|
|
+func (sf *tester) createGood1() {
|
|
|
+ sf.t.Log("createGood1")
|
|
|
+ sf.router = sf.web.FiberApp().Group("/anonym")
|
|
|
+ store, err := NewAnonymDel(sf.web, sf.router)
|
|
|
+ if err != nil {
|
|
|
+ sf.t.Fatalf("createGood1(): err=\n\t%v", err)
|
|
|
+ }
|
|
|
+ if store == nil {
|
|
|
+ sf.t.Fatalf("createGood1(): store==nil")
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+// Нет анонимного роутера
|
|
|
+func (sf *tester) createBad2() {
|
|
|
+ sf.t.Log("createBad2")
|
|
|
+ var err error
|
|
|
+ sf.serv = mock_service.NewMockService()
|
|
|
+ sf.web, err = mock_web.NewMockWeb(sf.serv)
|
|
|
+ if err != nil {
|
|
|
+ sf.t.Fatalf("createBad2(): err=\n\t%v", err)
|
|
|
+ }
|
|
|
+ anonDel, err := NewAnonymDel(sf.web, nil)
|
|
|
+ if err == nil {
|
|
|
+ sf.t.Fatalf("createBad2(): err==nil")
|
|
|
+ }
|
|
|
+ if anonDel != nil {
|
|
|
+ sf.t.Fatalf("createBad2(): anonDel!=nil")
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+// Нет объекта веб-сервера
|
|
|
+func (sf *tester) createBad1() {
|
|
|
+ sf.t.Log("createBad1")
|
|
|
+ store, err := NewAnonymDel(nil, nil)
|
|
|
+ if err == nil {
|
|
|
+ sf.t.Fatalf("createBad1(): err==nil")
|
|
|
+ }
|
|
|
+ if store != nil {
|
|
|
+ sf.t.Fatalf("createBad1(): store!=nil")
|
|
|
+ }
|
|
|
+}
|