Skip to content

Commit 02c415c

Browse files
committed
Added unit test
1 parent 84337ab commit 02c415c

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

internal/client/client_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,24 @@ func TestOCIClientPushFileStoreCloseError(t *testing.T) {
537537
}
538538
}
539539

540+
func TestOCIClientPushAbsPathError(t *testing.T) {
541+
// Stub absPathFunc to simulate failure
542+
origAbs := absPathFunc
543+
defer func() { absPathFunc = origAbs }()
544+
absPathFunc = func(path string) (string, error) {
545+
return "", fmt.Errorf("abs error")
546+
}
547+
548+
cfg := &config.Config{DefaultRegistry: "example.com"}
549+
client := NewOCIClient(cfg)
550+
551+
// Call Push: path value doesn't matter, stub will error first
552+
err := client.Push(context.Background(), "oci://example.com/repo:tag", "somepath")
553+
if err == nil || !strings.Contains(err.Error(), "failed to resolve absolute path somepath: abs error") {
554+
t.Errorf("expected abs path error, got %v", err)
555+
}
556+
}
557+
540558
func TestOCIClientPushPackManifestError(t *testing.T) {
541559
tmpFile, err := os.CreateTemp("", "test*.txt")
542560
if err != nil {

internal/client/oci_client.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ var (
4949
packManifest = oras.PackManifest
5050
copyFunc = oras.Copy
5151
contentFetcher = content.FetchAll
52+
absPathFunc = filepath.Abs
5253
)
5354

5455
// OCIClient provides an implementation of Client for OCI registries.
@@ -116,7 +117,7 @@ func (c *OCIClient) Push(ctx context.Context, reference, path string) error {
116117
}
117118

118119
// Resolve absolute path and split directory
119-
absPath, err := filepath.Abs(path)
120+
absPath, err := absPathFunc(path)
120121
if err != nil {
121122
return fmt.Errorf("failed to resolve absolute path %s: %w", path, err)
122123
}

0 commit comments

Comments
 (0)