2022-11-08 23:34:27 -07:00
|
|
|
// Copyright 2022 The Gitea Authors. All rights reserved.
|
2022-11-27 11:20:29 -07:00
|
|
|
// SPDX-License-Identifier: MIT
|
2022-11-08 23:34:27 -07:00
|
|
|
|
|
|
|
package setting
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestMustBytes(t *testing.T) {
|
|
|
|
test := func(value string) int64 {
|
2023-05-09 22:57:06 -06:00
|
|
|
cfg, err := NewConfigProviderFromData("[test]")
|
|
|
|
assert.NoError(t, err)
|
|
|
|
sec := cfg.Section("test")
|
2022-11-08 23:34:27 -07:00
|
|
|
sec.NewKey("VALUE", value)
|
|
|
|
|
|
|
|
return mustBytes(sec, "VALUE")
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.EqualValues(t, -1, test(""))
|
|
|
|
assert.EqualValues(t, -1, test("-1"))
|
|
|
|
assert.EqualValues(t, 0, test("0"))
|
|
|
|
assert.EqualValues(t, 1, test("1"))
|
|
|
|
assert.EqualValues(t, 10000, test("10000"))
|
|
|
|
assert.EqualValues(t, 1000000, test("1 mb"))
|
|
|
|
assert.EqualValues(t, 1048576, test("1mib"))
|
|
|
|
assert.EqualValues(t, 1782579, test("1.7mib"))
|
|
|
|
assert.EqualValues(t, -1, test("1 yib")) // too large
|
|
|
|
}
|