Skip to content

Commit

Permalink
chore: adds LastModified
Browse files Browse the repository at this point in the history
  • Loading branch information
debanjan97 committed Sep 5, 2024
1 parent 2650854 commit f1c5c85
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
15 changes: 9 additions & 6 deletions testhelper/docker/resource/minio/minio.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"path/filepath"
"slices"
"strings"
"time"

"github.com/minio/minio-go/v7"
"github.com/minio/minio-go/v7/pkg/credentials"
Expand All @@ -32,9 +33,10 @@ type Resource struct {
}

type File struct {
Key string
Content string
Etag string
Key string
Content string
Etag string
LastModificationTime time.Time
}

func Setup(pool *dockertest.Pool, d resource.Cleaner, opts ...func(*Config)) (*Resource, error) {
Expand Down Expand Up @@ -158,9 +160,10 @@ func (r *Resource) Contents(ctx context.Context, prefix string) ([]File, error)
}

contents = append(contents, File{
Key: objInfo.Key,
Content: string(b),
Etag: objInfo.ETag,
Key: objInfo.Key,
Content: string(b),
Etag: objInfo.ETag,
LastModificationTime: objInfo.LastModified,
})
}

Expand Down
21 changes: 16 additions & 5 deletions testhelper/docker/resource/minio/minio_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,22 @@ func TestMinioContents(t *testing.T) {
files, err := minioResource.Contents(context.Background(), "test-bucket/")
require.NoError(t, err)

require.Equal(t, []File{
{Key: "test-bucket/empty", Content: "", Etag: etag3},
{Key: "test-bucket/hello.txt", Content: "hello", Etag: etag1},
{Key: "test-bucket/hello.txt.gz", Content: "hello compressed", Etag: etag2},
}, files)
// LastModified is set after the file is uploaded, so we can't compare it
lo.ForEach(files, func(f File, _ int) {
switch f.Key {
case "test-bucket/hello.txt":
require.Equal(t, "hello", f.Content)
require.Equal(t, etag1, f.Etag)
case "test-bucket/hello.txt.gz":
require.Equal(t, "hello compressed", f.Content)
require.Equal(t, etag2, f.Etag)
case "test-bucket/empty":
require.Equal(t, "", f.Content)
require.Equal(t, etag3, f.Etag)
default:
t.Fatalf("unexpected file: %s", f.Key)
}
})

t.Run("canceled context", func(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
Expand Down

0 comments on commit f1c5c85

Please sign in to comment.