Skip to content
Snippets Groups Projects
Commit 9ce2fdf2 authored by ko_oler's avatar ko_oler
Browse files

fix

parent 3b0ba354
No related branches found
No related tags found
No related merge requests found
...@@ -5,75 +5,46 @@ import ( ...@@ -5,75 +5,46 @@ import (
"testing" "testing"
) )
type testSpaces struct { // dummySpaces используется для имитации поведения Spaces
// Моки использовать не можем, так как получается циклический импорт
type dummySpaces struct {
Spaces Spaces
space *Space 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) { func TestIsSpaceAvailable(t *testing.T) {
tests := []struct { tests := []struct {
name string name string
spacesCall *testSpaces space *Space
spaceId string wantErr bool
wantErr bool
}{ }{
{ {
"Without StateInfo", "Without StateInfo",
&testSpaces{ &Space{ID: "space", OrgID: "org", Name: "test-space"},
space: &Space{
ID: "space",
OrgID: "org",
Name: "test-space",
},
},
"space",
false, false,
}, },
{ {
"StateReady", "StateReady",
&testSpaces{ &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},
},
},
"space",
false, false,
}, },
{ {
"StatePreparing", "StatePreparing",
&testSpaces{ &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},
},
},
"space",
true, true,
}, },
{ {
"StateMigration", "StateMigration",
&testSpaces{ &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},
},
},
"space",
true, true,
}, },
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { 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) t.Errorf("IsSpaceAvailable() error = %v, wantErr %v", err, tt.wantErr)
} }
}) })
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment