github.com/ndarilek/terraform@v0.3.8-0.20150320140257-d3135c1b2bac/helper/schema/set_test.go (about)

     1  package schema
     2  
     3  import (
     4  	"reflect"
     5  	"testing"
     6  )
     7  
     8  func TestSetAdd(t *testing.T) {
     9  	s := &Set{F: testSetInt}
    10  	s.Add(1)
    11  	s.Add(5)
    12  	s.Add(25)
    13  
    14  	expected := []interface{}{1, 5, 25}
    15  	actual := s.List()
    16  	if !reflect.DeepEqual(actual, expected) {
    17  		t.Fatalf("bad: %#v", actual)
    18  	}
    19  }
    20  
    21  func TestSetContains(t *testing.T) {
    22  	s := &Set{F: testSetInt}
    23  	s.Add(5)
    24  
    25  	if s.Contains(2) {
    26  		t.Fatal("should not contain")
    27  	}
    28  	if !s.Contains(5) {
    29  		t.Fatal("should contain")
    30  	}
    31  }
    32  
    33  func TestSetDifference(t *testing.T) {
    34  	s1 := &Set{F: testSetInt}
    35  	s2 := &Set{F: testSetInt}
    36  
    37  	s1.Add(1)
    38  	s1.Add(5)
    39  
    40  	s2.Add(5)
    41  	s2.Add(25)
    42  
    43  	difference := s1.Difference(s2)
    44  	difference.Add(2)
    45  
    46  	expected := []interface{}{1, 2}
    47  	actual := difference.List()
    48  	if !reflect.DeepEqual(actual, expected) {
    49  		t.Fatalf("bad: %#v", actual)
    50  	}
    51  }
    52  
    53  func TestSetIntersection(t *testing.T) {
    54  	s1 := &Set{F: testSetInt}
    55  	s2 := &Set{F: testSetInt}
    56  
    57  	s1.Add(1)
    58  	s1.Add(5)
    59  
    60  	s2.Add(5)
    61  	s2.Add(25)
    62  
    63  	intersection := s1.Intersection(s2)
    64  	intersection.Add(2)
    65  
    66  	expected := []interface{}{2, 5}
    67  	actual := intersection.List()
    68  	if !reflect.DeepEqual(actual, expected) {
    69  		t.Fatalf("bad: %#v", actual)
    70  	}
    71  }
    72  
    73  func TestSetUnion(t *testing.T) {
    74  	s1 := &Set{F: testSetInt}
    75  	s2 := &Set{F: testSetInt}
    76  
    77  	s1.Add(1)
    78  	s1.Add(5)
    79  
    80  	s2.Add(5)
    81  	s2.Add(25)
    82  
    83  	union := s1.Union(s2)
    84  	union.Add(2)
    85  
    86  	expected := []interface{}{1, 2, 5, 25}
    87  	actual := union.List()
    88  	if !reflect.DeepEqual(actual, expected) {
    89  		t.Fatalf("bad: %#v", actual)
    90  	}
    91  }
    92  
    93  func testSetInt(v interface{}) int {
    94  	return v.(int)
    95  }