github.com/charypar/monobuild@v0.0.0-20211122220434-fd884ed50212/diff/diff_test.go (about)

     1  package diff
     2  
     3  import (
     4  	"reflect"
     5  	"testing"
     6  
     7  	"github.com/charypar/monobuild/graph"
     8  )
     9  
    10  func Test_Impacted(t *testing.T) {
    11  	exampleDependencies := graph.New(map[string][]graph.Edge{
    12  		"a": []graph.Edge{{Label: "b", Colour: graph.Weak}, {Label: "c", Colour: graph.Weak}},
    13  		"b": []graph.Edge{{Label: "c", Colour: graph.Weak}},
    14  		"c": []graph.Edge{},
    15  		"d": []graph.Edge{{Label: "a", Colour: graph.Strong}},
    16  		"e": []graph.Edge{{Label: "a", Colour: graph.Strong}, {Label: "b", Colour: graph.Strong}},
    17  	})
    18  
    19  	type args struct {
    20  		changedComponents []string
    21  		dependencies      graph.Graph
    22  	}
    23  	tests := []struct {
    24  		name string
    25  		args args
    26  		want []string
    27  	}{
    28  		{
    29  			"works with empty changes",
    30  			args{
    31  				[]string{},
    32  				exampleDependencies,
    33  			},
    34  			[]string{},
    35  		},
    36  		{
    37  			"collects affected strong dependencies",
    38  			args{
    39  				[]string{"a"},
    40  				exampleDependencies,
    41  			},
    42  			[]string{"a", "d", "e"},
    43  		},
    44  		{
    45  			"collects all affected dependencies",
    46  			args{
    47  				[]string{"c"},
    48  				exampleDependencies,
    49  			},
    50  			[]string{"a", "b", "c", "d", "e"},
    51  		},
    52  	}
    53  
    54  	for _, tt := range tests {
    55  		t.Run(tt.name, func(t *testing.T) {
    56  			if got := Impacted(tt.args.changedComponents, tt.args.dependencies); !reflect.DeepEqual(got, tt.want) {
    57  				t.Errorf("Dependencies() = %v, want %v", got, tt.want)
    58  			}
    59  		})
    60  	}
    61  }