-
Notifications
You must be signed in to change notification settings - Fork 544
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Preparation of e2eutils for Thanos indexheader unit tests. (#1982)
We want to pull in the indexheader package from Thanos so that we can add some experimental alternative implementations of BinaryReader. In order to also pull in the unit tests for this package, we need the replacements for e2eutil.Copy and e2eutil.CreateBlock. This change does two things: 1. Copy in e2eutil/copy.go and fix it up accordingly. 2. Move CreateBlock into a package to avoid circular imports.
- Loading branch information
Showing
3 changed files
with
61 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}) | ||
} |