• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang shared.NewExpect函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/trivago/gollum/shared.NewExpect函数的典型用法代码示例。如果您正苦于以下问题:Golang NewExpect函数的具体用法?Golang NewExpect怎么用?Golang NewExpect使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了NewExpect函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: TestProducerMessageLoop

func TestProducerMessageLoop(t *testing.T) {
	expect := shared.NewExpect(t)
	mockP := getMockProducer()
	mockP.setState(PluginStateActive)
	mockP.messages = make(chan Message, 10)
	msgData := "test Message loop"
	msg := Message{
		Data: []byte(msgData),
	}

	for i := 0; i < 9; i++ {
		mockP.messages <- msg
	}
	counter := 0
	onMessage := func(msg Message) {
		expect.Equal(msgData, msg.String())
		counter++
		if counter == 9 {
			mockP.setState(PluginStateDead)
		}
	}

	mockP.messageLoop(onMessage)
	expect.Equal(9, counter)
}
开发者ID:pombredanne,项目名称:gollum-1,代码行数:25,代码来源:producer_test.go


示例2: TestPluginRunState

func TestPluginRunState(t *testing.T) {
	expect := shared.NewExpect(t)
	pluginState := NewPluginRunState()

	expect.Equal(PluginStateDead, pluginState.GetState())

	pluginState.SetState(PluginStateWaiting)
	expect.Equal(PluginStateWaiting, pluginState.GetState())
	pluginState.SetState(PluginStateActive)
	expect.Equal(PluginStateActive, pluginState.GetState())
	pluginState.SetState(PluginStateStopping)
	expect.Equal(PluginStateStopping, pluginState.GetState())

	var wg sync.WaitGroup
	pluginState.SetWorkerWaitGroup(&wg)

	pluginState.AddWorker()
	pluginState.AddWorker()
	done := false

	go func() {
		pluginState.WorkerDone()
		pluginState.WorkerDone()
		wg.Wait()
		done = true
	}()
	// timeout for go routine.
	time.Sleep(500 * time.Millisecond)
	expect.True(done)

}
开发者ID:pombredanne,项目名称:gollum-1,代码行数:31,代码来源:plugin_test.go


示例3: TestPluginConfigRead

// Function reads initializes pluginConfig with predefined values and
// non-predefined values in the Settings
// Plan:
//  Create a new PluginConfig
//  Create a new shared.MarshalMap with mock key values
//  Check if they are actually added, if they are, assert the key-value correctness
func TestPluginConfigRead(t *testing.T) {
	expect := shared.NewExpect(t)
	mockPluginCfg := getMockPluginConfig()

	// create a mock MarshalMap
	testMarshalMap := shared.NewMarshalMap()
	testMarshalMap["Instances"] = 0

	mockPluginCfg.Read(testMarshalMap)
	// with 0 instance, plugin should be disabled
	expect.False(mockPluginCfg.Enable)
	// if there is no stream, then array with wildcard should be returned
	expect.Equal(mockPluginCfg.Stream, []string{"*"})

	//reset mockPluginCfg
	mockPluginCfg = getMockPluginConfig()
	testMarshalMap["ID"] = "mockId"
	testMarshalMap["Enable"] = true
	testMarshalMap["Instances"] = 2
	testMarshalMap["Stream"] = "mockStats"
	testMarshalMap["Host"] = "someHost"
	testMarshalMap["Database"] = "someDatabase"

	mockPluginCfg.Read(testMarshalMap)

	// Check for the bundled config options
	expect.Equal(mockPluginCfg.ID, "mockId")
	expect.True(mockPluginCfg.Enable)
	expect.Equal(mockPluginCfg.Instances, 2)
	expect.Equal(mockPluginCfg.Stream, []string{"mockStats"})

	// check for the miscelleneous settings key added
	expect.Equal(mockPluginCfg.GetString("Host", ""), "someHost")
	expect.Equal(mockPluginCfg.GetString("Database", ""), "someDatabase")
}
开发者ID:jrossi,项目名称:gollum,代码行数:41,代码来源:pluginconfig_test.go


示例4: TestConsumerTickerLoop

