mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-02-11 13:53:25 +02:00
Cleanup: improve test setup and check for the right error string
Use the assert package to check expectations; also, check for the exact error message instead of just whether any error occurred.
This commit is contained in:
parent
8932d17393
commit
bf685cf832
@ -1,6 +1,10 @@
|
||||
package yaml_utils
|
||||
|
||||
import "testing"
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestUpdateYaml(t *testing.T) {
|
||||
tests := []struct {
|
||||
@ -49,16 +53,14 @@ func TestUpdateYaml(t *testing.T) {
|
||||
for _, test := range tests {
|
||||
test := test
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
out, err := UpdateYaml([]byte(test.in), test.path, test.value)
|
||||
if test.expectedErr != "" {
|
||||
if err == nil {
|
||||
t.Errorf("expected error %q but got none", test.expectedErr)
|
||||
}
|
||||
} else if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
} else if string(out) != test.expectedOut {
|
||||
t.Errorf("expected %q but got %q", test.expectedOut, string(out))
|
||||
out, actualErr := UpdateYaml([]byte(test.in), test.path, test.value)
|
||||
if test.expectedErr == "" {
|
||||
assert.NoError(t, actualErr)
|
||||
} else {
|
||||
assert.EqualError(t, actualErr, test.expectedErr)
|
||||
}
|
||||
|
||||
assert.Equal(t, test.expectedOut, string(out))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user