1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-02-13 13:59:06 +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:
Stefan Haller 2023-06-22 18:32:49 +02:00
parent 8932d17393
commit bf685cf832

View File

@ -1,6 +1,10 @@
package yaml_utils package yaml_utils
import "testing" import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestUpdateYaml(t *testing.T) { func TestUpdateYaml(t *testing.T) {
tests := []struct { tests := []struct {
@ -49,16 +53,14 @@ func TestUpdateYaml(t *testing.T) {
for _, test := range tests { for _, test := range tests {
test := test test := test
t.Run(test.name, func(t *testing.T) { t.Run(test.name, func(t *testing.T) {
out, err := UpdateYaml([]byte(test.in), test.path, test.value) out, actualErr := UpdateYaml([]byte(test.in), test.path, test.value)
if test.expectedErr != "" { if test.expectedErr == "" {
if err == nil { assert.NoError(t, actualErr)
t.Errorf("expected error %q but got none", test.expectedErr) } else {
} assert.EqualError(t, actualErr, 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))
} }
assert.Equal(t, test.expectedOut, string(out))
}) })
} }
} }