// For completeness' sake. This is exactly the same as Producer's ticket loop
func TestConsumerTickerLoop(t *testing.T) {
	expect := shared.NewExpect(t)
	mockC := getMockConsumer()
	mockC.setState(PluginStateActive)
	// accept timeroff by abs( 8 ms)
	delta := float64(8 * time.Millisecond)
	var counter = 0
	tickerLoopTimeout := 20 * time.Millisecond
	var timeRecorded time.Time
	onTimeOut := func() {
		if counter > 3 {
			mockC.setState(PluginStateDead)
			return
		}
		//this was fired as soon as the ticker started. So ignore but save the time
		if counter == 0 {
			timeRecorded = time.Now()
			counter++
			return
		}
		diff := time.Now().Sub(timeRecorded)
		deltaDiff := math.Abs(float64(tickerLoopTimeout - diff))
		expect.True(deltaDiff < delta)
		timeRecorded = time.Now()
		counter++
		return
	}

	mockC.tickerLoop(tickerLoopTimeout, onTimeOut)
	time.Sleep(2 * time.Second)
	// in anycase, the callback has to be called atleast once
	expect.True(counter > 1)
}
开发者ID:pombredanne,项目名称:gollum-1,代码行数:34,代码来源:consumer_test.go


示例5: TestConsumerControlLoop

// For completeness' sake. This is exactly the same as Producer's control loop
func TestConsumerControlLoop(t *testing.T) {
	expect := shared.NewExpect(t)
	mockC := getMockConsumer()

	var stop bool
	var roll bool
	mockC.SetStopCallback(func() {
		stop = true
	})

	mockC.SetRollCallback(func() {
		roll = true
	})

	go mockC.ControlLoop()
	// let the go routine start
	time.Sleep(50 * time.Millisecond)
	mockC.control <- PluginControlStopConsumer
	time.Sleep(50 * time.Millisecond)
	expect.True(stop)

	go mockC.ControlLoop()
	time.Sleep(50 * time.Millisecond)
	mockC.control <- PluginControlRoll
	time.Sleep(50 * time.Millisecond)
	expect.True(roll)
}
开发者ID:pombredanne,项目名称:gollum-1,代码行数:28,代码来源:consumer_test.go


示例6: TestProducerControlLoop

func TestProducerControlLoop(t *testing.T) {
	expect := shared.NewExpect(t)
	mockP := getMockProducer()

	var stop bool
	var roll bool
	mockP.onStop = func() {
		stop = true
	}

	mockP.onRoll = func() {
		roll = true
	}

	go expect.NonBlocking(2*time.Second, mockP.ControlLoop)
	time.Sleep(50 * time.Millisecond)
	mockP.control <- PluginControlStopProducer // trigger stopLoop (stop expect.NonBlocking)
	time.Sleep(50 * time.Millisecond)
	expect.True(stop)

	go expect.NonBlocking(2*time.Second, mockP.ControlLoop)
	time.Sleep(50 * time.Millisecond)
	mockP.control <- PluginControlRoll // trigger rollLoop (stop expect.NonBlocking)
	time.Sleep(50 * time.Millisecond)
	expect.True(roll)

}
开发者ID:pombredanne,项目名称:gollum-1,代码行数:27,代码来源:producer_test.go


示例7: TestConsumerEnqueueCopy

func TestConsumerEnqueueCopy(t *testing.T) {
	expect := shared.NewExpect(t)
	mockC := getMockConsumer()

	dataToSend := "Consumer Enqueue Data"
	distribute := func(msg Message) {
		expect.Equal(dataToSend, msg.String())
	}

	mockStream := getMockStream()
	mockP := getMockProducer()
	mockStream.AddProducer(&mockP)
	mockStream.distribute = distribute
	mockStreamID := GetStreamID("mockStream")
	StreamRegistry.Register(&mockStream, mockStreamID)

	mockC.streams = []MappedStream{
		MappedStream{
			StreamID: mockStreamID,
			Stream:   &mockStream,
		},
	}

	mockC.EnqueueCopy([]byte(dataToSend), 2)

}
开发者ID:pombredanne,项目名称:gollum-1,代码行数:26,代码来源:consumer_test.go


示例8: TestJSONFormatter1

func TestJSONFormatter1(t *testing.T) {
	expect := shared.NewExpect(t)

	testString := `{"a":123,"b":"string","c":[1,2,3],"d":[{"a":1}],"e":[[1,2]],"f":[{"a":1},{"b":2}],"g":[[1,2],[3,4]]}`
	msg := core.NewMessage(nil, []byte(testString), 0)
	test := newTestJSONFormatter([]interface{}{
		`findKey    :":  key        ::`,
		`findKey    :}:             : pop  : end`,
		`key        :":  findVal    :      : key`,
		`findVal    :\:: value      ::`,
		`value      :":  string     ::`,
		`value      :[:  array      : push : arr`,
		`value      :{:  findKey    : push : obj`,
		`value      :,:  findKey    :      : val`,
		`value      :}:             : pop  : val+end`,
		`string     :":  findKey    :      : esc`,
		`array      :[:  array      : push : arr`,
		`array      :{:  findKey    : push : obj`,
		`array      :]:             : pop  : end`,
		`array      :,:  arrIntVal  :      : val`,
		`array      :":  arrStrVal  ::`,
		`arrIntVal  :,:  arrIntVal  :      : val`,
		`arrIntVal  :]:             : pop  : val+end`,
		`arrStrVal  :":  arrNextStr :      : esc`,
		`arrNextStr :":  arrStrVal  ::`,
		`arrNextStr :]:             : pop  : end`,
	}, "findKey")

	result, _ := test.Format(msg)
	expect.Equal(testString, string(result))
}
开发者ID:pombredanne,项目名称:gollum-1,代码行数:31,代码来源:json_test.go


