github.com/diggerhq/digger/libs@v0.0.0-20240604170430-9d61cdf01cc5/orchestrator/github/github_test.go (about) 1 package github 2 3 import ( 4 "testing" 5 6 "github.com/diggerhq/digger/libs/digger_config" 7 "github.com/stretchr/testify/assert" 8 ) 9 10 func TestFindAllProjectsDependantOnImpactedProjects(t *testing.T) { 11 12 projects := []digger_config.Project{ 13 { 14 Name: "a", 15 }, 16 { 17 Name: "b", 18 DependencyProjects: []string{"k"}, 19 }, 20 { 21 Name: "c", 22 DependencyProjects: []string{"b", "a", "i"}, 23 }, 24 { 25 Name: "d", 26 DependencyProjects: []string{"c"}, 27 }, 28 { 29 Name: "e", 30 DependencyProjects: []string{"i", "c"}, 31 }, 32 { 33 Name: "f", 34 DependencyProjects: []string{"e"}, 35 }, 36 { 37 Name: "g", 38 DependencyProjects: []string{"e"}, 39 }, 40 { 41 Name: "h", 42 }, 43 { 44 Name: "i", 45 }, 46 { 47 Name: "j", 48 }, 49 { 50 Name: "k", 51 }, 52 { 53 Name: "m", 54 DependencyProjects: []string{"h"}, 55 }, 56 } 57 58 dependencyGraph, err := digger_config.CreateProjectDependencyGraph(projects) 59 60 if err != nil { 61 t.Errorf("Error creating dependency graph: %v", err) 62 } 63 64 impactedProjects := []digger_config.Project{ 65 { 66 Name: "a", 67 }, 68 { 69 Name: "d", 70 }, 71 { 72 Name: "f", 73 }, 74 { 75 Name: "g", 76 }, 77 { 78 Name: "h", 79 }, 80 { 81 Name: "i", 82 }, 83 { 84 Name: "j", 85 }, 86 { 87 Name: "m", 88 }, 89 } 90 91 impactedProjectsWithDependants, err := FindAllProjectsDependantOnImpactedProjects(impactedProjects, dependencyGraph) 92 if err != nil { 93 return 94 } 95 96 assert.Equal(t, 10, len(impactedProjectsWithDependants)) 97 98 projectNames := make([]string, 10) 99 for _, project := range impactedProjectsWithDependants { 100 projectNames = append(projectNames, project.Name) 101 } 102 103 assert.Contains(t, projectNames, "a") 104 assert.Contains(t, projectNames, "c") 105 assert.Contains(t, projectNames, "d") 106 assert.Contains(t, projectNames, "e") 107 assert.Contains(t, projectNames, "f") 108 assert.Contains(t, projectNames, "g") 109 assert.Contains(t, projectNames, "h") 110 assert.Contains(t, projectNames, "i") 111 assert.Contains(t, projectNames, "j") 112 assert.Contains(t, projectNames, "m") 113 assert.NotContains(t, projectNames, "k") 114 assert.NotContains(t, projectNames, "b") 115 } 116 117 func TestFindAllChangedFilesOfPR(t *testing.T) { 118 githubPrService := NewGitHubService("", "digger", "diggerhq") 119 files, _ := githubPrService.GetChangedFiles(98) 120 // 45 changed files including 1 renamed file so the previous filename is included 121 assert.Equal(t, 46, len(files)) 122 }