-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
backup: fix working directory change (#20)
* restore working dir after backup backup.Perform was using os.Chdir, which changes working directory for the entire process. This in practice did not have any effect, but is the potential source of future bugs as it's an unexpected occurrence. Solve this by restoring working directory after executing the backup. A dedicated test case is provided. * goimports * fix golangcilint * comment unused code * lint 📿 * lint
- Loading branch information
Showing
6 changed files
with
97 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package backup_test | ||
|
||
import ( | ||
"bytes" | ||
"os" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
|
||
"github.com/endorama/devid/internal/backup" | ||
) | ||
|
||
func TestPerform(t *testing.T) { | ||
// type args struct { | ||
// b backup.Task | ||
// passphrase string | ||
// } | ||
// tests := []struct { | ||
// name string | ||
// args args | ||
// wantErr bool | ||
// }{ | ||
// // TODO: Add test cases. | ||
// } | ||
// for _, tt := range tests { | ||
// t.Run(tt.name, func(t *testing.T) { | ||
// if err := backup.Perform(tt.args.b, tt.args.passphrase); (err != nil) != tt.wantErr { | ||
// t.Errorf("Perform() error = %v, wantErr %v", err, tt.wantErr) | ||
// } | ||
// }) | ||
// } | ||
t.Skip("not implemented") | ||
} | ||
|
||
func TestPerform_Chdir(t *testing.T) { | ||
var out bytes.Buffer | ||
tk, err := backup.NewTask("test", "testdata", &out) | ||
assert.NoError(t, err) | ||
|
||
want, err := os.Getwd() | ||
assert.NoError(t, err) | ||
|
||
err = backup.Perform(tk, "test") | ||
assert.NoError(t, err) | ||
|
||
got, err := os.Getwd() | ||
assert.NoError(t, err) | ||
|
||
assert.Equal(t, want, got) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Foo Bar |