2020-02-15 09:59:43 +01:00
|
|
|
// Copyright 2020 The Gitea Authors. All rights reserved.
|
2022-11-27 19:20:29 +01:00
|
|
|
// SPDX-License-Identifier: MIT
|
2020-02-15 09:59:43 +01:00
|
|
|
|
|
|
|
package models
|
|
|
|
|
|
|
|
import (
|
2023-10-15 17:46:06 +02:00
|
|
|
"context"
|
2021-09-22 07:38:34 +02:00
|
|
|
"os"
|
2020-02-15 09:59:43 +01:00
|
|
|
"path/filepath"
|
|
|
|
"testing"
|
|
|
|
|
2023-10-15 17:46:06 +02:00
|
|
|
"code.gitea.io/gitea/models/db"
|
2021-11-12 15:36:47 +01:00
|
|
|
"code.gitea.io/gitea/models/unittest"
|
2020-02-15 09:59:43 +01:00
|
|
|
"code.gitea.io/gitea/modules/util"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2024-07-30 21:41:10 +02:00
|
|
|
"github.com/stretchr/testify/require"
|
2020-02-15 09:59:43 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestFixtureGeneration(t *testing.T) {
|
2024-07-30 21:41:10 +02:00
|
|
|
require.NoError(t, unittest.PrepareTestDatabase())
|
2020-02-15 09:59:43 +01:00
|
|
|
|
2023-10-15 17:46:06 +02:00
|
|
|
test := func(ctx context.Context, gen func(ctx context.Context) (string, error), name string) {
|
|
|
|
expected, err := gen(ctx)
|
2024-07-30 21:41:10 +02:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2023-09-27 05:30:03 +02:00
|
|
|
p := filepath.Join(unittest.FixturesDir(), name+".yml")
|
|
|
|
bytes, err := os.ReadFile(p)
|
2024-07-30 21:41:10 +02:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2020-02-15 09:59:43 +01:00
|
|
|
data := string(util.NormalizeEOL(bytes))
|
2023-09-27 05:30:03 +02:00
|
|
|
assert.EqualValues(t, expected, data, "Differences detected for %s", p)
|
2020-02-15 09:59:43 +01:00
|
|
|
}
|
|
|
|
|
2023-10-15 17:46:06 +02:00
|
|
|
test(db.DefaultContext, GetYamlFixturesAccess, "access")
|
2020-02-15 09:59:43 +01:00
|
|
|
}
|