From b29d8eb7cc609b2b0628c7b41f678c0d131a027a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=80=97=E5=AD=90?= Date: Fri, 29 Nov 2024 18:45:32 +0800 Subject: [PATCH] feat: add test cases --- utils_test.go | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 utils_test.go diff --git a/utils_test.go b/utils_test.go new file mode 100644 index 0000000..78d5c39 --- /dev/null +++ b/utils_test.go @@ -0,0 +1,45 @@ +package huaweicloud + +import ( + "testing" +) + +func TestPrepareRecordValueTXTWithQuotes(t *testing.T) { + result := prepareRecordValue("TXT", `"example"`) + expected := []string{`"example"`} + if len(result) != len(expected) || result[0] != expected[0] { + t.Errorf("expected %v, got %v", expected, result) + } +} + +func TestPrepareRecordValueTXTWithoutStartingQuote(t *testing.T) { + result := prepareRecordValue("TXT", `example"`) + expected := []string{`"example"`} + if len(result) != len(expected) || result[0] != expected[0] { + t.Errorf("expected %v, got %v", expected, result) + } +} + +func TestPrepareRecordValueTXTWithoutEndingQuote(t *testing.T) { + result := prepareRecordValue("TXT", `"example`) + expected := []string{`"example"`} + if len(result) != len(expected) || result[0] != expected[0] { + t.Errorf("expected %v, got %v", expected, result) + } +} + +func TestPrepareRecordValueTXTWithoutQuotes(t *testing.T) { + result := prepareRecordValue("TXT", `example`) + expected := []string{`"example"`} + if len(result) != len(expected) || result[0] != expected[0] { + t.Errorf("expected %v, got %v", expected, result) + } +} + +func TestPrepareRecordValueNonTXT(t *testing.T) { + result := prepareRecordValue("A", `example`) + expected := []string{`example`} + if len(result) != len(expected) || result[0] != expected[0] { + t.Errorf("expected %v, got %v", expected, result) + } +}