Skip to content
Snippets Groups Projects
Select Git revision
  • 17275cca8dea3a8373a4443af51e71e0dd7c9f51
  • master default protected
  • refactor/PRXS-3053-Files
  • feature/PRXS-3143-3235-ReferenceOptions
  • feature/PRXS-3421-ImplementNewRefAPI
  • feature/PRXS-3143-LimitReferenceFields
  • feature/PRXS-3234-FeaturePruneIdents
  • feature/3149-LocaleCodeAsID-Feature
  • feature/PRXS-3383-CollectionsRankSortAPI
  • PRXS-3421-RecursiveReferences
  • feature/PRXS-3383-CollectionsSort
  • feature/3109-SerializeFeature
  • release/0.33
  • feature/3109-RecoverySchema
  • feature/3109-feature
  • fix/PRXS-3369-ValidateFields
  • refactor/PRXS-3306-MovePkgGroup1
  • refactor/6-pkg-refactor-expr
  • fix/PRXS-3360-TemplateBuilderPatch
  • feature/3293-MongoV2
  • feature/3272-GoVersionUp
  • v0.33.1
  • v0.32.0
  • v0.31.1
  • v0.31.0
  • v0.30.0
  • v0.29.0
  • v0.28.0
  • v0.27.0-alpha.1+16
  • v0.27.0-alpha.1+15
  • v0.27.0-alpha.1+14
  • v0.27.0-alpha.1+13
  • v0.27.0-alpha.1+12
  • v0.27.0-alpha.1+11
  • v0.27.0-alpha.1+10
  • v0.27.0-alpha.1+9
  • v0.27.0-alpha.1+8
  • v0.27.0-alpha.1+7
  • v0.27.0-alpha.1+6
  • v0.27.0-alpha.1+5
  • v0.27.0-alpha.1+4
41 results

service_test.go

Blame
  • user avatar
    ko_oler authored
    17275cca
    History
    service_test.go 2.44 KiB
    package spaces
    
    import (
    	"context"
    	"testing"
    )
    
    // dummySpaces используется для имитации поведения Spaces
    // Моки использовать не можем, так как получается циклический импорт
    type dummySpaces struct {
    	Spaces
    	space *Space
    }
    
    func (t *dummySpaces) Get(_ context.Context, _ string) (*Space, error) { return t.space, nil }
    
    func TestIsSpaceAvailable(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}},
    			true,
    		},
    	}
    	for _, tt := range tests {
    		t.Run(tt.name, func(t *testing.T) {
    			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)
    			}
    		})
    	}
    }
    
    func TestIsSpaceReadable(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 := IsSpaceReadable(context.Background(), spaces, "space"); (err != nil) != tt.wantErr {
    				t.Errorf("IsSpaceReadable() error = %v, wantErr %v", err, tt.wantErr)
    			}
    		})
    	}
    }