gitech
1// Copyright 2022 The Gitea Authors. All rights reserved.
2// SPDX-License-Identifier: MIT
3
4//go:build !bindata
5
6package migration
7
8import (
9"io"
10"net/url"
11"os"
12"path"
13"path/filepath"
14)
15
16func openSchema(s string) (io.ReadCloser, error) {
17u, err := url.Parse(s)
18if err != nil {
19return nil, err
20}
21basename := path.Base(u.Path)
22filename := basename
23//
24// Schema reference each other within the schemas directory but
25// the tests run in the parent directory.
26//
27if _, err := os.Stat(filename); os.IsNotExist(err) {
28filename = filepath.Join("schemas", basename)
29//
30// Integration tests run from the git root directory, not the
31// directory in which the test source is located.
32//
33if _, err := os.Stat(filename); os.IsNotExist(err) {
34filename = filepath.Join("modules/migration/schemas", basename)
35}
36}
37return os.Open(filename)
38}
39