Skip to content

Commit

Permalink
Updated error handling and added new test (#172)
Browse files Browse the repository at this point in the history
- Changed the logging level from Error to Warning when a delete operation fails.
- Added a new test case in mv_test.go to verify the behavior when a file doesn't exist. The test creates a file, moves it, verifies its existence at the destination and non-existence at the source, then deletes it and checks that it no longer exists at either location.
  • Loading branch information
UnstoppableMango authored Aug 24, 2024
1 parent af636c5 commit 4d96e62
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
3 changes: 1 addition & 2 deletions provider/pkg/provider/cmd/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@ func (s *State[T]) Delete(ctx context.Context) error {
}

if len(failed) > 0 {
log.ErrorStatusf("%d delete operation(s) failed", len(failed))
return fmt.Errorf("a delete operation failed: %v", failed)
log.WarningStatusf("%d delete operation(s) failed", len(failed))
}
}

Expand Down
38 changes: 38 additions & 0 deletions tests/lifecycle/mv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,44 @@ var _ = Describe("Mv", func() {
Expect(provisioner).To(ContainFile(ctx, final))
})

It("should delete when file doesn't exist", func(ctx context.Context) {
source := containerPath("mv-custom1.txt")
dest := containerPath("mv-custom2.txt")

By("creating a file to be moved")
err := provisioner.WriteFile(ctx, source, []byte("some text"))
Expect(err).NotTo(HaveOccurred())

run(server, integration.LifeCycleTest{
Resource: resource,
Create: integration.Operation{
Inputs: pr.NewPropertyMapFromMap(map[string]interface{}{
"args": map[string]interface{}{
"source": []string{source},
"destination": dest,
},
}),
Hook: func(inputs, output pr.PropertyMap) {
Expect(output["stderr"]).To(HavePropertyValue(""))
Expect(output["stdout"]).To(HavePropertyValue(""))
Expect(output["exitCode"]).To(HavePropertyValue(0))
Expect(output["createdFiles"].V).To(BeEmpty())
Expect(output["movedFiles"].V).To(Equal(pr.NewPropertyMapFromMap(map[string]interface{}{
source: dest,
})))
Expect(output["args"]).To(Equal(inputs["args"]))
Expect(provisioner).NotTo(ContainFile(ctx, source))
Expect(provisioner).To(ContainFile(ctx, dest))
provisioner.Exec(ctx, "rm", dest)
Expect(provisioner).NotTo(ContainFile(ctx, dest))
},
},
})

Expect(provisioner).NotTo(ContainFile(ctx, source))
Expect(provisioner).NotTo(ContainFile(ctx, dest))
})

It("should fail when source doesn't exist", func() {
run(server, integration.LifeCycleTest{
Resource: resource,
Expand Down

0 comments on commit 4d96e62

Please sign in to comment.