github.com/andrewrech/ih-abstract@v0.0.0-20210322142951-2fec1c8d0f38/unique_test.go (about)

     1  package main
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/google/go-cmp/cmp"
     7  )
     8  
     9  func TestDiffUnq(t *testing.T) {
    10  	l := []string{"A", "B", "C", "A"}
    11  
    12  	in := make(chan []string)
    13  
    14  	go func() {
    15  		in <- l
    16  		close(in)
    17  	}()
    18  
    19  	channels, done := DiffUnq(in, "test-diff")
    20  
    21  	<-done
    22  
    23  	var unq []string
    24  
    25  	for l := range channels["test-diff-unique-strings"] {
    26  		unq = append(unq, l...)
    27  	}
    28  
    29  	var unqNew []string
    30  	for l := range channels["test-diff-unique-strings-new"] {
    31  		unqNew = append(unqNew, l...)
    32  	}
    33  
    34  	t.Run("Detect filtering of unique strings", func(t *testing.T) {
    35  		diff := cmp.Diff(unq, []string{"A", "B", "C"})
    36  
    37  		if diff != "" {
    38  			t.Fatalf(diff)
    39  		}
    40  	})
    41  
    42  	t.Run("Detect filtering of new strings compared to an existing output file", func(t *testing.T) {
    43  		diff := cmp.Diff(unqNew, []string{"C"})
    44  
    45  		if diff != "" {
    46  			t.Fatalf(diff)
    47  		}
    48  	})
    49  }