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

Golang log.NewMockLog函数代码示例

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

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



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

示例1: TestParseManifest

//TestParseManifest testing parses valid manfiest files
func TestParseManifest(t *testing.T) {
	// generate test cases
	var testCases []testCase
	for _, manifestFile := range sampleManifests {
		testCases = append(testCases, testCase{
			Input:  string(manifestFile),
			Output: loadManifestFromFile(t, manifestFile),
		})
	}
	agentName := "amazon-ssm-agent"
	log := log.NewMockLog()
	context := mockInstanceContext()
	// run tests
	for _, tst := range testCases {
		// call method
		parsedMsg, err := ParseManifest(log, tst.Input, context, agentName)

		// check results
		assert.Nil(t, err)
		assert.Equal(t, tst.Output, parsedMsg)
		assert.Equal(t, parsedMsg.Packages[0].Name, agentName)
		assert.Equal(t, parsedMsg.Packages[0].Files[0].Name, "amazon-ssm-agent-linux-amd64.tar.gz")
		assert.Equal(
			t,
			parsedMsg.Packages[0].Files[0].AvailableVersions[0].Version,
			"1.0.178.0")
		assert.Equal(
			t,
			parsedMsg.Packages[0].Files[0].AvailableVersions[0].Checksum,
			"d2b67b804e0c3d3d83d09992a6a62b9e6a79fa3214b00685b07998b4e548870e")
	}
}
开发者ID:aws,项目名称:amazon-ssm-agent,代码行数:33,代码来源:parser_test.go


示例2: ExampleSha256HashValue

func ExampleSha256HashValue() {
	path := filepath.Join("testdata", "CheckMyHash.txt")
	mockLog := log.NewMockLog()
	content, _ := Sha256HashValue(mockLog, path)
	fmt.Println(content)
	// Output:
	// 090c1965e46155b2b23ba9093ed7c67243957a397e3ad5531a693d57958a760a
}
开发者ID:aws,项目名称:amazon-ssm-agent,代码行数:8,代码来源:artifact_integ_test.go


示例3: ExampleMd5HashValue

func ExampleMd5HashValue() {
	path := filepath.Join("testdata", "CheckMyHash.txt")
	mockLog := log.NewMockLog()
	content, _ := Md5HashValue(mockLog, path)
	fmt.Println(content)
	// Output:
	// e84913ff3a8eef39238b32170e657ba8
}
开发者ID:aws,项目名称:amazon-ssm-agent,代码行数:8,代码来源:artifact_integ_test.go


示例4: MockContext

// NewMockDefault returns an instance of Mock with default expectations set.
func MockContext() *context.Mock {
	ctx := new(context.Mock)
	log := log.NewMockLog()
	config := appconfig.SsmagentConfig{}
	ctx.On("Log").Return(log)
	ctx.On("AppConfig").Return(config)
	ctx.On("With", mock.AnythingOfType("string")).Return(ctx)
	return ctx
}
开发者ID:aws,项目名称:amazon-ssm-agent,代码行数:10,代码来源:processor_scheduler_integ_test.go


示例5: NewMockDefault

// NewMockDefault returns an instance of Mock with default expectations set.
func NewMockDefault() *Mock {
	ctx := new(Mock)
	log := log.NewMockLog()
	config := appconfig.NewMockAppConfig()
	ctx.On("Log").Return(log)
	ctx.On("AppConfig").Return(config)
	ctx.On("With", mock.AnythingOfType("string")).Return(ctx)
	return ctx
}
开发者ID:aws,项目名称:amazon-ssm-agent,代码行数:10,代码来源:test_context.go


示例6: TestGetPlatformName

func TestGetPlatformName(t *testing.T) {
	var log = logger.NewMockLog()
	t.Log("get platform name and version")
	data, err := PlatformName(log)
	t.Logf("platform name is %v ", data)
	assert.NoError(t, err, "get platform name should not result in err")
	data, err = PlatformVersion(log)
	t.Logf("platform version is %v ", data)
	assert.NoError(t, err, "get platform version should not result in err")
}
开发者ID:aws,项目名称:amazon-ssm-agent,代码行数:10,代码来源:platform_integ_test.go


