Skip to content

Commit 3919780

Browse files
authored
make f.Root path absolute (#3465)
1 parent 8e434ad commit 3919780

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

pkg/functions/client_test.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -556,8 +556,8 @@ func TestClient_New_ImageRegistryDefaults(t *testing.T) {
556556
// Deploy (and confirms expected fields calculated).
557557
func TestClient_New_Delegation(t *testing.T) {
558558
var (
559-
root = "testdata/example.com/test-new-delegates" // .. in which to initialize
560-
expectedName = "test-new-delegates" // expected to be derived
559+
root = absPath("testdata/example.com/test-new-delegates") // .. in which to initialize
560+
expectedName = "test-new-delegates" // expected to be derived
561561
expectedImage = "example.com/alice/test-new-delegates:latest"
562562
builder = mock.NewBuilder()
563563
pusher = mock.NewPusher()
@@ -642,7 +642,7 @@ func TestClient_New_Delegation(t *testing.T) {
642642
// See TestClient_Runner for the test of the default runner implementation.
643643
func TestClient_Run(t *testing.T) {
644644
// Create the root function directory
645-
root := "testdata/example.com/test-run"
645+
root := absPath("testdata/example.com/test-run")
646646
defer Using(t, root)()
647647

648648
// client with the mock runner and the new test function
@@ -2235,3 +2235,11 @@ func TestClient_BuildPopulatesRuntimeImage(t *testing.T) {
22352235
t.Fatalf("written image in ./.func/built-image '%s' does not match expected '%s'", got, expect)
22362236
}
22372237
}
2238+
2239+
func absPath(p string) string {
2240+
abs, err := filepath.Abs(p)
2241+
if err != nil {
2242+
panic(err)
2243+
}
2244+
return abs
2245+
}

pkg/functions/function.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ type Function struct {
5656
// For details see the .Migrated() and .Migrate() methods.
5757
SpecVersion string `yaml:"specVersion"` // semver format
5858

59-
// Root on disk at which to find/create source and config files.
59+
// Root is the absolute path on disk at which to find/create source and
60+
// config files.
6061
Root string `yaml:"-"`
6162

6263
// Name of the function.
@@ -271,6 +272,9 @@ func NewFunction(root string) (f Function, err error) {
271272
return
272273
}
273274
}
275+
if root, err = filepath.Abs(root); err != nil {
276+
return
277+
}
274278
f.Root = root // path is not persisted, as this is the purview of the FS
275279

276280
// Path must exist and be a directory

0 commit comments

Comments
 (0)