github.com/mad-app/mattermost-server@v5.11.1+incompatible/store/storetest/system_store.go (about) 1 // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. 2 // See License.txt for license information. 3 4 package storetest 5 6 import ( 7 "testing" 8 9 "github.com/stretchr/testify/assert" 10 "github.com/stretchr/testify/require" 11 12 "github.com/mattermost/mattermost-server/model" 13 "github.com/mattermost/mattermost-server/store" 14 ) 15 16 func TestSystemStore(t *testing.T, ss store.Store) { 17 t.Run("", func(t *testing.T) { testSystemStore(t, ss) }) 18 t.Run("SaveOrUpdate", func(t *testing.T) { testSystemStoreSaveOrUpdate(t, ss) }) 19 t.Run("PermanentDeleteByName", func(t *testing.T) { testSystemStorePermanentDeleteByName(t, ss) }) 20 } 21 22 func testSystemStore(t *testing.T, ss store.Store) { 23 system := &model.System{Name: model.NewId(), Value: "value"} 24 store.Must(ss.System().Save(system)) 25 26 result := <-ss.System().Get() 27 systems := result.Data.(model.StringMap) 28 29 require.Equal(t, system.Value, systems[system.Name]) 30 31 system.Value = "value2" 32 store.Must(ss.System().Update(system)) 33 34 result2 := <-ss.System().Get() 35 systems2 := result2.Data.(model.StringMap) 36 37 require.Equal(t, system.Value, systems2[system.Name]) 38 39 result3 := <-ss.System().GetByName(system.Name) 40 rsystem := result3.Data.(*model.System) 41 require.Equal(t, system.Value, rsystem.Value) 42 } 43 44 func testSystemStoreSaveOrUpdate(t *testing.T, ss store.Store) { 45 system := &model.System{Name: model.NewId(), Value: "value"} 46 47 if err := (<-ss.System().SaveOrUpdate(system)).Err; err != nil { 48 t.Fatal(err) 49 } 50 51 system.Value = "value2" 52 53 if r := <-ss.System().SaveOrUpdate(system); r.Err != nil { 54 t.Fatal(r.Err) 55 } 56 } 57 58 func testSystemStorePermanentDeleteByName(t *testing.T, ss store.Store) { 59 s1 := &model.System{Name: model.NewId(), Value: "value"} 60 s2 := &model.System{Name: model.NewId(), Value: "value"} 61 62 store.Must(ss.System().Save(s1)) 63 store.Must(ss.System().Save(s2)) 64 65 res1 := <-ss.System().GetByName(s1.Name) 66 assert.Nil(t, res1.Err) 67 68 res2 := <-ss.System().GetByName(s2.Name) 69 assert.Nil(t, res2.Err) 70 71 res3 := <-ss.System().PermanentDeleteByName(s1.Name) 72 assert.Nil(t, res3.Err) 73 74 res4 := <-ss.System().GetByName(s1.Name) 75 assert.NotNil(t, res4.Err) 76 77 res5 := <-ss.System().GetByName(s2.Name) 78 assert.Nil(t, res5.Err) 79 80 res6 := <-ss.System().PermanentDeleteByName(s2.Name) 81 assert.Nil(t, res6.Err) 82 83 res7 := <-ss.System().GetByName(s1.Name) 84 assert.NotNil(t, res7.Err) 85 86 res8 := <-ss.System().GetByName(s2.Name) 87 assert.NotNil(t, res8.Err) 88 89 }