code.gitea.io/gitea@v1.19.3/modules/migration/schemas_dynamic.go (about) 1 // Copyright 2022 The Gitea Authors. All rights reserved. 2 // SPDX-License-Identifier: MIT 3 4 //go:build !bindata 5 6 package migration 7 8 import ( 9 "io" 10 "net/url" 11 "os" 12 "path" 13 "path/filepath" 14 ) 15 16 func openSchema(s string) (io.ReadCloser, error) { 17 u, err := url.Parse(s) 18 if err != nil { 19 return nil, err 20 } 21 basename := path.Base(u.Path) 22 filename := basename 23 // 24 // Schema reference each other within the schemas directory but 25 // the tests run in the parent directory. 26 // 27 if _, err := os.Stat(filename); os.IsNotExist(err) { 28 filename = 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 // 33 if _, err := os.Stat(filename); os.IsNotExist(err) { 34 filename = filepath.Join("modules/migration/schemas", basename) 35 } 36 } 37 return os.Open(filename) 38 }