Skip to content

Commit

Permalink
test: tune examples for unix and windows
Browse files Browse the repository at this point in the history
Signed-off-by: Mark Sagi-Kazar <mark.sagikazar@gmail.com>
  • Loading branch information
sagikazarmark committed Jun 4, 2024
1 parent 39ac328 commit ecfb568
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 23 deletions.
32 changes: 32 additions & 0 deletions example_unix_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//go:build !windows && !plan9

package locafero

import (
"fmt"

"github.com/spf13/afero"
)

func ExampleFinder_Find() {
fsys := afero.NewBasePathFs(afero.NewOsFs(), "testdata")

finder := Finder{
Paths: []string{
"/home/user",
"/etc",
},
Names: []string{"config.*"},
Type: FileTypeFile,
}

results, err := finder.Find(fsys)
if err != nil {
panic(err)
}

fmt.Println("On Unix:", results)

// Output:
// On Unix: [/home/user/config.yaml /etc/config.yaml]
}
34 changes: 34 additions & 0 deletions example_windows_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//go:build windows

package locafero

import (
"fmt"

"github.com/spf13/afero"
)

func ExampleFinder_Find() {
// Use relative paths for Windows, because we do not know the absolute path.
// fsys := afero.NewBasePathFs(afero.NewOsFs(), "testdata")
fsys := afero.NewOsFs()

finder := Finder{
Paths: []string{
"testdata\\home\\user",
"testdata\\etc",
},
Names: []string{"config.*"},
Type: FileTypeFile,
}

results, err := finder.Find(fsys)
if err != nil {
panic(err)
}

fmt.Println("On Windows:", results)

// Output:
// On Windows: [testdata\home\user\config.yaml testdata\etc\config.yaml]
}
23 changes: 0 additions & 23 deletions finder_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package locafero

import (
"fmt"
"os"
"path"
"path/filepath"
Expand All @@ -13,28 +12,6 @@ import (
"github.com/stretchr/testify/require"
)

func Example() {
fsys := afero.NewBasePathFs(afero.NewOsFs(), "testdata")

finder := Finder{
Paths: []string{
"/home/user",
"/etc",
},
Names: []string{"config.*"},
Type: FileTypeFile,
}

results, err := finder.Find(fsys)
if err != nil {
panic(err)
}

fmt.Print(results)

// Output: [/home/user/config.yaml /etc/config.yaml]
}

func TestFinder_Find(t *testing.T) {
fsys := afero.NewMemMapFs()

Expand Down

0 comments on commit ecfb568

Please sign in to comment.