diff --git a/pkg/spaces/service_test.go b/pkg/spaces/service_test.go new file mode 100644 index 0000000000000000000000000000000000000000..c51f6d6d3031b763334dc17212c5b46dbba8b51f --- /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) + } + }) + } +}