Some checks are pending
Docs Deploy / build_and_deploy (push) Waiting to run
Generate Docs / cli (push) Waiting to run
Generate Config Doc / cli (push) Waiting to run
Go formatting / go-formatting (push) Waiting to run
Check links / markdown-link-check (push) Waiting to run
Integration / pre-test (push) Waiting to run
Integration / test on (push) Blocked by required conditions
Integration / status (push) Blocked by required conditions
Lint / Lint Go code (push) Waiting to run
Test / test (ubuntu-latest) (push) Waiting to run
55 lines
1.2 KiB
Go
55 lines
1.2 KiB
Go
package diff
|
|
|
|
import (
|
|
"testing"
|
|
"testing/fstest"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestComputeFS(t *testing.T) {
|
|
require := require.New(t)
|
|
|
|
origin := fstest.MapFS{
|
|
"foo.txt": &fstest.MapFile{
|
|
Data: []byte("hello"),
|
|
},
|
|
"bar.txt": &fstest.MapFile{
|
|
Data: []byte("unmodified"),
|
|
},
|
|
"pkg/main.go": &fstest.MapFile{
|
|
Data: []byte("package main"),
|
|
},
|
|
}
|
|
modified := fstest.MapFS{
|
|
"foo.txt": &fstest.MapFile{
|
|
Data: []byte("world"),
|
|
},
|
|
"bar.txt": &fstest.MapFile{
|
|
Data: []byte("unmodified"),
|
|
},
|
|
"new.txt": &fstest.MapFile{
|
|
Data: []byte("new file"),
|
|
},
|
|
"pkg/main.go": &fstest.MapFile{
|
|
Data: []byte("package main\nfunc main() {}"),
|
|
},
|
|
}
|
|
|
|
unified, err := computeFS(origin, modified)
|
|
require.NoError(err)
|
|
require.Len(unified, 3)
|
|
expectedFiles := []string{"foo.txt", "new.txt", "pkg/main.go"}
|
|
for _, u := range unified {
|
|
require.Contains(expectedFiles, u.From, "unexpected file in diff: %s", u.From)
|
|
}
|
|
|
|
// Test ignoring files
|
|
unified, err = computeFS(origin, modified, "**.go")
|
|
require.NoError(err)
|
|
require.Len(unified, 2)
|
|
expectedFiles = []string{"foo.txt", "new.txt"}
|
|
for _, u := range unified {
|
|
require.Contains(expectedFiles, u.From, "unexpected file in diff: %s", u.From)
|
|
}
|
|
}
|