From 3b0ba354bda7994ea7d3e612ef5785d57b7a54b3 Mon Sep 17 00:00:00 2001
From: ko_oler <kooler89@gmail.com>
Date: Mon, 18 Dec 2023 13:20:51 +0300
Subject: [PATCH] =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?=
 =?UTF-8?q?=D0=BD=20=D1=82=D0=B5=D1=81=D1=82?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 pkg/spaces/service_test.go | 81 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 81 insertions(+)
 create mode 100644 pkg/spaces/service_test.go

diff --git a/pkg/spaces/service_test.go b/pkg/spaces/service_test.go
new file mode 100644
index 00000000..c51f6d6d
--- /dev/null
+++ b/pkg/spaces/service_test.go
@@ -0,0 +1,81 @@
+package spaces
+
+import (
+	"context"
+	"testing"
+)
+
+type testSpaces struct {
+	Spaces
+	space *Space
+}
+
+func (t *testSpaces) Get(_ context.Context, spaceID string) (*Space, error) { return t.space, nil }
+
+func TestIsSpaceAvailable(t *testing.T) {
+	tests := []struct {
+		name       string
+		spacesCall *testSpaces
+		spaceId    string
+		wantErr    bool
+	}{
+		{
+			"Without StateInfo",
+			&testSpaces{
+				space: &Space{
+					ID:    "space",
+					OrgID: "org",
+					Name:  "test-space",
+				},
+			},
+			"space",
+			false,
+		},
+		{
+			"StateReady",
+			&testSpaces{
+				space: &Space{
+					ID:        "space",
+					OrgID:     "org",
+					Name:      "test-space",
+					StateInfo: &StateInfo{State: StateReady},
+				},
+			},
+			"space",
+			false,
+		},
+		{
+			"StatePreparing",
+			&testSpaces{
+				space: &Space{
+					ID:        "space",
+					OrgID:     "org",
+					Name:      "test-space",
+					StateInfo: &StateInfo{State: StatePreparing},
+				},
+			},
+			"space",
+			true,
+		},
+		{
+			"StateMigration",
+			&testSpaces{
+				space: &Space{
+					ID:        "space",
+					OrgID:     "org",
+					Name:      "test-space",
+					StateInfo: &StateInfo{State: StateMigration},
+				},
+			},
+			"space",
+			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 {
+				t.Errorf("IsSpaceAvailable() error = %v, wantErr %v", err, tt.wantErr)
+			}
+		})
+	}
+}
-- 
GitLab