示例9: TestPluginConfigGetBool

// Function gets an bool value for a key or default if non-existant
// Plan: similar to TestPluginConfigGetInt
func TestPluginConfigGetBool(t *testing.T) {
	expect := shared.NewExpect(t)
	mockPluginCfg := getMockPluginConfig()

	expect.Equal(mockPluginCfg.GetBool("boolKey", false), false)
	mockPluginCfg.Settings["boolKey"] = true
	expect.Equal(mockPluginCfg.GetBool("boolKey", false), true)
}
开发者ID:jrossi,项目名称:gollum,代码行数:10,代码来源:pluginconfig_test.go


示例10: TestWriterAssemblySetWriter

func TestWriterAssemblySetWriter(t *testing.T) {
	expect := shared.NewExpect(t)
	mockIo := mockIoWrite{expect}
	wa := NewWriterAssembly(mockIo, mockIo.mockFlush, &mockFormatter{})

	wa.SetWriter(secondMockIoWrite{})
	length, _ := wa.writer.Write([]byte("abcde"))
	expect.Equal(length, 5)
}
开发者ID:pombredanne,项目名称:gollum-1,代码行数:9,代码来源:writerassembly_test.go


示例11: TestConsumerFuse

func TestConsumerFuse(t *testing.T) {
	expect := shared.NewExpect(t)
	mockC := getMockConsumer()

	conf := getMockPluginConfig()
	conf.Override("Fuse", "test")

	mockC.Configure(conf)
	expect.NotNil(mockC.fuse)

	burnedCallback := false
	activeCallback := false

	mockC.SetFuseBurnedCallback(func() { burnedCallback = true })
	mockC.SetFuseActiveCallback(func() { activeCallback = true })

	go mockC.ControlLoop()

	expect.False(mockC.fuse.IsBurned())
	expect.False(burnedCallback)
	expect.False(activeCallback)

	// Check manual fuse trigger

	burnedCallback = false
	activeCallback = false

	mockC.Control() <- PluginControlFuseBurn
	time.Sleep(10 * time.Millisecond)
	expect.True(burnedCallback)
	expect.False(activeCallback)

	burnedCallback = false
	mockC.Control() <- PluginControlFuseActive
	time.Sleep(10 * time.Millisecond)
	expect.False(burnedCallback)
	expect.True(activeCallback)

	// Check automatic burn callback

	burnedCallback = false
	activeCallback = false

	mockC.fuse.Burn()
	time.Sleep(shared.SpinTimeSuspend + 100*time.Millisecond)

	expect.True(burnedCallback)
	expect.False(activeCallback)

	// Check automatic activate callback

	burnedCallback = false
	mockC.fuse.Activate()
	time.Sleep(10 * time.Millisecond)
	expect.False(burnedCallback)
	expect.True(activeCallback)
}
开发者ID:pombredanne,项目名称:gollum-1,代码行数:57,代码来源:consumer_test.go


示例12: TestPluginConfigHasValue

// Function checks if predefined value exists or not
// Plan:
//  Create a new PluginConfig
//  Add non-predefined Values
//  Check if added ones return true, and others false
func TestPluginConfigHasValue(t *testing.T) {
	expect := shared.NewExpect(t)
	mockPluginCfg := getMockPluginConfig()

	expect.False(mockPluginCfg.HasValue("aKey"))

	mockPluginCfg.Settings["aKey"] = 1
	expect.True(mockPluginCfg.HasValue("aKey"))
}
开发者ID:jrossi,项目名称:gollum,代码行数:14,代码来源:pluginconfig_test.go


示例13: TestPluginConfigGetInt

// Function gets an int value for a key or default value if non-existant
// Plan:
//  Create a new PluginConfig
//  add a key and an int value in the Settings
//  get the value back and Assert
func TestPluginConfigGetInt(t *testing.T) {
	expect := shared.NewExpect(t)
	mockPluginCfg := getMockPluginConfig()

	expect.Equal(mockPluginCfg.GetInt("intKey", 0), 0)
	mockPluginCfg.Settings["intKey"] = 2
	expect.Equal(mockPluginCfg.GetInt("intKey", 0), 2)

}
开发者ID:jrossi,项目名称:gollum,代码行数:14,代码来源:pluginconfig_test.go


