The testing resource name may be hard coded but the path doesn't have to be.
(09:13) jnml@fsc-r550:~/src/tmp/SO/13854048$ ls -a
. .. a_test.go
(09:13) jnml@fsc-r550:~/src/tmp/SO/13854048$ cat a_test.go
package foo
import (
"testing"
"io/ioutil"
)
func Test(t *testing.T) {
b, err := ioutil.ReadFile("foo")
if err != nil {
t.Fatal(err)
}
t.Logf("resource content is: %s", b)
}
(09:13) jnml@fsc-r550:~/src/tmp/SO/13854048$ go test -v
=== RUN Test
--- FAIL: Test (0.00 seconds)
a_test.go:11: open foo: no such file or directory
FAIL
exit status 1
FAIL tmp/SO/13854048 0.005s
(09:14) jnml@fsc-r550:~/src/tmp/SO/13854048$
Correct, no such resource (yet). Let's create it.
(09:14) jnml@fsc-r550:~/src/tmp/SO/13854048$ echo blah > foo
(09:14) jnml@fsc-r550:~/src/tmp/SO/13854048$ go test -v
=== RUN Test
--- PASS: Test (0.00 seconds)
a_test.go:14: resource content is: blah
PASS
ok tmp/SO/13854048 0.007s
(09:14) jnml@fsc-r550:~/src/tmp/SO/13854048$ cd
(09:14) jnml@fsc-r550:~$ go test -v tmp/SO/13854048
=== RUN Test
--- PASS: Test (0.00 seconds)
a_test.go:14: resource content is: blah
PASS
ok tmp/SO/13854048 0.005s
(09:14) jnml@fsc-r550:~$
Note (in the last run above) that the cwd is correct even when go test
is invoked from elsewhere.