當前位置: 首頁>>代碼示例>>Golang>>正文


Golang log.NewMockLog函數代碼示例

本文整理匯總了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;未經允許,請勿轉載。