summaryrefslogtreecommitdiffstats
path: root/store/sql_system_store_test.go
blob: ce149e97ab543e89498eaee8a0cf8a000543dcbb (plain)
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
// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.

package store

import (
	"github.com/mattermost/platform/model"
	"testing"
)

func TestSqlSystemStore(t *testing.T) {
	Setup()

	system := &model.System{Name: model.NewId(), Value: "value"}
	Must(store.System().Save(system))

	result := <-store.System().Get()
	systems := result.Data.(model.StringMap)

	if systems[system.Name] != system.Value {
		t.Fatal()
	}

	system.Value = "value2"
	Must(store.System().Update(system))

	result2 := <-store.System().Get()
	systems2 := result2.Data.(model.StringMap)

	if systems2[system.Name] != system.Value {
		t.Fatal()
	}
}

func TestSqlSystemStoreSaveOrUpdate(t *testing.T) {
	Setup()

	system := &model.System{Name: model.NewId(), Value: "value"}

	if err := (<-store.System().SaveOrUpdate(system)).Err; err != nil {
		t.Fatal(err)
	}

	system.Value = "value2"

	if r := <-store.System().SaveOrUpdate(system); r.Err != nil {
		t.Fatal(r.Err)
	}
}