From 2acc30693f133ab33676bc0dc125e4c48271a5c2 Mon Sep 17 00:00:00 2001 From: mrjoelkamp Date: Thu, 29 Aug 2024 08:25:42 -0500 Subject: [PATCH] fix: remove mock tuf client output --- pkg/policy/resolver_test.go | 2 +- pkg/tuf/mock.go | 33 ++++----------------------------- 2 files changed, 5 insertions(+), 30 deletions(-) diff --git a/pkg/policy/resolver_test.go b/pkg/policy/resolver_test.go index bfde24c..026bd39 100644 --- a/pkg/policy/resolver_test.go +++ b/pkg/policy/resolver_test.go @@ -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 diff --git a/pkg/tuf/mock.go b/pkg/tuf/mock.go index 9e0f870..f024535 100644 --- a/pkg/tuf/mock.go +++ b/pkg/tuf/mock.go @@ -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 {