Skip to content

Commit

Permalink
add assertions for mocks expectations
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenruizdegauna committed Feb 28, 2025
1 parent 5dc1f53 commit e865340
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 20 deletions.
31 changes: 11 additions & 20 deletions publisher/release/marker_aws_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ func Test_Start(t *testing.T) {
mark, err := markerS3.Start(releaseInfo)
require.NoError(t, err)
require.Equal(t, releaseInfo, mark.ReleaseInfo)
mock.AssertExpectationsForObjects(t, s3ClientMock, timeProviderMock)
}

func Test_StartErrorReadingMarkers(t *testing.T) {
Expand Down Expand Up @@ -105,6 +106,7 @@ func Test_StartErrorReadingMarkers(t *testing.T) {
markerS3 := &markerAWS{timeProvider: timeProviderMock, conf: s3Config, client: s3ClientMock, logfn: nolog}
_, err := markerS3.Start(releaseInfo)
assert.ErrorIs(t, err, someError)
mock.AssertExpectationsForObjects(t, s3ClientMock, timeProviderMock)
}

func Test_StartErrorWritingMarkers(t *testing.T) {
Expand Down Expand Up @@ -158,6 +160,7 @@ func Test_StartErrorWritingMarkers(t *testing.T) {
markerS3 := &markerAWS{timeProvider: timeProviderMock, conf: s3Config, client: s3ClientMock, logfn: nolog}
_, err := markerS3.Start(releaseInfo)
assert.ErrorIs(t, err, someError)
mock.AssertExpectationsForObjects(t, s3ClientMock, timeProviderMock)
}
func Test_End(t *testing.T) {
s3ClientMock := &S3ClientMock{}
Expand Down Expand Up @@ -221,6 +224,7 @@ func Test_End(t *testing.T) {
err := markerS3.End(mark)
require.NoError(t, err)
require.Equal(t, releaseInfo, mark.ReleaseInfo)
mock.AssertExpectationsForObjects(t, s3ClientMock, timeProviderMock)
}

func Test_End_ErrorOnWriting(t *testing.T) {
Expand Down Expand Up @@ -285,6 +289,7 @@ func Test_End_ErrorOnWriting(t *testing.T) {
}
err := markerS3.End(mark)
assert.ErrorIs(t, err, someError)
mock.AssertExpectationsForObjects(t, s3ClientMock, timeProviderMock)
}

func Test_End_ErrorIfNoMarkerFound(t *testing.T) {
Expand All @@ -308,10 +313,6 @@ func Test_End_ErrorIfNoMarkerFound(t *testing.T) {
&s3.GetObjectInput{Bucket: &s3Config.Bucket, Key: aws.String(fmt.Sprintf("%s/%s", s3Config.Directory, markerName))},
&s3.GetObjectOutput{Body: readCloser})

// It should get current time for the end of the started marker
endTime := time.Date(2025, 3, 4, 11, 12, 13, 0, time.UTC)
timeProviderMock.ShouldProvideNow(endTime)

startTime := time.Date(2023, 1, 2, 00, 00, 00, 0, time.UTC)
mark := Mark{
ReleaseInfo: ReleaseInfo{
Expand All @@ -333,6 +334,7 @@ func Test_End_ErrorIfNoMarkerFound(t *testing.T) {
}
err := markerS3.End(mark)
assert.ErrorIs(t, err, ErrNoStartedMarkersFound)
mock.AssertExpectationsForObjects(t, s3ClientMock, timeProviderMock)
}
func Test_End_ErrorOnReadingMarkers(t *testing.T) {
s3ClientMock := &S3ClientMock{}
Expand Down Expand Up @@ -371,6 +373,7 @@ func Test_End_ErrorOnReadingMarkers(t *testing.T) {
}
err := markerS3.End(mark)
assert.ErrorIs(t, err, someError)
mock.AssertExpectationsForObjects(t, s3ClientMock, timeProviderMock)
}

func Test_EndFailsIfLatestMarkerIsEnded(t *testing.T) {
Expand Down Expand Up @@ -398,10 +401,6 @@ func Test_EndFailsIfLatestMarkerIsEnded(t *testing.T) {
&s3.GetObjectInput{Bucket: &s3Config.Bucket, Key: aws.String(fmt.Sprintf("%s/%s", s3Config.Directory, markerName))},
&s3.GetObjectOutput{Body: readCloser})

// It should get current time for the end of the started marker
endTime := time.Date(2025, 3, 4, 11, 12, 13, 0, time.UTC)
timeProviderMock.ShouldProvideNow(endTime)

startTime := time.Date(2023, 1, 2, 00, 00, 00, 0, time.UTC)
mark := Mark{
ReleaseInfo: ReleaseInfo{
Expand All @@ -423,6 +422,7 @@ func Test_EndFailsIfLatestMarkerIsEnded(t *testing.T) {
}
err := markerS3.End(mark)
assert.ErrorIs(t, err, ErrLastMarkerEnded)
mock.AssertExpectationsForObjects(t, s3ClientMock, timeProviderMock)
}

func Test_EndFailsIfMarkerForAppNotFound(t *testing.T) {
Expand Down Expand Up @@ -450,10 +450,6 @@ func Test_EndFailsIfMarkerForAppNotFound(t *testing.T) {
&s3.GetObjectInput{Bucket: &s3Config.Bucket, Key: aws.String(fmt.Sprintf("%s/%s", s3Config.Directory, markerName))},
&s3.GetObjectOutput{Body: readCloser})

// It should get current time for the end of the started marker
endTime := time.Date(2025, 3, 4, 11, 12, 13, 0, time.UTC)
timeProviderMock.ShouldProvideNow(endTime)

startTime := time.Date(2023, 1, 2, 00, 00, 00, 0, time.UTC)
mark := Mark{
ReleaseInfo: ReleaseInfo{
Expand All @@ -475,6 +471,7 @@ func Test_EndFailsIfMarkerForAppNotFound(t *testing.T) {
}
err := markerS3.End(mark)
assert.ErrorIs(t, err, ErrNoStartedMarkerFoundForApp)
mock.AssertExpectationsForObjects(t, s3ClientMock, timeProviderMock)
}

func Test_EndFailsIfMarkerStartTimeIsDifferent(t *testing.T) {
Expand Down Expand Up @@ -502,10 +499,6 @@ func Test_EndFailsIfMarkerStartTimeIsDifferent(t *testing.T) {
&s3.GetObjectInput{Bucket: &s3Config.Bucket, Key: aws.String(fmt.Sprintf("%s/%s", s3Config.Directory, markerName))},
&s3.GetObjectOutput{Body: readCloser})

// It should get current time for the end of the started marker
endTime := time.Date(2025, 3, 4, 11, 12, 13, 0, time.UTC)
timeProviderMock.ShouldProvideNow(endTime)

startTime := time.Date(2023, 1, 2, 00, 00, 00, 0, time.UTC)
mark := Mark{
ReleaseInfo: ReleaseInfo{
Expand All @@ -527,6 +520,7 @@ func Test_EndFailsIfMarkerStartTimeIsDifferent(t *testing.T) {
}
err := markerS3.End(mark)
assert.ErrorIs(t, err, ErrNoStartedMarkerFoundForApp)
mock.AssertExpectationsForObjects(t, s3ClientMock, timeProviderMock)
}

func Test_EndFailsIfMarkerStartIsZero(t *testing.T) {
Expand Down Expand Up @@ -554,10 +548,6 @@ func Test_EndFailsIfMarkerStartIsZero(t *testing.T) {
&s3.GetObjectInput{Bucket: &s3Config.Bucket, Key: aws.String(fmt.Sprintf("%s/%s", s3Config.Directory, markerName))},
&s3.GetObjectOutput{Body: readCloser})

// It should get current time for the end of the started marker
endTime := time.Date(2025, 3, 4, 11, 12, 13, 0, time.UTC)
timeProviderMock.ShouldProvideNow(endTime)

startTime := time.Time{}
mark := Mark{
ReleaseInfo: ReleaseInfo{
Expand All @@ -579,6 +569,7 @@ func Test_EndFailsIfMarkerStartIsZero(t *testing.T) {
}
err := markerS3.End(mark)
assert.ErrorIs(t, err, ErrNotStartedMark)
mock.AssertExpectationsForObjects(t, s3ClientMock, timeProviderMock)
}

///////////////////////////////////////////////////////////////
Expand Down
1 change: 1 addition & 0 deletions publisher/upload/upload_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ func TestUploadArtifacts(t *testing.T) {
_, err = os.Stat(path.Join(dest, expectedFile))
assert.NoError(t, err)
}
mock.AssertExpectationsForObjects(t, marker)
})
}

Expand Down

0 comments on commit e865340

Please sign in to comment.