-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathmetadata_test.go
57 lines (53 loc) · 1.79 KB
/
metadata_test.go
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
package alzlib
import (
"context"
"os"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
// TestFetchLibrariesWithDependencies tests fetching libraries with dependencies and they they are fetched in the right order.
func TestFetchLibrariesWithDependencies(t *testing.T) {
ctx := context.Background()
require.NoError(t, os.RemoveAll(".alzlib"))
defer os.RemoveAll(".alzlib") // nolint: errcheck
expcted := []string{
"testdata/dependent-libs/lib2",
"testdata/dependent-libs/lib1",
"testdata/dependent-libs/libB",
"testdata/dependent-libs/libA",
}
lib1 := NewCustomLibraryReference("testdata/dependent-libs/lib1")
libA := NewCustomLibraryReference("testdata/dependent-libs/libA")
libs := LibraryReferences{lib1, libA}
libs, err := libs.FetchWithDependencies(ctx)
assert.NoError(t, err)
require.Len(t, libs, 4)
result := make([]string, 4)
for i, lib := range libs {
result[i] = lib.String()
}
assert.ElementsMatch(t, expcted, result)
}
// TestFetchLibrariesWithCommonDependency checks that a libraries having a common dependency is fetched only once.
func TestFetchLibrariesWithCommonDependency(t *testing.T) {
ctx := context.Background()
require.NoError(t, os.RemoveAll(".alzlib"))
defer os.RemoveAll(".alzlib") // nolint: errcheck
expcted := []string{
"testdata/dependent-libs/lib2",
"testdata/dependent-libs/lib1",
"testdata/dependent-libs/lib3",
}
lib1 := NewCustomLibraryReference("testdata/dependent-libs/lib1")
libA := NewCustomLibraryReference("testdata/dependent-libs/lib3")
libs := LibraryReferences{lib1, libA}
libs, err := libs.FetchWithDependencies(ctx)
assert.NoError(t, err)
require.Len(t, libs, 3)
result := make([]string, 3)
for i, lib := range libs {
result[i] = lib.String()
}
assert.ElementsMatch(t, expcted, result)
}