|
@@ -0,0 +1,69 @@
|
|
|
+package mock_web
|
|
|
+
|
|
|
+import (
|
|
|
+ "os"
|
|
|
+ "testing"
|
|
|
+
|
|
|
+ "git.p78su.freemyip.com/svi/gostore/pkg/mock/mock_service"
|
|
|
+)
|
|
|
+
|
|
|
+type tester struct {
|
|
|
+ t *testing.T
|
|
|
+ serv *mock_service.MockService
|
|
|
+ mockWeb *MockWeb
|
|
|
+}
|
|
|
+
|
|
|
+func TestMockWeb(t *testing.T) {
|
|
|
+ fnClear := func() {
|
|
|
+ _ = os.RemoveAll("./store")
|
|
|
+ }
|
|
|
+ fnClear()
|
|
|
+ defer fnClear()
|
|
|
+ sf := &tester{
|
|
|
+ t: t,
|
|
|
+ }
|
|
|
+ sf.create()
|
|
|
+ // sf.run()
|
|
|
+}
|
|
|
+
|
|
|
+// Создание мок-веб-сервера
|
|
|
+func (sf *tester) create() {
|
|
|
+ sf.t.Log("create")
|
|
|
+ sf.createBad1()
|
|
|
+ sf.createGood1()
|
|
|
+}
|
|
|
+
|
|
|
+func (sf *tester) createGood1() {
|
|
|
+ sf.t.Log("createGood1")
|
|
|
+ sf.serv = mock_service.NewMockService()
|
|
|
+ var err error
|
|
|
+ sf.mockWeb, err = NewMockWeb(sf.serv)
|
|
|
+ if err != nil {
|
|
|
+ sf.t.Fatalf("createGood1(): err=\n\t%v", err)
|
|
|
+ }
|
|
|
+ if sf.mockWeb == nil {
|
|
|
+ sf.t.Fatalf("createGood1(): mockWeb==nil")
|
|
|
+ }
|
|
|
+ if fiber := sf.mockWeb.FiberApp(); fiber == nil {
|
|
|
+ sf.t.Fatalf("createGood1(): fiber==nil")
|
|
|
+ }
|
|
|
+ if serv := sf.mockWeb.Service(); serv == nil {
|
|
|
+ sf.t.Fatalf("createGood1(): serv==nil")
|
|
|
+ }
|
|
|
+ if err := sf.mockWeb.Run(); err != nil {
|
|
|
+ sf.t.Fatalf("createGood1(): err=\n\t%v", err)
|
|
|
+ }
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+// Нет объекта сервиса
|
|
|
+func (sf *tester) createBad1() {
|
|
|
+ sf.t.Log("createBad1")
|
|
|
+ mockWeb, err := NewMockWeb(nil)
|
|
|
+ if err == nil {
|
|
|
+ sf.t.Fatalf("createBad1(): err==nil")
|
|
|
+ }
|
|
|
+ if mockWeb != nil {
|
|
|
+ sf.t.Fatalf("createBad1(): mockWeb!=nil")
|
|
|
+ }
|
|
|
+}
|