File: file.go

package info (click to toggle)
rdap 0.9.1-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 608 kB
  • sloc: makefile: 4
file content (42 lines) | stat: -rw-r--r-- 616 bytes parent folder | download
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
// OpenRDAP
// Copyright 2017 Tom Harwood
// MIT License, see the LICENSE file.

package test

import (
	"io/ioutil"
	"log"
	"path"
	"runtime"
)

var testDataPath string

func LoadFile(filename string) []byte {
	var body []byte

	if len(testDataPath) == 0 {
		testDataPath = findTestDataPath()
	}

	body, err := ioutil.ReadFile(path.Join(testDataPath, filename))

	if err != nil {
		log.Panic(err)
	}

	return body
}

func findTestDataPath() string {
	_, filename, _, ok := runtime.Caller(0)
	if !ok {
		log.Panic("runtime.Caller() failed")
	}

	dir, _ := path.Split(filename)

	return path.Join(dir, "testdata")
}