github.com/xzl8028/xenia-server@v0.0.0-20190809101854-18450a97da63/store/storetest/license_store.go (about) 1 // Copyright (c) 2016-present Xenia, Inc. All Rights Reserved. 2 // See License.txt for license information. 3 4 package storetest 5 6 import ( 7 "testing" 8 9 "github.com/xzl8028/xenia-server/model" 10 "github.com/xzl8028/xenia-server/store" 11 "github.com/stretchr/testify/require" 12 ) 13 14 func TestLicenseStore(t *testing.T, ss store.Store) { 15 t.Run("Save", func(t *testing.T) { testLicenseStoreSave(t, ss) }) 16 t.Run("Get", func(t *testing.T) { testLicenseStoreGet(t, ss) }) 17 } 18 19 func testLicenseStoreSave(t *testing.T, ss store.Store) { 20 l1 := model.LicenseRecord{} 21 l1.Id = model.NewId() 22 l1.Bytes = "junk" 23 24 if _, err := ss.License().Save(&l1); err != nil { 25 t.Fatal("couldn't save license record", err) 26 } 27 28 if _, err := ss.License().Save(&l1); err != nil { 29 t.Fatal("shouldn't fail on trying to save existing license record", err) 30 } 31 32 l1.Id = "" 33 34 if _, err := ss.License().Save(&l1); err == nil { 35 t.Fatal("should fail on invalid license", err) 36 } 37 } 38 39 func testLicenseStoreGet(t *testing.T, ss store.Store) { 40 l1 := model.LicenseRecord{} 41 l1.Id = model.NewId() 42 l1.Bytes = "junk" 43 44 _, err := ss.License().Save(&l1) 45 require.Nil(t, err) 46 47 if record, err := ss.License().Get(l1.Id); err != nil { 48 t.Fatal("couldn't get license", err) 49 } else { 50 if record.Bytes != l1.Bytes { 51 t.Fatal("license bytes didn't match") 52 } 53 } 54 55 if _, err := ss.License().Get("missing"); err == nil { 56 t.Fatal("should fail on get license", err) 57 } 58 }