Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preparation of e2eutils for Thanos indexheader unit tests. #1982

Merged
merged 5 commits into from
Jun 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions pkg/storegateway/bucket_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (

mimir_tsdb "github.com/grafana/mimir/pkg/storage/tsdb"
"github.com/grafana/mimir/pkg/storegateway/indexcache"
"github.com/grafana/mimir/pkg/storegateway/testhelper"

"github.com/thanos-io/thanos/pkg/block"
"github.com/thanos-io/thanos/pkg/block/metadata"
Expand Down Expand Up @@ -90,9 +91,9 @@ func prepareTestBlocks(t testing.TB, now time.Time, count int, dir string, bkt o

// Create two blocks per time slot. Only add 10 samples each so only one chunk
// gets created each. This way we can easily verify we got 10 chunks per series below.
id1, err := CreateBlock(ctx, dir, series[:4], 10, mint, maxt, extLset, 0, metadata.NoneFunc)
id1, err := testhelper.CreateBlock(ctx, dir, series[:4], 10, mint, maxt, extLset, 0, metadata.NoneFunc)
assert.NoError(t, err)
id2, err := CreateBlock(ctx, dir, series[4:], 10, mint, maxt, extLset, 0, metadata.NoneFunc)
id2, err := testhelper.CreateBlock(ctx, dir, series[4:], 10, mint, maxt, extLset, 0, metadata.NoneFunc)
assert.NoError(t, err)

dir1, dir2 := filepath.Join(dir, id1.String()), filepath.Join(dir, id2.String())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Provenance-includes-location: https://github.com/thanos-io/thanos/blob/main/pkg/testutil/e2eutil/prometheus.go
// Provenance-includes-license: Apache-2.0
// Provenance-includes-copyright: The Thanos Authors.
package storegateway
package testhelper

import (
"context"
Expand Down
57 changes: 57 additions & 0 deletions pkg/util/test/copy.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// SPDX-License-Identifier: AGPL-3.0-only
// Provenance-includes-location: https://github.com/thanos-io/thanos/blob/main/pkg/testutil/e2eutil/copy.go
// Provenance-includes-license: Apache-2.0
// Provenance-includes-copyright: The Thanos Authors.

package test

import (
"io"
"os"
"path/filepath"
"testing"

"github.com/grafana/dskit/runutil"
"github.com/pkg/errors"
"github.com/stretchr/testify/require"
)

func Copy(t testing.TB, src, dst string) {
require.NoError(t, copyRecursive(src, dst))
}

func copyRecursive(src, dst string) error {
return filepath.Walk(src, func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}

relPath, err := filepath.Rel(src, path)
if err != nil {
return err
}

if info.IsDir() {
return os.MkdirAll(filepath.Join(dst, relPath), os.ModePerm)
}

if !info.Mode().IsRegular() {
return errors.Errorf("%s is not a regular file", path)
}

source, err := os.Open(filepath.Clean(path))
if err != nil {
return err
}
defer runutil.CloseWithErrCapture(&err, source, "close file")

destination, err := os.Create(filepath.Join(dst, relPath))
if err != nil {
return err
}
defer runutil.CloseWithErrCapture(&err, destination, "close file")

_, err = io.Copy(destination, source)
return err
})
}