summaryrefslogtreecommitdiffstats
path: root/api/license_test.go
blob: 15d3b9eefbaa8c72eff2904723c315e803835a79 (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
50
// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.

package api

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

func TestGetLicenceConfig(t *testing.T) {
	th := Setup().InitBasic()
	Client := th.BasicClient

	if result, err := Client.GetClientLicenceConfig(""); err != nil {
		t.Fatal(err)
	} else {
		cfg := result.Data.(map[string]string)

		if _, ok := cfg["IsLicensed"]; !ok {
			t.Fatal(cfg)
		}

		// test etag caching
		if cache_result, err := Client.GetClientLicenceConfig(result.Etag); err != nil {
			t.Fatal(err)
		} else if len(cache_result.Data.(map[string]string)) != 0 {
			t.Log(cache_result.Data)
			t.Fatal("cache should be empty")
		}

		utils.SetClientLicense(map[string]string{"IsLicensed": "true"})

		if cache_result, err := Client.GetClientLicenceConfig(result.Etag); err != nil {
			t.Fatal(err)
		} else if len(cache_result.Data.(map[string]string)) == 0 {
			t.Fatal("result should not be empty")
		}

		utils.SetClientLicense(map[string]string{"SomeFeature": "true", "IsLicensed": "true"})

		if cache_result, err := Client.GetClientLicenceConfig(result.Etag); err != nil {
			t.Fatal(err)
		} else if len(cache_result.Data.(map[string]string)) == 0 {
			t.Fatal("result should not be empty")
		}

		utils.SetClientLicense(map[string]string{"IsLicensed": "false"})
	}
}