Skip to content

Commit

Permalink
[#66] fix ReplacePathFileProc.Process mapping entity.DataFile.Data
Browse files Browse the repository at this point in the history
  • Loading branch information
kozmod committed Feb 18, 2023
1 parent cc08091 commit ad4ab02
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
5 changes: 4 additions & 1 deletion internal/exec/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,10 @@ func NewReplacePathFileProc(paths map[string]string) *ReplacePathFileProc {
func (p *ReplacePathFileProc) Process(file entity.DataFile) (entity.DataFile, error) {
newPath, ok := p.paths[file.Path()]
if ok {
file = entity.DataFile{FileInfo: entity.NewFileInfo(newPath)}
file = entity.DataFile{
FileInfo: entity.NewFileInfo(newPath),
Data: file.Data,
}
}
return file, nil
}
Expand Down
7 changes: 5 additions & 2 deletions internal/exec/file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ func Test_ReplacePathFileProc(t *testing.T) {
oldPathA = "old_1/old_A.go"
oldPathB = "old_1/old_B.go"
newPathA = "old_1/new_A.go"
someData = "DATA_!!!"
)

var (
Expand All @@ -238,15 +239,17 @@ func Test_ReplacePathFileProc(t *testing.T) {

t.Run("success_replace_old_path_to_new_one", func(t *testing.T) {
proc := ReplacePathFileProc{paths: paths}
res, err := proc.Process(entity.DataFile{Data: nil, FileInfo: entity.NewFileInfo(oldPathA)})
res, err := proc.Process(entity.DataFile{Data: []byte(someData), FileInfo: entity.NewFileInfo(oldPathA)})
assert.NoError(t, err)
assert.Equal(t, newPathA, res.Path())
assert.Equal(t, []byte(someData), res.Data)
})
t.Run("success_nit_replace_old_path_when_new_one_not_present", func(t *testing.T) {
proc := ReplacePathFileProc{paths: paths}
res, err := proc.Process(entity.DataFile{Data: nil, FileInfo: entity.NewFileInfo(oldPathB)})
res, err := proc.Process(entity.DataFile{Data: []byte(someData), FileInfo: entity.NewFileInfo(oldPathB)})
assert.NoError(t, err)
assert.Equal(t, oldPathB, res.Path())
assert.Equal(t, []byte(someData), res.Data)
})
}

Expand Down

0 comments on commit ad4ab02

Please sign in to comment.