github.com/tetratelabs/wazero@v1.7.3-0.20240513003603-48f702e154b5/experimental/sysfs/config_example_test.go (about) 1 package sysfs_test 2 3 import ( 4 "io/fs" 5 "testing/fstest" 6 7 "github.com/tetratelabs/wazero" 8 "github.com/tetratelabs/wazero/experimental/sysfs" 9 ) 10 11 var moduleConfig wazero.ModuleConfig 12 13 // This example shows how to adapt a fs.FS to a sys.FS 14 func ExampleAdaptFS() { 15 m := fstest.MapFS{ 16 "a/b.txt": &fstest.MapFile{Mode: 0o666}, 17 ".": &fstest.MapFile{Mode: 0o777 | fs.ModeDir}, 18 } 19 root := &sysfs.AdaptFS{FS: m} 20 21 moduleConfig = wazero.NewModuleConfig(). 22 WithFSConfig(wazero.NewFSConfig().(sysfs.FSConfig).WithSysFSMount(root, "/")) 23 } 24 25 // This example shows how to configure a sysfs.DirFS 26 func ExampleDirFS() { 27 root := sysfs.DirFS(".") 28 29 moduleConfig = wazero.NewModuleConfig(). 30 WithFSConfig(wazero.NewFSConfig().(sysfs.FSConfig).WithSysFSMount(root, "/")) 31 } 32 33 // This example shows how to configure a sysfs.ReadFS 34 func ExampleReadFS() { 35 root := sysfs.DirFS(".") 36 readOnly := &sysfs.ReadFS{FS: root} 37 38 moduleConfig = wazero.NewModuleConfig(). 39 WithFSConfig(wazero.NewFSConfig().(sysfs.FSConfig).WithSysFSMount(readOnly, "/")) 40 }