Пример #1
0
func TestGetSampleString(t *testing.T) {

	// mock changing behavior
	mockData := "FooBar"
	ctrl := gomock.NewController(t)
	defer ctrl.Finish()
	s3mock := myaws.NewMockS3API(ctrl)
	s3mock.EXPECT().GetObject(&s3.GetObjectInput{
		Bucket: aws.String("sample-backet"),
		Key:    aws.String("sample-key"),
	}).Return(&s3.GetObjectOutput{
		Body: ioutil.NopCloser(strings.NewReader(mockData)),
	}, nil)
	myaws.SetClient(s3mock)

	// run
	format := "Fetching data is %v"
	result, err := GetSampleString(format)
	if err != nil {
		t.Fatal(err)
	}

	// assert
	expected := fmt.Sprintf(format, mockData)
	if result != expected {
		t.Errorf("Result is expected '%v', but '%v'.", expected, result)
	}
}
Пример #2
0
func TestGetSampleString2(t *testing.T) {

	// mock
	myaws.SetClient(&myaws.S3MockDoSameThing{})

	// run
	format := "Fetching data is %v"
	result, err := GetSampleString(format)
	if err != nil {
		t.Fatal(err)
	}

	// assert
	expected := fmt.Sprintf(format, "dummy")
	if result != expected {
		t.Errorf("Result is expected '%v', but '%v'.", expected, result)
	}
}