2020-01-07 06:23:09 -05:00
|
|
|
// Copyright 2019 The Gitea Authors. All rights reserved.
|
2022-11-27 13:20:29 -05:00
|
|
|
// SPDX-License-Identifier: MIT
|
2020-01-07 06:23:09 -05:00
|
|
|
|
|
|
|
package queue
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2021-07-24 12:03:58 -04:00
|
|
|
"code.gitea.io/gitea/modules/json"
|
|
|
|
|
2020-01-07 06:23:09 -05:00
|
|
|
"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)
|
|
|
|
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)
|
|
|
|
}
|