Example #1
0
func TestDeploymentEqual(t *testing.T) {
	assert := assert.New(t)

	dep := Deployment{}
	assert.True(dep.Equal(&Deployment{}))

	other := Deployment{
		Annotation: Annotation{
			RequestID: "somewhere around here",
		},
	}
	assert.True(dep.Equal(&other))
}
Example #2
0
func TestOwnerSet(t *testing.T) {
	set := NewOwnerSet("one")
	set.Add("two")
	set.Add("one")
	slice := set.Slice()
	assert.Len(t, slice, 2)
	assert.Contains(t, slice, "one")
	assert.Contains(t, slice, "two")
	assert.True(t, set.Equal(NewOwnerSet("two", "one")))
}
Example #3
0
func TestDone(t *testing.T) {
	assert := assert.New(t)

	ar := setupAR()

	received := false
	var result error

	ar.addListener(func(tc, done triggerChannel, ec announceChannel) {
		select {
		case err := <-ec:
			received = true
			result = err
			close(done)
		}
	})
	done := ar.Kickoff()
	for range done {
	}
	assert.True(received, "Should have received announcement")
}
Example #4
0
func TestVolumesEqual(t *testing.T) {
	//Log.Vomit.SetOutput(os.Stderr)
	//Log.Debug.SetOutput(os.Stderr)
	assert := assert.New(t)
	vs := []vpair{
		vpair{Volumes{&Volume{"a", "a", "RO"}, &Volume{"a", "a", "RO"}}, 1},
		vpair{Volumes{&Volume{"a", "a", "RO"}, &Volume{"a", "a", "RO"}}, 1},
		vpair{Volumes{&Volume{"a", "a", "RO"}}, 4},
		vpair{Volumes{&Volume{"a", "b", "RO"}, &Volume{"a", "a", "RO"}}, 2},
		vpair{Volumes{&Volume{"a", "a", "RW"}, &Volume{"a", "a", "RO"}}, 3},
	}

	for _, l := range vs {
		for _, r := range vs {
			if l.i == r.i {
				assert.True(l.v.Equal(r.v))
			} else {
				assert.False(l.v.Equal(r.v))
			}
		}
	}
}
Example #5
0
func TestPredicateBuilder(t *testing.T) {
	assert := assert.New(t)

	ds := make([]*sous.Deployment, 0, 8)
	cs := []string{"cluster1", "cluster2"}
	rs := []string{"github.com/ot/one", "github.com/ot/two"}
	os := []string{"up", "down"}

	for _, c := range cs {
		for _, r := range rs {
			for _, o := range os {
				ds = append(ds, &sous.Deployment{
					ClusterName: c,
					SourceID: sous.SourceID{
						Location: sous.SourceLocation{
							Repo: r,
							Dir:  o,
						},
					},
				})
			}
		}
	}

	parseSL := func(string) (sous.SourceLocation, error) {
		return sous.SourceLocation{}, nil
	}

	//	for i, d := range ds {
	//		fmt.Printf("%d: %#v\n", i, d)
	//	}
	//
	f := config.DeployFilterFlags{}

	rf, err := f.BuildFilter(parseSL)
	assert.NoError(err)
	assert.True(rf.All())

	f.Repo = string(rs[0])
	pd, err := f.BuildPredicate(parseSL)
	assert.NoError(err)
	assert.NotNil(pd)
	filtered := filter(ds, pd)
	assert.Contains(filtered, ds[0])
	assert.Contains(filtered, ds[1])
	assert.Contains(filtered, ds[4])
	assert.Contains(filtered, ds[5])
	assert.Len(filtered, 4)

	f.Offset = string(os[0])
	pd, err = f.BuildPredicate(parseSL)
	assert.NoError(err)
	assert.NotNil(pd)
	filtered = filter(ds, pd)
	assert.Contains(filtered, ds[0])
	assert.Contains(filtered, ds[4])
	assert.Len(filtered, 2)

	f.Cluster = cs[0]
	pd, err = f.BuildPredicate(parseSL)
	assert.NoError(err)
	assert.NotNil(pd)
	filtered = filter(ds, pd)
	assert.Contains(filtered, ds[0])
	assert.Len(filtered, 1)

	f = config.DeployFilterFlags{Cluster: cs[1]}
	pd, err = f.BuildPredicate(parseSL)
	assert.NoError(err)
	assert.NotNil(pd)
	filtered = filter(ds, pd)
	assert.Contains(filtered, ds[4])
	assert.Contains(filtered, ds[5])
	assert.Contains(filtered, ds[6])
	assert.Contains(filtered, ds[7])
	assert.Len(filtered, 4)

	f = config.DeployFilterFlags{All: true}
	pd, err = f.BuildPredicate(parseSL)
	assert.NoError(err)
	assert.NotNil(pd)
	filtered = filter(ds, pd)
	assert.Len(filtered, 8)
}
Example #6
0
// True asserts that the specified value is true.
//
//    assert.True(t, myBool, "myBool should be true")
//
// Returns whether the assertion was successful (true) or not (false).
func True(t TestingT, value bool, msgAndArgs ...interface{}) {
	if !assert.True(t, value, msgAndArgs...) {
		t.FailNow()
	}
}