Exemple #1
0
func TestMapCreation(t *testing.T) {

	o := New(nil)
	assert.Nil(t, o)

	o = New("Tyler")
	assert.Nil(t, o)

	unconvertable := &Unconvertable{name: "Tyler"}
	o = New(unconvertable)
	assert.Nil(t, o)

	convertable := &Convertable{name: "Tyler"}
	o = New(convertable)
	if assert.NotNil(t, convertable) {
		assert.Equal(t, "Tyler", o["name"], "Tyler")
	}

	o = MSI()
	if assert.NotNil(t, o) {
		assert.NotNil(t, o)
	}

	o = MSI("name", "Tyler")
	if assert.NotNil(t, o) {
		if assert.NotNil(t, o) {
			assert.Equal(t, o["name"], "Tyler")
		}
	}

}
Exemple #2
0
func TestMapFromJSONWithError(t *testing.T) {

	var m Map

	assert.Panics(t, func() {
		m = MustFromJSON(`"name":"Mat"}`)
	})

	assert.Nil(t, m)

}
func TestAccessorsAccessGetFromArrayWithInt(t *testing.T) {

	current := []interface{}{map[string]interface{}{"first": "Tyler", "last": "Bunnell"}, map[string]interface{}{"first": "Capitol", "last": "Bollocks"}}
	one := access(current, 0, nil, false, false)
	two := access(current, 1, nil, false, false)
	three := access(current, 2, nil, false, false)

	assert.Equal(t, "Tyler", one.(map[string]interface{})["first"])
	assert.Equal(t, "Capitol", two.(map[string]interface{})["first"])
	assert.Nil(t, three)

}
func TestAccessorsAccessGetInsideArray(t *testing.T) {

	current := map[string]interface{}{"names": []interface{}{map[string]interface{}{"first": "Tyler", "last": "Bunnell"}, map[string]interface{}{"first": "Capitol", "last": "Bollocks"}}}
	assert.Equal(t, "Tyler", access(current, "names[0].first", nil, false, true))
	assert.Equal(t, "Bunnell", access(current, "names[0].last", nil, false, true))
	assert.Equal(t, "Capitol", access(current, "names[1].first", nil, false, true))
	assert.Equal(t, "Bollocks", access(current, "names[1].last", nil, false, true))

	assert.Panics(t, func() {
		access(current, "names[2]", nil, false, true)
	})
	assert.Nil(t, access(current, "names[2]", nil, false, false))

}
Exemple #5
0
func TestSuiteLogging(t *testing.T) {
	testT := testing.T{}

	suiteLoggingTester := new(SuiteLoggingTester)

	capture := StdoutCapture{}
	capture.StartCapture()
	Run(&testT, suiteLoggingTester)
	output, err := capture.StopCapture()

	assert.Nil(t, err, "Got an error trying to capture stdout!")

	// Failed tests' output is always printed
	assert.Contains(t, output, "TESTLOGFAIL")

	if testing.Verbose() {
		// In verbose mode, output from successful tests is also printed
		assert.Contains(t, output, "TESTLOGPASS")
	} else {
		assert.NotContains(t, output, "TESTLOGPASS")
	}
}
Exemple #6
0
// Nil asserts that the specified object is nil.
//
//    require.Nil(t, err, "err should be nothing")
//
// Returns whether the assertion was successful (true) or not (false).
func Nil(t TestingT, object interface{}, msgAndArgs ...interface{}) {
	if !assert.Nil(t, object, msgAndArgs...) {
		t.FailNow()
	}
}