From 8055baeb5c41752cc4332593655042f54e58cae6 Mon Sep 17 00:00:00 2001 From: Martin Holst Swende Date: Thu, 21 Sep 2023 09:09:56 +0200 Subject: [PATCH] stores/yaml: use assert in tests Signed-off-by: Martin Holst Swende --- stores/yaml/store_test.go | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/stores/yaml/store_test.go b/stores/yaml/store_test.go index 1f2be1e29..83c86d971 100644 --- a/stores/yaml/store_test.go +++ b/stores/yaml/store_test.go @@ -284,7 +284,7 @@ func TestComment7(t *testing.T) { func TestDuplicateAttributes(t *testing.T) { // Duplicate keys are _not_ valid yaml. // - // See https://yaml.org/spec/1.2.2/ + // See https://yaml.org/spec/1.2.2/#mapping // > The content of a mapping node is an unordered set of key/value node pairs, // > with the restriction that each of the keys is unique. // @@ -297,13 +297,9 @@ rootunique: ` s := new(Store) _, err := s.LoadPlainFile([]byte(data)) - if err == nil { - t.Errorf("Expected error") - } - if have, want := err.Error(), `yaml: unmarshal errors: - line 3: mapping key "hello" already defined at line 2`; have != want { - t.Errorf("have '%v', want '%v'", have, want) - } + assert.NotNil(t, err) + assert.Equal(t, `yaml: unmarshal errors: + line 3: mapping key "hello" already defined at line 2`, err.Error()) } func TestReservedAttributes(t *testing.T) { @@ -313,10 +309,6 @@ sops: The attribute 'sops' must be rejected, otherwise the file cannot be opened ` s := new(Store) _, err := s.LoadPlainFile([]byte(data)) - if err == nil { - t.Errorf("Expected error") - } - if have, want := err.Error(), `YAML doc used reserved word 'sops'`; have != want { - t.Errorf("have '%v', want '%v'", have, want) - } + assert.NotNil(t, err) + assert.Equal(t, `YAML doc used reserved word 'sops'`, err.Error()) }