示例7: TestUpdaterFailedSetRegion

func TestUpdaterFailedSetRegion(t *testing.T) {
	// setup
	log = logger.NewMockLog()
	region = regionFailedStub
	updater = &stubUpdater{returnUpdateError: true}

	os.Args = updateCommand

	// action
	main()
}
开发者ID:aws,项目名称:amazon-ssm-agent,代码行数:11,代码来源:updater_test.go


示例8: TestUpdater

func TestUpdater(t *testing.T) {
	// setup
	log = logger.NewMockLog()
	region = regionStub
	updater = &stubUpdater{}

	os.Args = updateCommand

	// action
	main()
}
开发者ID:aws,项目名称:amazon-ssm-agent,代码行数:11,代码来源:updater_test.go


示例9: TestUpdaterWithDowngrade

func TestUpdaterWithDowngrade(t *testing.T) {
	// setup
	log = logger.NewMockLog()
	region = regionStub
	updater = &stubUpdater{returnUpdateError: true}

	os.Args = []string{"updater", "-update", "-source.version", "5.0.0.0", "-source.location", "http://source",
		"-target.version", "1.0.0.0", "-target.location", "http://target"}

	// action
	main()

	// assert
	assert.Equal(t, *sourceVersion, "5.0.0.0")
	assert.Equal(t, *targetVersion, "1.0.0.0")
}
开发者ID:aws,项目名称:amazon-ssm-agent,代码行数:16,代码来源:updater_test.go


示例10: TestUpdaterFailedWithoutSourceTargetCmd

func TestUpdaterFailedWithoutSourceTargetCmd(t *testing.T) {
	// setup
	log = logger.NewMockLog()
	region = regionStub
	updater = &stubUpdater{returnUpdateError: true}

	os.Args = []string{"updater", "-update", "-source.version", "", "-source.location", "http://source",
		"-target.version", "", "-target.location", "http://target"}

	// action
	main()

	// assert
	assert.Equal(t, *update, true)
	assert.Empty(t, *sourceVersion)
	assert.Empty(t, *targetVersion)
}
开发者ID:aws,项目名称:amazon-ssm-agent,代码行数:17,代码来源:updater_test.go


示例11: TestValidateExecutionTimeout

func TestValidateExecutionTimeout(t *testing.T) {
	logger := log.NewMockLog()
	logger.On("Error", mock.Anything).Return(nil)
	logger.On("Info", mock.Anything).Return(nil)

	// Run tests
	var input interface{}
	var num int

	// Check with a value less than min value
	input = 3
	num = ValidateExecutionTimeout(logger, input)
	assert.Equal(t, defaultExecutionTimeoutInSeconds, num)

	// Check with a value more than max value
	input = 28900
	num = ValidateExecutionTimeout(logger, input)
	assert.Equal(t, defaultExecutionTimeoutInSeconds, num)

	// Check with a float64 value
	input = 5.0
	num = ValidateExecutionTimeout(logger, input)
	assert.Equal(t, 5, num)

	// Check with int in a string
	input = "10"
	num = ValidateExecutionTimeout(logger, input)
	assert.Equal(t, 10, num)

	// Check with float64 in a string
	input = "10.5"
	num = ValidateExecutionTimeout(logger, input)
	assert.Equal(t, 10, num)

	// Check with character string
	input = "test"
	num = ValidateExecutionTimeout(logger, input)
	assert.Equal(t, defaultExecutionTimeoutInSeconds, num)
}
开发者ID:aws,项目名称:amazon-ssm-agent,代码行数:39,代码来源:pluginutil_test.go


示例12: TestParseManifestWithError

//Test ParseManifest with invalid manifest files
func TestParseManifestWithError(t *testing.T) {
	// generate test cases
	var testCases []testCase
	for _, manifestFile := range errorManifests {
		testCases = append(testCases, testCase{
			Input:  string(manifestFile),
			Output: loadManifestFromFile(t, manifestFile),
		})
	}
	agentName := "amazon-ssm-agent"
	log := log.NewMockLog()
	context := mockInstanceContext()
	// run tests
	for _, tst := range testCases {
		// call method
		parsedMsg, err := ParseManifest(log, tst.Input, context, agentName)

		// check results
		assert.NotNil(t, err)
		assert.Equal(t, tst.Output, parsedMsg)
	}
}
开发者ID:aws,项目名称:amazon-ssm-agent,代码行数:23,代码来源:parser_test.go


