ooni-probe-cli/internal/fsx/example_test.go
Simone Basso acd4ffff35
doc: cleanup and improve for recently moved pkgs (#354)
* chore(atomicx): review docs and add usage example

* chore(fsx): improve docs, return value, add examples

* fix(kvstore): correct typo and add example

* fix(multierror): add basic example

* doc: revamp ooapi documentation
2021-06-04 11:39:00 +02:00

35 lines
631 B
Go

package fsx_test
import (
"errors"
"fmt"
"io"
"log"
"path/filepath"
"syscall"
"github.com/ooni/probe-cli/v3/internal/fsx"
)
func ExampleOpenFile_openingDir() {
filep, err := fsx.OpenFile("testdata")
if !errors.Is(err, syscall.ENOENT) {
log.Fatal("unexpected error", err)
}
if filep != nil {
log.Fatal("expected nil fp")
}
}
func ExampleOpenFile_openingFile() {
filep, err := fsx.OpenFile(filepath.Join("testdata", "testfile.txt"))
if err != nil {
log.Fatal("unexpected error", err)
}
data, err := io.ReadAll(filep)
if err != nil {
log.Fatal("unexpected error", err)
}
fmt.Printf("%d\n", len(data))
}