コード例 #1
0
func TestExecute(t *testing.T) {
	pluginInput := createStubPluginInput()
	pluginInput.TargetVersion = ""
	config := contracts.Configuration{}
	p := make([]interface{}, 1)
	p[0] = pluginInput
	config.Properties = p
	plugin := &Plugin{}

	pluginInput.TargetVersion = ""
	mockCancelFlag := new(task.MockCancelFlag)
	mockContext := context.NewMockDefault()

	// Create stub
	updateAgent = func(
		p *Plugin,
		config contracts.Configuration,
		log log.T,
		manager pluginHelper,
		util updateutil.T,
		rawPluginInput interface{},
		cancelFlag task.CancelFlag,
		outputS3BucketName string,
		outputS3KeyPrefix string,
		startTime time.Time) (out UpdatePluginOutput) {
		out = UpdatePluginOutput{}
		out.ExitCode = 1
		out.Stderr = "error"

		return out
	}

	// Setup mocks
	mockCancelFlag.On("Canceled").Return(false)
	mockCancelFlag.On("ShutDown").Return(false)
	mockCancelFlag.On("Wait").Return(false).After(100 * time.Millisecond)

	result := plugin.Execute(mockContext, config, mockCancelFlag)

	assert.Equal(t, result.Code, 1)
	assert.Contains(t, result.Output, "error")
}
コード例 #2
0
func setCancelFlagExpectations(mockCancelFlag *task.MockCancelFlag) {
	mockCancelFlag.On("Canceled").Return(false)
	mockCancelFlag.On("ShutDown").Return(false)
}