2020-02-15 16:59:43 +08:00
|
|
|
// Copyright 2020 The Gitea Authors. All rights reserved.
|
2022-11-28 02:20:29 +08:00
|
|
|
// SPDX-License-Identifier: MIT
|
2020-02-15 16:59:43 +08:00
|
|
|
|
|
|
|
package models
|
|
|
|
|
|
|
|
import (
|
2021-09-22 13:38:34 +08:00
|
|
|
"os"
|
2020-02-15 16:59:43 +08:00
|
|
|
"path/filepath"
|
|
|
|
"testing"
|
|
|
|
|
2021-11-12 22:36:47 +08:00
|
|
|
"code.gitea.io/gitea/models/unittest"
|
2020-02-15 16:59:43 +08:00
|
|
|
"code.gitea.io/gitea/modules/util"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestFixtureGeneration(t *testing.T) {
|
2021-11-12 22:36:47 +08:00
|
|
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
2020-02-15 16:59:43 +08:00
|
|
|
|
|
|
|
test := func(gen func() (string, error), name string) {
|
|
|
|
expected, err := gen()
|
|
|
|
if !assert.NoError(t, err) {
|
|
|
|
return
|
|
|
|
}
|
2021-11-12 22:36:47 +08:00
|
|
|
bytes, err := os.ReadFile(filepath.Join(unittest.FixturesDir(), name+".yml"))
|
2020-02-15 16:59:43 +08:00
|
|
|
if !assert.NoError(t, err) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
data := string(util.NormalizeEOL(bytes))
|
|
|
|
assert.True(t, data == expected, "Differences detected for %s.yml", name)
|
|
|
|
}
|
|
|
|
|
|
|
|
test(GetYamlFixturesAccess, "access")
|
|
|
|
}
|