-
Notifications
You must be signed in to change notification settings - Fork 7.1k
/
license_store.go
51 lines (37 loc) · 1.33 KB
/
license_store.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package storetest
import (
"testing"
"github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/store"
"github.com/stretchr/testify/require"
)
func TestLicenseStore(t *testing.T, ss store.Store) {
t.Run("Save", func(t *testing.T) { testLicenseStoreSave(t, ss) })
t.Run("Get", func(t *testing.T) { testLicenseStoreGet(t, ss) })
}
func testLicenseStoreSave(t *testing.T, ss store.Store) {
l1 := model.LicenseRecord{}
l1.Id = model.NewId()
l1.Bytes = "junk"
_, err := ss.License().Save(&l1)
require.Nil(t, err, "couldn't save license record")
_, err = ss.License().Save(&l1)
require.Nil(t, err, "shouldn't fail on trying to save existing license record")
l1.Id = ""
_, err = ss.License().Save(&l1)
require.NotNil(t, err, "should fail on invalid license")
}
func testLicenseStoreGet(t *testing.T, ss store.Store) {
l1 := model.LicenseRecord{}
l1.Id = model.NewId()
l1.Bytes = "junk"
_, err := ss.License().Save(&l1)
require.Nil(t, err)
record, err := ss.License().Get(l1.Id)
require.Nil(t, err, "couldn't get license")
require.Equal(t, record.Bytes, l1.Bytes, "license bytes didn't match")
_, err = ss.License().Get("missing")
require.NotNil(t, err, "should fail on get license")
}