fix(snapshot): check duplicate name even when renaming to same name

The SnapshotsAPITestCreateUpdate test expects that PUT /api/snapshots/:name
with the same Name in the body returns a conflict error. The previous fix
added 'b.Name != name' guards to skip the duplicate check when the name
hasn't changed, but this broke the test which expects the old behavior:
any existing name (including the snapshot's own current name) should be
rejected as a duplicate.

Remove the 'b.Name != name' condition from both the pre-task validation
and the in-task duplicate check so the behavior matches the original.
This commit is contained in:
André Roth
2026-05-25 18:22:37 +00:00
parent b8373b0afc
commit 7362e7ee3b
+3 -3
View File
@@ -340,7 +340,7 @@ func apiSnapshotsUpdate(c *gin.Context) {
} }
// Pre-task validation of new name if provided // Pre-task validation of new name if provided
if b.Name != "" && b.Name != name { if b.Name != "" {
_, err = collection.ByName(b.Name) _, err = collection.ByName(b.Name)
if err == nil { if err == nil {
AbortWithJSONError(c, 409, fmt.Errorf("unable to rename: snapshot %s already exists", b.Name)) AbortWithJSONError(c, 409, fmt.Errorf("unable to rename: snapshot %s already exists", b.Name))
@@ -362,8 +362,8 @@ func apiSnapshotsUpdate(c *gin.Context) {
return &task.ProcessReturnValue{Code: http.StatusInternalServerError, Value: nil}, err return &task.ProcessReturnValue{Code: http.StatusInternalServerError, Value: nil}, err
} }
// Fresh duplicate check inside lock (if renaming) // Fresh duplicate check inside lock
if b.Name != "" && b.Name != name { if b.Name != "" {
_, err := taskCollection.ByName(b.Name) _, err := taskCollection.ByName(b.Name)
if err == nil { if err == nil {
return &task.ProcessReturnValue{Code: http.StatusConflict, Value: nil}, fmt.Errorf("unable to rename: snapshot %s already exists", b.Name) return &task.ProcessReturnValue{Code: http.StatusConflict, Value: nil}, fmt.Errorf("unable to rename: snapshot %s already exists", b.Name)