github.com/m3db/m3@v1.5.1-0.20231129193456-75a402aa583b/src/dbnode/storage/bootstrap/bootstrapper/fs/migrator/options_test.go (about) 1 // Copyright (c) 2020 Uber Technologies, Inc. 2 // 3 // Permission is hereby granted, free of charge, to any person obtaining a copy 4 // of this software and associated documentation files (the "Software"), to deal 5 // in the Software without restriction, including without limitation the rights 6 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 // copies of the Software, and to permit persons to whom the Software is 8 // furnished to do so, subject to the following conditions: 9 // 10 // The above copyright notice and this permission notice shall be included in 11 // all copies or substantial portions of the Software. 12 // 13 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 // THE SOFTWARE. 20 21 package migrator 22 23 import ( 24 "testing" 25 26 "github.com/m3db/m3/src/dbnode/persist/fs" 27 "github.com/m3db/m3/src/dbnode/persist/fs/migration" 28 "github.com/m3db/m3/src/dbnode/storage" 29 "github.com/m3db/m3/src/dbnode/storage/bootstrap" 30 xtest "github.com/m3db/m3/src/x/test" 31 32 "github.com/golang/mock/gomock" 33 "github.com/stretchr/testify/require" 34 ) 35 36 func TestOptionsValidateStorageOptions(t *testing.T) { 37 ctrl := xtest.NewController(t) 38 defer ctrl.Finish() 39 40 opts := newTestOptions(ctrl) 41 require.NoError(t, opts.Validate()) 42 43 opts = opts.SetStorageOptions(nil) 44 require.Error(t, opts.Validate()) 45 46 opts = opts.SetStorageOptions(storage.DefaultTestOptions()) 47 require.Error(t, opts.Validate()) 48 } 49 50 func TestOptionsValidateMigrationTaskFn(t *testing.T) { 51 ctrl := xtest.NewController(t) 52 defer ctrl.Finish() 53 54 opts := newTestOptions(ctrl) 55 require.NoError(t, opts.Validate()) 56 57 opts = opts.SetMigrationTaskFn(nil) 58 require.Error(t, opts.Validate()) 59 } 60 61 func TestOptionsValidateInfoFilesByNamespace(t *testing.T) { 62 ctrl := xtest.NewController(t) 63 defer ctrl.Finish() 64 65 opts := newTestOptions(ctrl) 66 require.NoError(t, opts.Validate()) 67 68 opts = opts.SetInfoFilesByNamespace(nil) 69 require.Error(t, opts.Validate()) 70 } 71 72 func TestOptionsValidateMigrationOpts(t *testing.T) { 73 ctrl := xtest.NewController(t) 74 defer ctrl.Finish() 75 76 opts := newTestOptions(ctrl) 77 require.NoError(t, opts.Validate()) 78 79 opts = opts.SetMigrationOptions(nil) 80 require.Error(t, opts.Validate()) 81 } 82 83 func TestOptionsValidateInstrumentOpts(t *testing.T) { 84 ctrl := xtest.NewController(t) 85 defer ctrl.Finish() 86 87 opts := newTestOptions(ctrl) 88 require.NoError(t, opts.Validate()) 89 90 opts = opts.SetInstrumentOptions(nil) 91 require.Error(t, opts.Validate()) 92 } 93 94 func TestOptionsValidateFilesystemOpts(t *testing.T) { 95 ctrl := xtest.NewController(t) 96 defer ctrl.Finish() 97 98 opts := newTestOptions(ctrl) 99 require.NoError(t, opts.Validate()) 100 101 opts = opts.SetFilesystemOptions(nil) 102 require.Error(t, opts.Validate()) 103 } 104 105 func newTestOptions(ctrl *gomock.Controller) Options { 106 mockOpts := storage.NewMockOptions(ctrl) 107 mockOpts.EXPECT().Validate().AnyTimes() 108 109 return NewOptions(). 110 SetMigrationTaskFn(func(result fs.ReadInfoFileResult) (migration.NewTaskFn, bool) { 111 return nil, false 112 }). 113 SetInfoFilesByNamespace(make(bootstrap.InfoFilesByNamespace)). 114 SetStorageOptions(mockOpts). 115 SetFilesystemOptions(fs.NewOptions()) 116 }