llbsolver: fix selectors dedupe

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
docker-19.03
Tonis Tiigi 2019-03-05 17:58:36 -08:00
parent 06809f387a
commit 6d859fc9b0
2 changed files with 28 additions and 1 deletions

View File

@ -165,7 +165,7 @@ func dedupePaths(inp []string) []string {
for p1 := range old {
var skip bool
for p2 := range old {
if p1 != p2 && strings.HasPrefix(p1, p2) {
if p1 != p2 && strings.HasPrefix(p1, p2+"/") {
skip = true
break
}

View File

@ -0,0 +1,27 @@
package ops
import (
"testing"
"github.com/stretchr/testify/require"
)
func TestDedupPaths(t *testing.T) {
res := dedupePaths([]string{"Gemfile", "Gemfile/foo"})
require.Equal(t, []string{"Gemfile"}, res)
res = dedupePaths([]string{"Gemfile/bar", "Gemfile/foo"})
require.Equal(t, []string{"Gemfile/bar", "Gemfile/foo"}, res)
res = dedupePaths([]string{"Gemfile", "Gemfile.lock"})
require.Equal(t, []string{"Gemfile", "Gemfile.lock"}, res)
res = dedupePaths([]string{"Gemfile.lock", "Gemfile"})
require.Equal(t, []string{"Gemfile", "Gemfile.lock"}, res)
res = dedupePaths([]string{"foo", "Gemfile", "Gemfile/foo"})
require.Equal(t, []string{"Gemfile", "foo"}, res)
res = dedupePaths([]string{"foo/bar/baz", "foo/bara", "foo/bar/bax", "foo/bar"})
require.Equal(t, []string{"foo/bar", "foo/bara"}, res)
}