fix: remove mock tuf client output

This commit is contained in:
mrjoelkamp
2024-08-29 08:25:42 -05:00
parent 5db1b5c4c1
commit 2acc30693f
2 changed files with 5 additions and 30 deletions

View File

@@ -41,7 +41,7 @@ func TestResolvePolicy(t *testing.T) {
opts := &policy.Options{}
tempDir := test.CreateTempDir(t, "", "tuf-dest")
if !tc.DisableTUF {
tufClient = tuf.NewMockTufClient(tufPolicyPath, tempDir)
tufClient = tuf.NewMockTufClient(tufPolicyPath)
}
if tc.policyID != "" {
opts.PolicyID = tc.policyID

View File

@@ -10,23 +10,18 @@ import (
type MockTufClient struct {
srcPath string
dstPath string
}
func NewMockTufClient(srcPath string, dstPath string) *MockTufClient {
func NewMockTufClient(srcPath string) *MockTufClient {
if srcPath == "" {
panic("srcPath must be set")
}
if dstPath == "" {
panic("dstPath must be set")
}
return &MockTufClient{
srcPath: srcPath,
dstPath: dstPath,
}
}
func (dc *MockTufClient) DownloadTarget(target string, filePath string) (file *TargetFile, err error) {
func (dc *MockTufClient) DownloadTarget(target string, _ string) (file *TargetFile, err error) {
targetPath := filepath.Join(dc.srcPath, target)
src, err := os.Open(targetPath)
if err != nil {
@@ -34,32 +29,12 @@ func (dc *MockTufClient) DownloadTarget(target string, filePath string) (file *T
}
defer src.Close()
var dstFilePath string
if filePath == "" {
dstFilePath = filepath.Join(dc.dstPath, filepath.FromSlash(target))
} else {
dstFilePath = filePath
}
err = os.MkdirAll(filepath.Dir(dstFilePath), os.ModePerm)
if err != nil {
return nil, err
}
dst, err := os.Create(dstFilePath)
if err != nil {
return nil, err
}
defer dst.Close()
// reading from tee will read from src and write to dst at the same time
tee := io.TeeReader(src, dst)
b, err := io.ReadAll(tee)
b, err := io.ReadAll(src)
if err != nil {
return nil, err
}
return &TargetFile{ActualFilePath: dstFilePath, TargetURI: targetPath, Data: b, Digest: util.SHA256Hex(b)}, nil
return &TargetFile{TargetURI: targetPath, Data: b, Digest: util.SHA256Hex(b)}, nil
}
type MockVersionChecker struct {