Beispiel #1
0
func TestNextBadVersionData(t *testing.T) {
	vs := Versions{
		Version{
			Version:   "1",
			Published: true,
		},
		Version{
			Version:   "2",
			Published: false,
			Required:  true, // Required but not Published makes no sense
		},
	}

	next, err := vs.Next("1")
	assert.Equal(t, "", next)
	assert.EqualError(t, err, `current version "1" is latest`)

	vs = Versions{
		Version{
			Version:   "1",
			Published: false,
		},
		Version{
			Version:   "2",
			Published: false, // nothing Published is not helpful
		},
	}

	latest, err := vs.Latest()
	assert.Equal(t, "", latest.Version)
	assert.EqualError(t, err, `no published versions`)
}
Beispiel #2
0
func TestUploadOrderReadFail1(t *testing.T) {
	s, ops, _ := loggingSvc(emptyList)
	mgr := s3manager.NewUploaderWithClient(s)
	_, err := mgr.Upload(&s3manager.UploadInput{
		Bucket: aws.String("Bucket"),
		Key:    aws.String("Key"),
		Body:   &failreader{times: 1},
	})

	assert.Equal(t, "ReadRequestBody", err.(awserr.Error).Code())
	assert.EqualError(t, err.(awserr.Error).OrigErr(), "random failure")
	assert.Equal(t, []string{}, *ops)
}
Beispiel #3
0
func TestUploadOrderReadFail2(t *testing.T) {
	s, ops, _ := loggingSvc([]string{"UploadPart"})
	mgr := s3manager.NewUploaderWithClient(s, func(u *s3manager.Uploader) {
		u.Concurrency = 1
	})
	_, err := mgr.Upload(&s3manager.UploadInput{
		Bucket: aws.String("Bucket"),
		Key:    aws.String("Key"),
		Body:   &failreader{times: 2},
	})

	assert.Equal(t, "ReadRequestBody", err.(awserr.Error).Code())
	assert.EqualError(t, err.(awserr.Error).OrigErr(), "random failure")
	assert.Equal(t, []string{"CreateMultipartUpload", "AbortMultipartUpload"}, *ops)
}
Beispiel #4
0
func TestNext(t *testing.T) {
	vs := Versions{
		Version{
			Version:   "1",
			Published: true,
		},
		Version{
			Version:   "2",
			Published: false,
		},
		Version{
			Version:   "3",
			Published: true,
		},
		Version{
			Version:   "4",
			Published: true,
			Required:  true,
		},
		Version{
			Version:   "5",
			Published: true,
			Required:  true,
		},
		Version{
			Version:   "6",
			Published: true,
		},
		Version{
			Version:   "7",
			Published: true,
		},
		Version{
			Version:   "8",
			Published: true,
		},
		Version{
			Version:   "9",
			Published: false,
		},
	}

	next, err := vs.Next("10")
	assert.Equal(t, "", next)
	assert.EqualError(t, err, `current version "10" not found`)

	next, err = vs.Next("1")
	assert.Equal(t, "4", next, "from version 1, next required version is 4")
	assert.Nil(t, err)

	next, err = vs.Next("4")
	assert.Equal(t, "5", next, "from version 4, next required version is 5")
	assert.Nil(t, err)

	next, err = vs.Next("5")
	assert.Equal(t, "8", next, "from version 5, latest published version is 8")
	assert.Nil(t, err)

	next, err = vs.Next("8")
	assert.Equal(t, "", next)
	assert.EqualError(t, err, `current version "8" is latest`)
}
Beispiel #5
0
// EqualError asserts that a function returned an error (i.e. not `nil`)
// and that it is equal to the provided error.
//
//   actualObj, err := SomeFunction()
//   if assert.Error(t, err, "An error was expected") {
// 	   assert.Equal(t, err, expectedError)
//   }
//
// Returns whether the assertion was successful (true) or not (false).
func EqualError(t TestingT, theError error, errString string, msgAndArgs ...interface{}) {
	if !assert.EqualError(t, theError, errString, msgAndArgs...) {
		t.FailNow()
	}
}