github.com/koko1123/flow-go-1@v0.29.6/utils/test_matrix/test_matrix_test.go (about) 1 package main 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/require" 7 ) 8 9 // Can't have a const []string so resorting to using a test helper function. 10 func getAllFlowPackages() []string { 11 return []string{ 12 flowPackagePrefix + "abc", 13 flowPackagePrefix + "abc/def", 14 flowPackagePrefix + "abc/def/ghi", 15 flowPackagePrefix + "def", 16 flowPackagePrefix + "def/abc", 17 flowPackagePrefix + "ghi", 18 flowPackagePrefix + "jkl", 19 flowPackagePrefix + "mno/abc", 20 flowPackagePrefix + "pqr", 21 flowPackagePrefix + "stu", 22 flowPackagePrefix + "vwx", 23 flowPackagePrefix + "vwx/ghi", 24 flowPackagePrefix + "yz", 25 } 26 } 27 28 func TestListTargetPackages(t *testing.T) { 29 targetPackages, seenPackages := listTargetPackages([]string{"abc", "ghi"}, getAllFlowPackages()) 30 require.Equal(t, 2, len(targetPackages)) 31 require.Equal(t, 4, len(seenPackages)) 32 33 // there should be 3 packages that start with "abc" 34 require.Equal(t, 3, len(targetPackages["abc"])) 35 require.Contains(t, targetPackages["abc"], flowPackagePrefix+"abc") 36 require.Contains(t, targetPackages["abc"], flowPackagePrefix+"abc/def") 37 require.Contains(t, targetPackages["abc"], flowPackagePrefix+"abc/def/ghi") 38 39 // there should be 1 package that starts with "ghi" 40 require.Equal(t, 1, len(targetPackages["ghi"])) 41 require.Contains(t, targetPackages["ghi"], flowPackagePrefix+"ghi") 42 43 require.Contains(t, seenPackages, flowPackagePrefix+"abc") 44 require.Contains(t, seenPackages, flowPackagePrefix+"abc/def") 45 require.Contains(t, seenPackages, flowPackagePrefix+"abc/def/ghi") 46 require.Contains(t, seenPackages, flowPackagePrefix+"ghi") 47 } 48 49 func TestListOtherPackages(t *testing.T) { 50 var seenPackages = make(map[string]string) 51 seenPackages[flowPackagePrefix+"abc"] = flowPackagePrefix + "abc" 52 seenPackages[flowPackagePrefix+"ghi"] = flowPackagePrefix + "ghi" 53 seenPackages[flowPackagePrefix+"mno/abc"] = flowPackagePrefix + "mno/abc" 54 seenPackages[flowPackagePrefix+"stu"] = flowPackagePrefix + "stu" 55 56 otherPackages := listOtherPackages(getAllFlowPackages(), seenPackages) 57 58 require.Equal(t, 9, len(otherPackages)) 59 60 require.Contains(t, otherPackages, flowPackagePrefix+"abc/def") 61 require.Contains(t, otherPackages, flowPackagePrefix+"abc/def/ghi") 62 require.Contains(t, otherPackages, flowPackagePrefix+"def") 63 require.Contains(t, otherPackages, flowPackagePrefix+"def/abc") 64 require.Contains(t, otherPackages, flowPackagePrefix+"jkl") 65 require.Contains(t, otherPackages, flowPackagePrefix+"pqr") 66 require.Contains(t, otherPackages, flowPackagePrefix+"vwx") 67 require.Contains(t, otherPackages, flowPackagePrefix+"vwx/ghi") 68 require.Contains(t, otherPackages, flowPackagePrefix+"yz") 69 } 70 71 func TestGenerateTestMatrix(t *testing.T) { 72 targetPackages, seenPackages := listTargetPackages([]string{"abc", "ghi"}, getAllFlowPackages()) 73 require.Equal(t, 2, len(targetPackages)) 74 require.Equal(t, 4, len(seenPackages)) 75 76 otherPackages := listOtherPackages(getAllFlowPackages(), seenPackages) 77 78 matrix := generateTestMatrix(targetPackages, otherPackages) 79 80 // should be 3 groups in test matrix: abc, ghi, others 81 require.Equal(t, 3, len(matrix)) 82 83 require.Contains(t, matrix, testMatrix{ 84 Name: "abc", 85 Packages: "github.com/koko1123/flow-go-1/abc github.com/koko1123/flow-go-1/abc/def github.com/koko1123/flow-go-1/abc/def/ghi"}, 86 ) 87 require.Contains(t, matrix, testMatrix{ 88 Name: "ghi", 89 Packages: "github.com/koko1123/flow-go-1/ghi"}, 90 ) 91 require.Contains(t, matrix, testMatrix{ 92 Name: "others", 93 Packages: "github.com/koko1123/flow-go-1/def github.com/koko1123/flow-go-1/def/abc github.com/koko1123/flow-go-1/jkl github.com/koko1123/flow-go-1/mno/abc github.com/koko1123/flow-go-1/pqr github.com/koko1123/flow-go-1/stu github.com/koko1123/flow-go-1/vwx github.com/koko1123/flow-go-1/vwx/ghi github.com/koko1123/flow-go-1/yz"}, 94 ) 95 }