aboutsummaryrefslogtreecommitdiff
path: root/internal/conf/conf_test.go
blob: 1ac64d6cc62b74ed857f8478ed45dd0d7b76a516 (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
51
52
53
54
55
56
57
58
59
60
61
62
63
// Copyright 2020 The Gogs 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 conf

import (
	"bytes"
	"path/filepath"
	"testing"

	"github.com/stretchr/testify/assert"
	"gopkg.in/ini.v1"

	"gogs.io/gogs/internal/testutil"
)

func TestInit(t *testing.T) {
	ini.PrettyFormat = false
	defer func() {
		MustInit("")
		ini.PrettyFormat = true
	}()

	assert.Nil(t, Init(filepath.Join("testdata", "custom.ini")))

	cfg := ini.Empty()
	cfg.NameMapper = ini.SnackCase

	for _, v := range []struct {
		section string
		config  interface{}
	}{
		{"", &App},
		{"server", &Server},
		{"server", &SSH},
		{"repository", &Repository},
		{"database", &Database},
		{"security", &Security},
		{"email", &Email},
		{"auth", &Auth},
		{"user", &User},
		{"session", &Session},
		{"attachment", &Attachment},
		{"time", &Time},
		{"picture", &Picture},
		{"mirror", &Mirror},
		{"i18n", &I18n},
	} {
		err := cfg.Section(v.section).ReflectFrom(v.config)
		if err != nil {
			t.Fatalf("%s: %v", v.section, err)
		}
	}

	buf := new(bytes.Buffer)
	_, err := cfg.WriteTo(buf)
	if err != nil {
		t.Fatal(err)
	}

	testutil.AssertGolden(t, filepath.Join("testdata", "TestInit.golden.ini"), testutil.Update("TestInit"), buf.String())
}