summaryrefslogtreecommitdiffstats
path: root/modules/queue/queue_test.go
blob: 89ce23ac4c5c7fc7c12a66c22e45fdbf4a672923 (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
// Copyright 2019 The Gitea Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.

package queue

import (
	"testing"

	jsoniter "github.com/json-iterator/go"
	"github.com/stretchr/testify/assert"
)

type testData struct {
	TestString string
	TestInt    int
}

func TestToConfig(t *testing.T) {
	cfg := testData{
		TestString: "Config",
		TestInt:    10,
	}
	exemplar := testData{}

	cfg2I, err := toConfig(exemplar, cfg)
	assert.NoError(t, err)
	cfg2, ok := (cfg2I).(testData)
	assert.True(t, ok)
	assert.NotEqual(t, cfg2, exemplar)
	assert.Equal(t, &cfg, &cfg2)

	json := jsoniter.ConfigCompatibleWithStandardLibrary
	cfgString, err := json.Marshal(cfg)
	assert.NoError(t, err)

	cfg3I, err := toConfig(exemplar, cfgString)
	assert.NoError(t, err)
	cfg3, ok := (cfg3I).(testData)
	assert.True(t, ok)
	assert.Equal(t, cfg.TestString, cfg3.TestString)
	assert.Equal(t, cfg.TestInt, cfg3.TestInt)
	assert.NotEqual(t, cfg3, exemplar)
}