From e2e0cc20a6da46f174e9322b3c222b8f94b543ba Mon Sep 17 00:00:00 2001 From: Rohan Verma Date: Wed, 6 Mar 2024 23:59:08 +0530 Subject: [PATCH] fix: broken toml parser tests --- parsers/toml/toml_test.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/parsers/toml/toml_test.go b/parsers/toml/toml_test.go index 719b01d9..72132280 100644 --- a/parsers/toml/toml_test.go +++ b/parsers/toml/toml_test.go @@ -1,6 +1,8 @@ package toml import ( + "sort" + "strings" "testing" "github.com/stretchr/testify/assert" @@ -110,7 +112,7 @@ number = 2.0 "object": map[string]interface{}{"a": "b", "c": "d"}, "string": "Hello World", }, - output: []byte(`array = [1,2,3,4,5] + output: []byte(`array = [1, 2, 3, 4, 5] boolean = true color = "gold" number = 123 @@ -132,8 +134,16 @@ string = "Hello World" assert.NotNil(t, err) } else { assert.Nil(t, err) - assert.Equal(t, tc.output, out) + assert.Equal(t, sortLines(tc.output), sortLines(out)) } }) } } + +// toml marshal is not guaranteed to produce the same output every time +// so we sort the lines before comparing. +func sortLines(s []byte) string { + lines := strings.Split(string(s), "\n") + sort.Strings(lines) + return strings.Join(lines, "\n") +}