github.com/qichengzx/mattermost-server@v4.5.1-0.20180604164826-2c75247c97d0+incompatible/store/sqlstore/upgrade_test.go (about)

     1  // Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved.
     2  // See License.txt for license information.
     3  
     4  package sqlstore
     5  
     6  import (
     7  	"testing"
     8  
     9  	"github.com/mattermost/mattermost-server/model"
    10  	"github.com/mattermost/mattermost-server/store"
    11  )
    12  
    13  func TestStoreUpgrade(t *testing.T) {
    14  	StoreTest(t, func(t *testing.T, ss store.Store) {
    15  		saveSchemaVersion(ss.(*store.LayeredStore).DatabaseLayer.(SqlStore), VERSION_3_0_0)
    16  		UpgradeDatabase(ss.(*store.LayeredStore).DatabaseLayer.(SqlStore))
    17  
    18  		saveSchemaVersion(ss.(*store.LayeredStore).DatabaseLayer.(SqlStore), "")
    19  		UpgradeDatabase(ss.(*store.LayeredStore).DatabaseLayer.(SqlStore))
    20  	})
    21  }
    22  
    23  func TestSaveSchemaVersion(t *testing.T) {
    24  	StoreTest(t, func(t *testing.T, ss store.Store) {
    25  		saveSchemaVersion(ss.(*store.LayeredStore).DatabaseLayer.(SqlStore), VERSION_3_0_0)
    26  		if result := <-ss.System().Get(); result.Err != nil {
    27  			t.Fatal(result.Err)
    28  		} else {
    29  			props := result.Data.(model.StringMap)
    30  			if props["Version"] != VERSION_3_0_0 {
    31  				t.Fatal("version not updated")
    32  			}
    33  		}
    34  
    35  		if ss.(*store.LayeredStore).DatabaseLayer.(SqlStore).GetCurrentSchemaVersion() != VERSION_3_0_0 {
    36  			t.Fatal("version not updated")
    37  		}
    38  
    39  		saveSchemaVersion(ss.(*store.LayeredStore).DatabaseLayer.(SqlStore), model.CurrentVersion)
    40  	})
    41  }