summaryrefslogtreecommitdiffstats
path: root/src/go/pkg/multipath/multipath_test.go
blob: cd6c90d95182ced5a61ea8b59fb8319d14db4557 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// SPDX-License-Identifier: GPL-3.0-or-later

package multipath

import (
	"errors"
	"testing"

	"github.com/stretchr/testify/assert"
)

func TestNew(t *testing.T) {
	assert.Len(
		t,
		New("path1", "path2", "path2", "", "path3"),
		3,
	)
}

func TestMultiPath_Find(t *testing.T) {
	m := New("path1", "testdata/data1")

	v, err := m.Find("not exist")
	assert.Zero(t, v)
	assert.Error(t, err)

	v, err = m.Find("test-empty.conf")
	assert.Equal(t, "testdata/data1/test-empty.conf", v)
	assert.Nil(t, err)

	v, err = m.Find("test.conf")
	assert.Equal(t, "testdata/data1/test.conf", v)
	assert.Nil(t, err)
}

func TestIsNotFound(t *testing.T) {
	assert.True(t, IsNotFound(ErrNotFound{}))
	assert.False(t, IsNotFound(errors.New("")))
}

func TestMultiPath_FindFiles(t *testing.T) {
	m := New("path1", "testdata/data2", "testdata/data1")

	files, err := m.FindFiles(".conf")
	assert.NoError(t, err)
	assert.Equal(t, []string{"testdata/data2/test-empty.conf", "testdata/data2/test.conf"}, files)

	files, err = m.FindFiles()
	assert.NoError(t, err)
	assert.Equal(t, []string{"testdata/data2/test-empty.conf", "testdata/data2/test.conf"}, files)

	files, err = m.FindFiles(".not_exist")
	assert.NoError(t, err)
	assert.Equal(t, []string(nil), files)

	m = New("path1", "testdata/data1", "testdata/data2")
	files, err = m.FindFiles(".conf")
	assert.NoError(t, err)
	assert.Equal(t, []string{"testdata/data1/test-empty.conf", "testdata/data1/test.conf"}, files)
}