Skip to content
Snippets Groups Projects
Commit 8fa5d49e authored by ko_oler's avatar ko_oler
Browse files

правки после обновления perxis-go

parent 05402c16
No related branches found
No related tags found
No related merge requests found
......@@ -92,7 +92,7 @@ func TestSetupInstall(t *testing.T) {
sps := &spaces.Space{
ID: spaceID,
OrgID: "org",
State: spaces.StateReady,
StateInfo: &spaces.StateInfo{State: spaces.StateReady},
}
t.Run("Success, nothing to install", func(t *testing.T) {
......@@ -668,7 +668,7 @@ func TestSetupInstall(t *testing.T) {
t.Run("Success on retry when space not available", func(t *testing.T) {
logger := zaptest.NewLogger(t, zaptest.WrapOptions())
sp := &mocks.Spaces{}
sp.On("Get", mock.Anything, mock.Anything).Return(&spaces.Space{ID: spaceID, OrgID: "org", State: spaces.StateMigration}, nil).Twice()
sp.On("Get", mock.Anything, mock.Anything).Return(&spaces.Space{ID: spaceID, OrgID: "org", StateInfo: &spaces.StateInfo{State: spaces.StateMigration}}, nil).Twice()
sp.On("Get", mock.Anything, mock.Anything).Return(sps, nil).Once()
setup := NewSetup(&content.Content{Spaces: sp}, spaceID, envID, logger)
......@@ -682,7 +682,7 @@ func TestSetupInstall(t *testing.T) {
t.Run("Error on retry", func(t *testing.T) {
logger := zaptest.NewLogger(t, zaptest.WrapOptions())
sp := &mocks.Spaces{}
sp.On("Get", mock.Anything, mock.Anything).Return(&spaces.Space{ID: spaceID, OrgID: "org", State: spaces.StateMigration}, nil).Twice()
sp.On("Get", mock.Anything, mock.Anything).Return(&spaces.Space{ID: spaceID, OrgID: "org", StateInfo: &spaces.StateInfo{State: spaces.StateMigration}}, nil).Twice()
sp.On("Get", mock.Anything, mock.Anything).Return(nil, errors.New("some error")).Once()
setup := NewSetup(&content.Content{Spaces: sp}, spaceID, envID, logger)
err := setup.WithWaitForSpaceReady().Install(context.Background())
......@@ -774,7 +774,7 @@ func TestSetupUninstall(t *testing.T) {
sps := &spaces.Space{
ID: spaceID,
OrgID: "org",
State: spaces.StateReady,
StateInfo: &spaces.StateInfo{State: spaces.StateReady},
}
t.Run("Success, nothing to uninstall", func(t *testing.T) {
......@@ -1051,7 +1051,7 @@ func TestSetupUninstall(t *testing.T) {
logger := zaptest.NewLogger(t, zaptest.WrapOptions())
sp := &mocks.Spaces{}
sp.On("Get", mock.Anything, mock.Anything).Return(&spaces.Space{ID: spaceID, OrgID: "org", State: spaces.StateMigration}, nil).Twice()
sp.On("Get", mock.Anything, mock.Anything).Return(&spaces.Space{ID: spaceID, OrgID: "org", StateInfo: &spaces.StateInfo{State: spaces.StateMigration}}, nil).Twice()
sp.On("Get", mock.Anything, mock.Anything).Return(sps, nil).Once()
setup := NewSetup(&content.Content{Spaces: sp}, spaceID, envID, logger)
......@@ -1067,7 +1067,7 @@ func TestSetupUninstall(t *testing.T) {
logger := zaptest.NewLogger(t, zaptest.WrapOptions())
sp := &mocks.Spaces{}
sp.On("Get", mock.Anything, mock.Anything).Return(&spaces.Space{ID: spaceID, OrgID: "org", State: spaces.StateMigration}, nil).Twice()
sp.On("Get", mock.Anything, mock.Anything).Return(&spaces.Space{ID: spaceID, OrgID: "org", StateInfo: &spaces.StateInfo{State: spaces.StateMigration}}, nil).Twice()
sp.On("Get", mock.Anything, mock.Anything).Return(nil, errors.New("some error")).Once()
setup := NewSetup(&content.Content{Spaces: sp}, spaceID, envID, logger)
......@@ -1082,7 +1082,7 @@ func TestSetupCheck(t *testing.T) {
sps := &spaces.Space{
ID: spaceID,
OrgID: "org",
State: spaces.StateReady,
StateInfo: &spaces.StateInfo{State: spaces.StateReady},
}
t.Run("Success, nothing to check", func(t *testing.T) {
......@@ -1275,7 +1275,7 @@ func TestSetupCheck(t *testing.T) {
logger := zaptest.NewLogger(t, zaptest.WrapOptions())
sp := &mocks.Spaces{}
sp.On("Get", mock.Anything, mock.Anything).Return(&spaces.Space{ID: spaceID, OrgID: "org", State: spaces.StatePreparing}, nil).Twice()
sp.On("Get", mock.Anything, mock.Anything).Return(&spaces.Space{ID: spaceID, OrgID: "org", StateInfo: &spaces.StateInfo{State: spaces.StatePreparing}}, nil).Twice()
sp.On("Get", mock.Anything, mock.Anything).Return(sps, nil).Once()
setup := NewSetup(&content.Content{Spaces: sp}, spaceID, envID, logger)
......@@ -1291,7 +1291,7 @@ func TestSetupCheck(t *testing.T) {
logger := zaptest.NewLogger(t, zaptest.WrapOptions())
sp := &mocks.Spaces{}
sp.On("Get", mock.Anything, mock.Anything).Return(&spaces.Space{ID: spaceID, OrgID: "org", State: spaces.StatePreparing}, nil).Twice()
sp.On("Get", mock.Anything, mock.Anything).Return(&spaces.Space{ID: spaceID, OrgID: "org", StateInfo: &spaces.StateInfo{State: spaces.StatePreparing}}, nil).Twice()
sp.On("Get", mock.Anything, mock.Anything).Return(nil, errors.New("some error")).Once()
setup := NewSetup(&content.Content{Spaces: sp}, spaceID, envID, logger)
......
......@@ -63,7 +63,7 @@ func IsSpaceAvailable(ctx context.Context, svc Spaces, spaceID string) error {
if err != nil {
return errors.Wrap(err, "fail to get space")
}
if sp.State == StateReady || sp.State == StateNew {
if sp.StateInfo == nil || sp.StateInfo != nil && (sp.StateInfo.State == StateNew || sp.StateInfo.State == StateReady) {
return nil
}
return ErrSpaceNotAvailable
......@@ -74,10 +74,10 @@ func IsReadAvailable(ctx context.Context, svc Spaces, spaceID string) error {
if err != nil {
return errors.Wrap(err, "fail to get space")
}
if sp.State == StateReady || sp.State == StateNew || sp.State == StateMigration {
if sp.StateInfo == nil || sp.StateInfo != nil && sp.StateInfo.State == StateNew || sp.StateInfo.State == StateReady || sp.StateInfo.State == StateMigration {
return nil
}
return errors.WithContext(ErrSpaceNotAvailable, "state", sp.State)
return errors.WithContext(ErrSpaceNotAvailable, "state", sp.StateInfo.State)
}
func WaitSpaceAvailable(ctx context.Context, svc Spaces, spaceID string, logger *zap.Logger) error {
......
......@@ -50,3 +50,40 @@ func TestIsSpaceAvailable(t *testing.T) {
})
}
}
func TestIsReadAvailable(t *testing.T) {
tests := []struct {
name string
space *Space
wantErr bool
}{
{
"Space has nil StateInfo: available",
&Space{ID: "space", OrgID: "org", Name: "test-space"},
false,
},
{
"Space state is StateReady: available",
&Space{ID: "space", OrgID: "org", Name: "test-space", StateInfo: &StateInfo{State: StateReady}},
false,
},
{
"Space state is StatePreparing: not available",
&Space{ID: "space", OrgID: "org", Name: "test-space", StateInfo: &StateInfo{State: StatePreparing}},
true,
},
{
"Space state is StateMigration: not available",
&Space{ID: "space", OrgID: "org", Name: "test-space", StateInfo: &StateInfo{State: StateMigration}},
false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
spaces := &dummySpaces{space: tt.space}
if err := IsReadAvailable(context.Background(), spaces, "space"); (err != nil) != tt.wantErr {
t.Errorf("IsReadAvailable() error = %v, wantErr %v", err, tt.wantErr)
}
})
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment