2021-06-04 11:39:00 +02:00
|
|
|
package fsx_test
|
|
|
|
|
|
|
|
import (
|
2021-06-15 13:44:28 +02:00
|
|
|
"context"
|
2021-06-04 11:39:00 +02:00
|
|
|
"errors"
|
|
|
|
"fmt"
|
|
|
|
"log"
|
|
|
|
"path/filepath"
|
|
|
|
"syscall"
|
|
|
|
|
|
|
|
"github.com/ooni/probe-cli/v3/internal/fsx"
|
2021-09-28 12:42:01 +02:00
|
|
|
"github.com/ooni/probe-cli/v3/internal/netxlite"
|
2021-06-04 11:39:00 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
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)
|
|
|
|
}
|
2021-09-28 12:42:01 +02:00
|
|
|
data, err := netxlite.ReadAllContext(context.Background(), filep)
|
2021-06-04 11:39:00 +02:00
|
|
|
if err != nil {
|
|
|
|
log.Fatal("unexpected error", err)
|
|
|
|
}
|
|
|
|
fmt.Printf("%d\n", len(data))
|
|
|
|
}
|