示例14: TestWriterAssemblySetValidator

func TestWriterAssemblySetValidator(t *testing.T) {
	expect := shared.NewExpect(t)
	mockIo := mockIoWrite{expect}
	wa := NewWriterAssembly(mockIo, mockIo.mockFlush, &mockFormatter{})
	validator := func() bool {
		return true
	}
	wa.SetValidator(validator)
	expect.True(wa.validate())
}
开发者ID:pombredanne,项目名称:gollum-1,代码行数:10,代码来源:writerassembly_test.go


示例15: TestStreamRegistryRegister

func TestStreamRegistryRegister(t *testing.T) {
	expect := shared.NewExpect(t)
	mockSRegistry := getMockStreamRegistry()

	streamName := "testStream"
	mockStream := getMockStream()
	mockSRegistry.Register(&mockStream, GetStreamID(streamName))

	expect.NotNil(mockSRegistry.GetStream(GetStreamID(streamName)))
}
开发者ID:pombredanne,项目名称:gollum-1,代码行数:10,代码来源:streamregistry_test.go


示例16: TestPluginConfigGetString

// Function gets the string value for a key or if the key/value(?) doesn't
// exist, returns the default value
// Plan:
//  Create a new PluginConfig
//  For a random key, check if the default value is returned
//  Add a key with a value
//  Asserts the string returned for the key is correct
func TestPluginConfigGetString(t *testing.T) {
	expect := shared.NewExpect(t)
	mockPluginCfg := getMockPluginConfig()

	//check for non-existant key
	expect.Equal(mockPluginCfg.GetString("aKey", "default"), "default")

	mockPluginCfg.Settings["aKey"] = "aValue"
	expect.Equal(mockPluginCfg.GetString("aKey", "default"), "aValue")
}
开发者ID:jrossi,项目名称:gollum,代码行数:17,代码来源:pluginconfig_test.go


示例17: TestStreamRegistryIsStreamRegistered

func TestStreamRegistryIsStreamRegistered(t *testing.T) {
	expect := shared.NewExpect(t)
	mockSRegistry := getMockStreamRegistry()

	mockStreamID := GetStreamID("testStream")

	expect.False(mockSRegistry.IsStreamRegistered(mockStreamID))
	// TODO: Get a real stream and test with that
	mockSRegistry.streams[mockStreamID] = &StreamBase{}
	expect.True(mockSRegistry.IsStreamRegistered(mockStreamID))
}
开发者ID:pombredanne,项目名称:gollum-1,代码行数:11,代码来源:streamregistry_test.go


示例18: TestStreamRegistryForEachStream

func TestStreamRegistryForEachStream(t *testing.T) {
	expect := shared.NewExpect(t)
	mockSRegistry := getMockStreamRegistry()

	callback := func(streamID MessageStreamID, stream Stream) {
		expect.Equal(streamID, GetStreamID("testRegistry"))
	}

	mockSRegistry.streams[GetStreamID("testRegistry")] = &StreamBase{}
	mockSRegistry.ForEachStream(callback)
}
开发者ID:pombredanne,项目名称:gollum-1,代码行数:11,代码来源:streamregistry_test.go


示例19: TestStreamRegistryGetStreamByName

func TestStreamRegistryGetStreamByName(t *testing.T) {
	expect := shared.NewExpect(t)
	mockSRegistry := getMockStreamRegistry()

	streamName := mockSRegistry.GetStreamByName("testStream")
	expect.Equal(streamName, nil)

	mockStreamID := GetStreamID("testStream")
	// TODO: Get a real stream and test with that
	mockSRegistry.streams[mockStreamID] = &StreamBase{}
	expect.Equal(mockSRegistry.GetStreamByName("testStream"), &StreamBase{})
}
开发者ID:pombredanne,项目名称:gollum-1,代码行数:12,代码来源:streamregistry_test.go


示例20: TestConsumerControl

func TestConsumerControl(t *testing.T) {
	expect := shared.NewExpect(t)
	mockC := getMockConsumer()
	mockC.control = make(chan PluginControl, 2)

	ctrlChan := mockC.Control()
	ctrlChan <- PluginControlRoll
	ctrlChan <- PluginControlStopConsumer

	expect.Equal(PluginControlRoll, <-mockC.control)
	expect.Equal(PluginControlStopConsumer, <-mockC.control)
}
开发者ID:pombredanne,项目名称:gollum-1,代码行数:12,代码来源:consumer_test.go



注:本文中的github.com/trivago/gollum/shared.NewExpect函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang vect.Float函数代码示例发布时间:2022-05-28
下一篇:
Golang core.PluginConfig类代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap