Beispiel #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")
		}
	}

}
Beispiel #2
0
func TestMapFromJSON(t *testing.T) {

	o := MustFromJSON(`{"name":"Mat"}`)

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

}
Beispiel #3
0
func TestDefaultShouldDefaultMultipleFields(t *testing.T) {
	assert := assert.New(t)

	type S struct {
		A string `default:"i am a string"`
		B string
		C int `default:"1"`
	}

	s := S{}

	assert.Equal(s.A, "")
	assert.Equal(s.B, "")
	assert.Equal(s.C, 0)

	v, err := SetDefault(&s, "A")
	assert.Nil(err)
	assert.Equal(s.A, "i am a string")
	assert.Equal(s.A, v)

	_, err = SetDefault(&s, "B")
	assert.NotNil(err)
	assert.Equal(s.B, "")

	v, err = SetDefault(&s, "C")
	assert.Nil(err)
	assert.Equal(s.C, 1)
	assert.Equal(s.C, v)
}
Beispiel #4
0
func TestScheduleShouldStartAndStop(t *testing.T) {
	defer glog.Flush()
	assert := assert.New(t)

	unit := 10 * time.Millisecond
	calledCount := 0
	testF := func(start time.Time, dur time.Time) {
		remainder := start.Nanosecond() % int(unit)
		assert.Equal(0, remainder, "Start not truncated to 10ms")
		calledCount++
	}
	s := schedule.Schedule{
		Callback: testF,
		Period:   unit,
	}

	assert.NotNil(s)

	sleepCount := 3
	start := time.Now()
	err := s.Start()
	assert.Nil(err)
	time.Sleep(unit * time.Duration(sleepCount))
	s.Stop()
	elapsed := time.Since(start)
	assert.True(calledCount >= sleepCount && calledCount <= int(elapsed/unit))
}
Beispiel #5
0
func TestMapFromURLQuery(t *testing.T) {

	m, err := FromURLQuery("name=tyler&state=UT")
	if assert.NoError(t, err) && assert.NotNil(t, m) {
		assert.Equal(t, "tyler", m.Get("name").Str())
		assert.Equal(t, "UT", m.Get("state").Str())
	}

}
Beispiel #6
0
func TestScheduleShouldNotDoubleStart(t *testing.T) {
	defer glog.Flush()
	assert := assert.New(t)

	s := schedule.Schedule{
		Callback: func(start time.Time, dur time.Time) {},
		Period:   time.Millisecond,
	}

	assert.NotNil(s)

	err := s.Start()
	assert.Nil(err)

	err = s.Start()
	assert.NotNil(err)

	s.Stop()
}
func TestDynamicConfiguratonValidateShouldFailNilConf(t *testing.T) {
	assert := assert.New(t)

	dc := config.DynamicConfiguration{
		Type: "test",
		Conf: nil,
	}

	err := dc.Validate()
	assert.NotNil(err)
}
Beispiel #8
0
func Test_Mock_TestData(t *testing.T) {

	var mockedService *TestExampleImplementation = new(TestExampleImplementation)

	if assert.NotNil(t, mockedService.TestData()) {

		mockedService.TestData().Set("something", 123)
		assert.Equal(t, 123, mockedService.TestData().Get("something").Data())

	}

}
Beispiel #9
0
func TestDefaultShouldDefaultErrorOnMissingField(t *testing.T) {
	assert := assert.New(t)

	type S struct {
		A string `default:"a"`
	}

	s := S{}

	_, err := SetDefault(&s, "B")
	assert.NotNil(err)

}
Beispiel #10
0
func TestDefaultShouldDefaultErrorOnMissingTag(t *testing.T) {
	assert := assert.New(t)

	type S struct {
		A string
	}

	s := S{}

	_, err := SetDefault(&s, "A")
	assert.NotNil(err)

}
Beispiel #11
0
func TestDefaultShouldNotDefaultInvalidBool(t *testing.T) {
	assert := assert.New(t)

	type S struct {
		A bool `default:"invalid"`
	}

	s := S{}

	assert.Equal(s.A, false)
	_, err := SetDefault(&s, "A")
	assert.NotNil(err)

}
Beispiel #12
0
func TestSetAllDefaultsShouldErrorOnNonPtr(t *testing.T) {
	assert := assert.New(t)

	type S struct {
		A string `default:"i am a string"`
	}

	s := S{}
	assert.Equal(s.A, "")

	err := SetAllDefaults(s)
	assert.NotNil(err)

}
Beispiel #13
0
func TestDefaultShouldNotDefaultInvalidFloat(t *testing.T) {
	assert := assert.New(t)

	type S struct {
		A float64 `default:"1.0a"`
	}

	s := S{}

	assert.Equal(s.A, 0.0)
	_, err := SetDefault(&s, "A")
	assert.NotNil(err)

}
Beispiel #14
0
func TestDefaultShouldNotDefaultInvalidUint(t *testing.T) {
	assert := assert.New(t)

	type S struct {
		A uint `default:"-1"`
	}

	s := S{}

	assert.Equal(s.A, uint(0))
	_, err := SetDefault(&s, "A")
	assert.NotNil(err)

}
Beispiel #15
0
func Test_Mock_findExpectedCall(t *testing.T) {

	m := new(Mock)
	m.On("One", 1).Return("one")
	m.On("Two", 2).Return("two")
	m.On("Two", 3).Return("three")

	f, c := m.findExpectedCall("Two", 3)

	if assert.Equal(t, 2, f) {
		if assert.NotNil(t, c) {
			assert.Equal(t, "Two", c.Method)
			assert.Equal(t, 3, c.Arguments[0])
			assert.Equal(t, "three", c.ReturnArguments[0])
		}
	}

}