Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ func Translate(c *Config) error {
}

var knownFuncs = make(map[string]int)
var visitedPaths = make(map[string]bool)
// Locate all the assets.
for _, input := range c.Input {
var visitedPaths = make(map[string]bool)
if err := findFiles(input.Path, c.Prefix, input.Recursive, &toc, c.Ignore, knownFuncs, visitedPaths); err != nil {
return err
}
Expand Down
35 changes: 35 additions & 0 deletions convert_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package bindata

import (
"os"
"regexp"
"strings"
"testing"
Expand Down Expand Up @@ -134,3 +135,37 @@ func TestNoPrefixExtensionMatch(t *testing.T) {
t.Fatal("should have returned err retrieving nonexistent file, got nil")
}
}

func TestTranslate(t *testing.T) {
t.Run("multiple symlinks pointing to the same file", func(t *testing.T) {
// Build the config.
c := NewConfig()
c.Input = []InputConfig{
{Path: "testdata/symlinkFile", Recursive: true},
{Path: "testdata/symlinkFileDup", Recursive: true},
}
c.Output = "testdata/symlink_test.go" // Dummy value that isn't used

// Stub out implementation for diffAndWrite.
var output string
oldDiffAndWrite := diffAndWrite
diffAndWrite = func(filename string, data []byte, mode os.FileMode) error {
output = string(data)
return nil
}
defer func() { diffAndWrite = oldDiffAndWrite }()

if err := Translate(c); err != nil {
t.Fatal(err)
}

if len(output) == 0 {
t.Fatal("should have data in output file")
}

if !strings.Contains(output, "testdata/symlinkFile/file1") ||
!strings.Contains(output, "testdata/symlinkFileDup/file1") {
t.Fatal("should have data for both symlinkFile and symlinkFileDup")
}
})
}
5 changes: 4 additions & 1 deletion filewriter.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ import (
"os"
)

func diffAndWrite(filename string, data []byte, mode os.FileMode) error {
// Note: diffAndWrite is doubled for testing purposes.
var diffAndWrite = diffAndWriteImpl

func diffAndWriteImpl(filename string, data []byte, mode os.FileMode) error {
// If the file has the same contents as data, try to avoid a write.
f, err := os.Open(filename)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions testdata/symlinkFileDup/file1