From 9ce2fdf209e4a0f5cbbabdb7a4c0084e08019e48 Mon Sep 17 00:00:00 2001
From: ko_oler <kooler89@gmail.com>
Date: Mon, 18 Dec 2023 13:36:57 +0300
Subject: [PATCH] fix

---
 pkg/spaces/service_test.go | 55 +++++++++-----------------------------
 1 file changed, 13 insertions(+), 42 deletions(-)

diff --git a/pkg/spaces/service_test.go b/pkg/spaces/service_test.go
index c51f6d6d..8885076d 100644
--- a/pkg/spaces/service_test.go
+++ b/pkg/spaces/service_test.go
@@ -5,75 +5,46 @@ import (
 	"testing"
 )
 
-type testSpaces struct {
+// dummySpaces используется для имитации поведения Spaces
+// Моки использовать не можем, так как получается циклический импорт
+type dummySpaces struct {
 	Spaces
 	space *Space
 }
 
-func (t *testSpaces) Get(_ context.Context, spaceID string) (*Space, error) { return t.space, nil }
+func (t *dummySpaces) Get(_ context.Context, _ string) (*Space, error) { return t.space, nil }
 
 func TestIsSpaceAvailable(t *testing.T) {
 	tests := []struct {
-		name       string
-		spacesCall *testSpaces
-		spaceId    string
-		wantErr    bool
+		name    string
+		space   *Space
+		wantErr bool
 	}{
 		{
 			"Without StateInfo",
-			&testSpaces{
-				space: &Space{
-					ID:    "space",
-					OrgID: "org",
-					Name:  "test-space",
-				},
-			},
-			"space",
+			&Space{ID: "space", OrgID: "org", Name: "test-space"},
 			false,
 		},
 		{
 			"StateReady",
-			&testSpaces{
-				space: &Space{
-					ID:        "space",
-					OrgID:     "org",
-					Name:      "test-space",
-					StateInfo: &StateInfo{State: StateReady},
-				},
-			},
-			"space",
+			&Space{ID: "space", OrgID: "org", Name: "test-space", StateInfo: &StateInfo{State: StateReady}},
 			false,
 		},
 		{
 			"StatePreparing",
-			&testSpaces{
-				space: &Space{
-					ID:        "space",
-					OrgID:     "org",
-					Name:      "test-space",
-					StateInfo: &StateInfo{State: StatePreparing},
-				},
-			},
-			"space",
+			&Space{ID: "space", OrgID: "org", Name: "test-space", StateInfo: &StateInfo{State: StatePreparing}},
 			true,
 		},
 		{
 			"StateMigration",
-			&testSpaces{
-				space: &Space{
-					ID:        "space",
-					OrgID:     "org",
-					Name:      "test-space",
-					StateInfo: &StateInfo{State: StateMigration},
-				},
-			},
-			"space",
+			&Space{ID: "space", OrgID: "org", Name: "test-space", StateInfo: &StateInfo{State: StateMigration}},
 			true,
 		},
 	}
 	for _, tt := range tests {
 		t.Run(tt.name, func(t *testing.T) {
-			if err := IsSpaceAvailable(context.Background(), tt.spacesCall, tt.spaceId); (err != nil) != tt.wantErr {
+			spaces := &dummySpaces{space: tt.space}
+			if err := IsSpaceAvailable(context.Background(), spaces, "space"); (err != nil) != tt.wantErr {
 				t.Errorf("IsSpaceAvailable() error = %v, wantErr %v", err, tt.wantErr)
 			}
 		})
-- 
GitLab