Skip to content

Commit

Permalink
add test caes
Browse files Browse the repository at this point in the history
Signed-off-by: nitishfy <[email protected]>
  • Loading branch information
nitishfy committed Dec 18, 2024
1 parent a38c6c1 commit 6985ec0
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
8 changes: 7 additions & 1 deletion internal/directives/file_deleter.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,14 @@ func (f *fileDeleter) runPromotionStep(

symlink, err := f.isSymlink(absPath)

/* TODO
if err != nil {
}
*/

if symlink {
err := os.Remove(absPath)
err = os.Remove(absPath)
if err != nil {
return PromotionStepResult{}, err
}

Check warning on line 77 in internal/directives/file_deleter.go

View check run for this annotation

Codecov / codecov/patch

internal/directives/file_deleter.go#L76-L77

Added lines #L76 - L77 were not covered by tests
Expand Down
28 changes: 28 additions & 0 deletions internal/directives/file_deleter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,34 @@ func Test_fileDeleter_runPromotionStep(t *testing.T) {
assert.True(t, os.IsNotExist(statErr))
},
},
{
name: "removes a file within a symlink",
setupFiles: func(t *testing.T) string {
tmpDir := t.TempDir()

inDir := filepath.Join(tmpDir, "bar")
require.NoError(t, os.Mkdir(inDir, 0o755))

filePath := filepath.Join(inDir, "file.txt")
require.NoError(t, os.WriteFile(filePath, []byte("test content"), 0o600))

symlinkPath := filepath.Join(tmpDir, "foo")
require.NoError(t, os.Symlink(inDir, symlinkPath))

return tmpDir
},
cfg: DeleteConfig{
Path: "foo",
},
assertions: func(t *testing.T, workDir string, result PromotionStepResult, err error) {
assert.NoError(t, err)
require.Equal(t, PromotionStepResult{Status: kargoapi.PromotionPhaseSucceeded}, result)

_, statErr := os.Stat(filepath.Join(workDir, "foo", "file.txt"))
assert.Error(t, statErr)
assert.True(t, os.IsNotExist(statErr))
},
},
}
runner := &fileDeleter{}

Expand Down

0 comments on commit 6985ec0

Please sign in to comment.