|
@@ -1 +1,94 @@
|
|
|
package router_anonym
|
|
|
+
|
|
|
+import (
|
|
|
+ "net/http"
|
|
|
+ "testing"
|
|
|
+
|
|
|
+ "git.p78su.freemyip.com/svi/gostore/pkg/mock/mock_service"
|
|
|
+ "git.p78su.freemyip.com/svi/gostore/pkg/mock/mock_web"
|
|
|
+ "github.com/gofiber/fiber/v2"
|
|
|
+)
|
|
|
+
|
|
|
+type tester struct {
|
|
|
+ t *testing.T
|
|
|
+ serv *mock_service.MockService
|
|
|
+ web *mock_web.MockWeb
|
|
|
+ anonRouter *RouterAnonym
|
|
|
+}
|
|
|
+
|
|
|
+func TestRouterAnonym(t *testing.T) {
|
|
|
+ sf := &tester{
|
|
|
+ t: t,
|
|
|
+ }
|
|
|
+ sf.create()
|
|
|
+ sf.get()
|
|
|
+ sf.time()
|
|
|
+}
|
|
|
+
|
|
|
+// Получение времени с сервера
|
|
|
+func (sf *tester) time() {
|
|
|
+ sf.t.Log("time")
|
|
|
+ app := fiber.New()
|
|
|
+ app.Get("/anonym/time", sf.anonRouter.time)
|
|
|
+ req, err := http.NewRequest("GET", "/anonym/time", nil)
|
|
|
+ if err != nil {
|
|
|
+ sf.t.Fatalf("time(): err=\n\t%v", err)
|
|
|
+ }
|
|
|
+ resp, err := app.Test(req)
|
|
|
+ if err != nil {
|
|
|
+ sf.t.Fatalf("time(): err=\n\t%v", err)
|
|
|
+ }
|
|
|
+ defer resp.Body.Close()
|
|
|
+}
|
|
|
+
|
|
|
+// Получение страницы размещения анонимного ключа
|
|
|
+func (sf *tester) get() {
|
|
|
+ sf.t.Log("get")
|
|
|
+ app := fiber.New()
|
|
|
+ app.Get("/anonym", sf.anonRouter.get)
|
|
|
+ req, err := http.NewRequest("GET", "/anonym", nil)
|
|
|
+ if err != nil {
|
|
|
+ sf.t.Fatalf("get(): err=\n\t%v", err)
|
|
|
+ }
|
|
|
+ resp, err := app.Test(req)
|
|
|
+ if err != nil {
|
|
|
+ sf.t.Fatalf("get(): err=\n\t%v", err)
|
|
|
+ }
|
|
|
+ defer resp.Body.Close()
|
|
|
+}
|
|
|
+
|
|
|
+// Создание роутера анонимных ключей
|
|
|
+func (sf *tester) create() {
|
|
|
+ sf.t.Log("create")
|
|
|
+ sf.createBad1()
|
|
|
+ sf.createGood1()
|
|
|
+}
|
|
|
+func (sf *tester) createGood1() {
|
|
|
+ sf.t.Log("createGood1")
|
|
|
+ var err error
|
|
|
+ sf.anonRouter, err = NewRouterAnonym(sf.web)
|
|
|
+ if err != nil {
|
|
|
+ sf.t.Fatalf("createGood1(): err=\n\t%v", err)
|
|
|
+ }
|
|
|
+ if sf.anonRouter == nil {
|
|
|
+ sf.t.Fatalf("createGood1(): anonRouter==nil")
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+// Нет объекта веб-сервера
|
|
|
+func (sf *tester) createBad1() {
|
|
|
+ sf.t.Log("createBad1")
|
|
|
+ sf.serv = mock_service.NewMockService()
|
|
|
+ var err error
|
|
|
+ sf.web, err = mock_web.NewMockWeb(sf.serv)
|
|
|
+ if err != nil {
|
|
|
+ sf.t.Fatalf("createBad1(): err=\n\t%v", err)
|
|
|
+ }
|
|
|
+ sf.anonRouter, err = NewRouterAnonym(nil)
|
|
|
+ if err == nil {
|
|
|
+ sf.t.Fatalf("createBad1(): err==nil")
|
|
|
+ }
|
|
|
+ if sf.anonRouter != nil {
|
|
|
+ sf.t.Fatalf("createBad1(): anonRouter!=nil")
|
|
|
+ }
|
|
|
+}
|