github.com/mad-app/mattermost-server@v5.11.1+incompatible/store/storetest/license_store.go (about)

     1  // Copyright (c) 2016-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/mattermost/mattermost-server/model"
    10  	"github.com/mattermost/mattermost-server/store"
    11  )
    12  
    13  func TestLicenseStore(t *testing.T, ss store.Store) {
    14  	t.Run("Save", func(t *testing.T) { testLicenseStoreSave(t, ss) })
    15  	t.Run("Get", func(t *testing.T) { testLicenseStoreGet(t, ss) })
    16  }
    17  
    18  func testLicenseStoreSave(t *testing.T, ss store.Store) {
    19  	l1 := model.LicenseRecord{}
    20  	l1.Id = model.NewId()
    21  	l1.Bytes = "junk"
    22  
    23  	if err := (<-ss.License().Save(&l1)).Err; err != nil {
    24  		t.Fatal("couldn't save license record", err)
    25  	}
    26  
    27  	if err := (<-ss.License().Save(&l1)).Err; err != nil {
    28  		t.Fatal("shouldn't fail on trying to save existing license record", err)
    29  	}
    30  
    31  	l1.Id = ""
    32  
    33  	if err := (<-ss.License().Save(&l1)).Err; err == nil {
    34  		t.Fatal("should fail on invalid license", err)
    35  	}
    36  }
    37  
    38  func testLicenseStoreGet(t *testing.T, ss store.Store) {
    39  	l1 := model.LicenseRecord{}
    40  	l1.Id = model.NewId()
    41  	l1.Bytes = "junk"
    42  
    43  	store.Must(ss.License().Save(&l1))
    44  
    45  	if r := <-ss.License().Get(l1.Id); r.Err != nil {
    46  		t.Fatal("couldn't get license", r.Err)
    47  	} else {
    48  		if r.Data.(*model.LicenseRecord).Bytes != l1.Bytes {
    49  			t.Fatal("license bytes didn't match")
    50  		}
    51  	}
    52  
    53  	if err := (<-ss.License().Get("missing")).Err; err == nil {
    54  		t.Fatal("should fail on get license", err)
    55  	}
    56  }