mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
embed: treat uninitialized FS as empty
As described in the FS documentation. This prevents http.FS and other clients from panicking when the go:embed directive is missing. For #43682 Related #43698 Change-Id: Iecf26d229a099e55d24670c3119cd6c6d17ecc6e Reviewed-on: https://go-review.googlesource.com/c/go/+/283852 Run-TryBot: Jay Conrod <jayconrod@google.com> TryBot-Result: Go Bot <gobot@golang.org> Trust: Jay Conrod <jayconrod@google.com> Reviewed-by: Bryan C. Mills <bcmills@google.com>
This commit is contained in:
parent
d047c91a6c
commit
ca5774a5a5
2 changed files with 23 additions and 0 deletions
|
|
@ -112,3 +112,20 @@ func TestHidden(t *testing.T) {
|
|||
testDir(t, star, "testdata/.hidden",
|
||||
"fortune.txt", "more/") // but not .more or _more
|
||||
}
|
||||
|
||||
func TestUninitialized(t *testing.T) {
|
||||
var uninitialized embed.FS
|
||||
testDir(t, uninitialized, ".")
|
||||
f, err := uninitialized.Open(".")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer f.Close()
|
||||
fi, err := f.Stat()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !fi.IsDir() {
|
||||
t.Errorf("in uninitialized embed.FS, . is not a directory")
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue