Files
zot/pkg/storage/local/driver_internal_test.go
Andrei Aaron 5309e7f5cf chore: increase/stabilize go test coverage (#3411)
* chore: increase/stabilize coverage for the local storage driver

Signed-off-by: Andrei Aaron <andreifdaaron@gmail.com>

* chore: add/stabilize coverage for soring ImageSummary objects

Signed-off-by: Andrei Aaron <andreifdaaron@gmail.com>

* chore: stabilize coverage in sync tests

Signed-off-by: Andrei Aaron <andreifdaaron@gmail.com>

---------

Signed-off-by: Andrei Aaron <andreifdaaron@gmail.com>
2025-10-01 15:24:38 -07:00

66 lines
2.1 KiB
Go

package local
import (
"errors"
"testing"
storagedriver "github.com/distribution/distribution/v3/registry/storage/driver"
. "github.com/smartystreets/goconvey/convey"
)
func TestFormatErr(t *testing.T) {
Convey("Test formatErr error handling", t, func() {
driver := New(true)
Convey("Test formatErr with nil error", func() {
err := driver.formatErr(nil)
So(err, ShouldBeNil)
})
Convey("Test formatErr with PathNotFoundError", func() {
pathErr := storagedriver.PathNotFoundError{Path: "/test"}
formatted := driver.formatErr(pathErr)
So(formatted, ShouldNotBeNil)
// Check if it's still a PathNotFoundError with driver name set
var pathNotFoundErr storagedriver.PathNotFoundError
So(errors.As(formatted, &pathNotFoundErr), ShouldBeTrue)
So(pathNotFoundErr.DriverName, ShouldEqual, "local")
})
Convey("Test formatErr with InvalidPathError", func() {
invalidErr := storagedriver.InvalidPathError{Path: "/test"}
formatted := driver.formatErr(invalidErr)
So(formatted, ShouldNotBeNil)
// Check if it's still an InvalidPathError with driver name set
var invalidPathErr storagedriver.InvalidPathError
So(errors.As(formatted, &invalidPathErr), ShouldBeTrue)
So(invalidPathErr.DriverName, ShouldEqual, "local")
})
Convey("Test formatErr with InvalidOffsetError", func() {
offsetErr := storagedriver.InvalidOffsetError{Path: "/test", Offset: 100}
formatted := driver.formatErr(offsetErr)
So(formatted, ShouldNotBeNil)
// Check if it's still an InvalidOffsetError with driver name set
var invalidOffsetErr storagedriver.InvalidOffsetError
So(errors.As(formatted, &invalidOffsetErr), ShouldBeTrue)
So(invalidOffsetErr.DriverName, ShouldEqual, "local")
})
Convey("Test formatErr with generic error", func() {
genericErr := errors.New("generic error")
formatted := driver.formatErr(genericErr)
So(formatted, ShouldNotBeNil)
// Check if it's wrapped in a storagedriver.Error
var storageErr storagedriver.Error
So(errors.As(formatted, &storageErr), ShouldBeTrue)
So(storageErr.DriverName, ShouldEqual, "local")
So(storageErr.Detail, ShouldEqual, genericErr)
})
})
}