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) } }) } }