test: correctly makes all example tests runnable (#2281)
Signed-off-by: Takeshi Yoneda <t.y.mathetake@gmail.com>
This commit is contained in:
2
Makefile
2
Makefile
@@ -187,7 +187,7 @@ golangci_lint_goarch ?= $(shell go env GOARCH)
|
|||||||
|
|
||||||
.PHONY: lint
|
.PHONY: lint
|
||||||
lint: $(golangci_lint_path)
|
lint: $(golangci_lint_path)
|
||||||
@GOARCH=$(golangci_lint_goarch) CGO_ENABLED=0 $(golangci_lint_path) run --timeout 5m
|
@GOARCH=$(golangci_lint_goarch) CGO_ENABLED=0 $(golangci_lint_path) run --timeout 5m -E testableexamples
|
||||||
|
|
||||||
.PHONY: format
|
.PHONY: format
|
||||||
format:
|
format:
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ var ctx context.Context
|
|||||||
func Example_closeNotifier() {
|
func Example_closeNotifier() {
|
||||||
closeCh := make(chan struct{})
|
closeCh := make(chan struct{})
|
||||||
ctx = experimental.WithCloseNotifier(
|
ctx = experimental.WithCloseNotifier(
|
||||||
ctx,
|
context.Background(),
|
||||||
experimental.CloseNotifyFunc(func(context.Context, uint32) { close(closeCh) }),
|
experimental.CloseNotifyFunc(func(context.Context, uint32) { close(closeCh) }),
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -24,4 +24,6 @@ func Example_closeNotifier() {
|
|||||||
default:
|
default:
|
||||||
// do some more work with the module
|
// do some more work with the module
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Output:
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,6 +20,8 @@ func ExampleAdaptFS() {
|
|||||||
|
|
||||||
moduleConfig = wazero.NewModuleConfig().
|
moduleConfig = wazero.NewModuleConfig().
|
||||||
WithFSConfig(wazero.NewFSConfig().(sysfs.FSConfig).WithSysFSMount(root, "/"))
|
WithFSConfig(wazero.NewFSConfig().(sysfs.FSConfig).WithSysFSMount(root, "/"))
|
||||||
|
|
||||||
|
// Output:
|
||||||
}
|
}
|
||||||
|
|
||||||
// This example shows how to configure a sysfs.DirFS
|
// This example shows how to configure a sysfs.DirFS
|
||||||
@@ -28,6 +30,8 @@ func ExampleDirFS() {
|
|||||||
|
|
||||||
moduleConfig = wazero.NewModuleConfig().
|
moduleConfig = wazero.NewModuleConfig().
|
||||||
WithFSConfig(wazero.NewFSConfig().(sysfs.FSConfig).WithSysFSMount(root, "/"))
|
WithFSConfig(wazero.NewFSConfig().(sysfs.FSConfig).WithSysFSMount(root, "/"))
|
||||||
|
|
||||||
|
// Output:
|
||||||
}
|
}
|
||||||
|
|
||||||
// This example shows how to configure a sysfs.ReadFS
|
// This example shows how to configure a sysfs.ReadFS
|
||||||
@@ -37,4 +41,6 @@ func ExampleReadFS() {
|
|||||||
|
|
||||||
moduleConfig = wazero.NewModuleConfig().
|
moduleConfig = wazero.NewModuleConfig().
|
||||||
WithFSConfig(wazero.NewFSConfig().(sysfs.FSConfig).WithSysFSMount(readOnly, "/"))
|
WithFSConfig(wazero.NewFSConfig().(sysfs.FSConfig).WithSysFSMount(readOnly, "/"))
|
||||||
|
|
||||||
|
// Output:
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,4 +24,6 @@ func Example_fsConfig() {
|
|||||||
moduleConfig = wazero.NewModuleConfig().
|
moduleConfig = wazero.NewModuleConfig().
|
||||||
// Make "index.html" accessible to the guest as "/index.html".
|
// Make "index.html" accessible to the guest as "/index.html".
|
||||||
WithFSConfig(wazero.NewFSConfig().WithFSMount(rooted, "/"))
|
WithFSConfig(wazero.NewFSConfig().WithFSMount(rooted, "/"))
|
||||||
|
|
||||||
|
// Output:
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,38 +0,0 @@
|
|||||||
package sys_test
|
|
||||||
|
|
||||||
import (
|
|
||||||
"io/fs"
|
|
||||||
"math"
|
|
||||||
|
|
||||||
"github.com/tetratelabs/wazero/sys"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
walltime sys.Walltime
|
|
||||||
info fs.FileInfo
|
|
||||||
st sys.Stat_t
|
|
||||||
)
|
|
||||||
|
|
||||||
// This shows typical conversions to sys.EpochNanos type, for sys.Stat_t fields.
|
|
||||||
func Example_epochNanos() {
|
|
||||||
// Convert an adapted fs.File's fs.FileInfo to Mtim.
|
|
||||||
st.Mtim = info.ModTime().UnixNano()
|
|
||||||
|
|
||||||
// Generate a fake Atim using sys.Walltime passed to wazero.ModuleConfig.
|
|
||||||
sec, nsec := walltime()
|
|
||||||
st.Atim = sec*1e9 + int64(nsec)
|
|
||||||
}
|
|
||||||
|
|
||||||
type fileInfoWithSys struct {
|
|
||||||
fs.FileInfo
|
|
||||||
st sys.Stat_t
|
|
||||||
}
|
|
||||||
|
|
||||||
func (f *fileInfoWithSys) Sys() any { return &f.st }
|
|
||||||
|
|
||||||
// This shows how to return data not defined in fs.FileInfo, notably sys.Inode.
|
|
||||||
func Example_inode() {
|
|
||||||
st := sys.NewStat_t(info)
|
|
||||||
st.Ino = math.MaxUint64 // arbitrary non-zero value
|
|
||||||
info = &fileInfoWithSys{info, st}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user