github.com/haalcala/mattermost-server-change-repo@v0.0.0-20210713015153-16753fbeee5f/store/storetest/license_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/require" 10 11 "github.com/mattermost/mattermost-server/v5/model" 12 "github.com/mattermost/mattermost-server/v5/store" 13 ) 14 15 func TestLicenseStore(t *testing.T, ss store.Store) { 16 t.Run("Save", func(t *testing.T) { testLicenseStoreSave(t, ss) }) 17 t.Run("Get", func(t *testing.T) { testLicenseStoreGet(t, ss) }) 18 } 19 20 func testLicenseStoreSave(t *testing.T, ss store.Store) { 21 l1 := model.LicenseRecord{} 22 l1.Id = model.NewId() 23 l1.Bytes = "junk" 24 25 _, err := ss.License().Save(&l1) 26 require.NoError(t, err, "couldn't save license record") 27 28 _, err = ss.License().Save(&l1) 29 require.NoError(t, err, "shouldn't fail on trying to save existing license record") 30 31 l1.Id = "" 32 33 _, err = ss.License().Save(&l1) 34 require.Error(t, err, "should fail on invalid license") 35 } 36 37 func testLicenseStoreGet(t *testing.T, ss store.Store) { 38 l1 := model.LicenseRecord{} 39 l1.Id = model.NewId() 40 l1.Bytes = "junk" 41 42 _, err := ss.License().Save(&l1) 43 require.NoError(t, err) 44 45 record, err := ss.License().Get(l1.Id) 46 require.NoError(t, err, "couldn't get license") 47 48 require.Equal(t, record.Bytes, l1.Bytes, "license bytes didn't match") 49 50 _, err = ss.License().Get("missing") 51 require.Error(t, err, "should fail on get license") 52 }