示例13: TestHandleAwsErrorCount

func TestHandleAwsErrorCount(t *testing.T) {
	errorCount := 10
	stopPolicy := NewStopPolicy("test", errorCount)

	log := log.NewMockLog()

	for i := 0; i < errorCount-1; i++ {
		HandleAwsError(log, errSample, stopPolicy)
		if !stopPolicy.IsHealthy() {
			assert.Fail(t, "stoppolicy should be healthy")
		}
	}

	HandleAwsError(log, errSample, stopPolicy)
	if stopPolicy.IsHealthy() {
		assert.Fail(t, "stoppolicy should not be healthy")
	}

	HandleAwsError(log, nil, stopPolicy)
	if !stopPolicy.IsHealthy() {
		assert.Fail(t, "stoppolicy should have reset and be heallthy")
	}

}
开发者ID:aws,项目名称:amazon-ssm-agent,代码行数:24,代码来源:awserr_test.go


示例14: TestRunCommand

}

var ShellCommandExecuterCancelTestCases = []TestCase{
	{
		Commands: []string{
			"sh",
			"-c",
			echoToStdout(stdoutMsg) + ";" + echoToStderr(stderrMsg) + ";" + "sleep 10" + ";" + echoToStdout("bye stdout") + ";" + echoToStderr("bye stderr"),
		},
		ExpectedStdout:   stdoutMsg + "\n",
		ExpectedStderr:   stderrMsg + "\n",
		ExpectedExitCode: processTerminatedByUserExitCode,
	},
}

var logger = log.NewMockLog()

// TestRunCommand tests that RunCommand (in memory call, no local script or output files) works correctly.
func TestRunCommand(t *testing.T) {
	for _, testCase := range RunCommandTestCases {
		runCommandInvoker, _ := prepareTestRunCommand(t)
		testCommandInvoker(t, runCommandInvoker, testCase)
	}
}

// TestRunCommand_cancel tests that RunCommand (in memory call, no local script or output files) is canceled correctly.
func TestRunCommand_cancel(t *testing.T) {
	for _, testCase := range RunCommandCancelTestCases {
		runCommandInvoker, cancelFlag := prepareTestRunCommand(t)
		testCommandInvokerCancel(t, runCommandInvoker, cancelFlag, testCase)
	}
开发者ID:aws,项目名称:amazon-ssm-agent,代码行数:31,代码来源:executers_integ_test.go


示例15:

	"fmt"

	"github.com/aws/amazon-ssm-agent/agent/log"
	"github.com/stretchr/testify/assert"
)

type DownloadTest struct {
	input          DownloadInput
	expectedOutput DownloadOutput
}

var (
	localPathExist, _    = filepath.Abs(filepath.Join(".", "testdata", "CheckMyHash.txt"))
	localPathNotExist, _ = filepath.Abs(filepath.Join(".", "testdata", "IDontExist.txt"))
	downloadFolder, _    = filepath.Abs(filepath.Join(".", "testdata"))
	mockLog              = log.NewMockLog()

	downloadTests = []DownloadTest{
		// {DownloadInput{SourceUrl, DestinationDirectory, SourceHashValue, SourceHashType},
		// DownloadOutput{LocalFilePath, IsUpdated, IsHashMatched}},
		{
			// validate sha256
			DownloadInput{
				localPathExist,
				downloadFolder,
				"090c1965e46155b2b23ba9093ed7c67243957a397e3ad5531a693d57958a760a",
				"sha256"},
			DownloadOutput{
				localPathExist,
				false,
				true},
开发者ID:aws,项目名称:amazon-ssm-agent,代码行数:31,代码来源:artifact_integ_test.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang log.T类代码示例发布时间:2022-05-24
下一篇:
Golang context.T类代码示例发布时间:2022-05-24
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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