From e2543428d950179009cf0bce79b772cf13aaab7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Antonio=20Reyes?= Date: Thu, 29 Feb 2024 15:10:47 -0300 Subject: [PATCH] add test cases --- util/util_test.go | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 util/util_test.go diff --git a/util/util_test.go b/util/util_test.go new file mode 100644 index 000000000..770d1dd95 --- /dev/null +++ b/util/util_test.go @@ -0,0 +1,43 @@ +package util + +import ( + "fmt" + "reflect" + "testing" + + "github.com/hashicorp/go-cty/cty" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" +) + +func TestValidateTZValueDiagFunc(t *testing.T) { + notValidTZ1 := "not a valid TZ" + + cases := []struct { + given string + want diag.Diagnostics + path cty.Path + }{ + { + given: "America/Montevideo", + want: nil, + path: cty.Path{}, + }, + { + given: "America/Indiana/Indianapolis", + want: nil, + path: cty.Path{}, + }, + { + given: notValidTZ1, + want: diag.Diagnostics{diag.Diagnostic{Severity: 0, Summary: fmt.Sprintf("\"%s\" is a not valid input. Please refer to the list of allowed Time Zone values at https://developer.pagerduty.com/docs/1afe25e9c94cb-types#time-zone", notValidTZ1), Detail: "", AttributePath: cty.Path{cty.GetAttrStep{Name: "time_zone"}}}}, + path: cty.Path{cty.GetAttrStep{Name: "time_zone"}}, + }, + } + + for _, c := range cases { + got := ValidateTZValueDiagFunc(c.given, c.path) + if !reflect.DeepEqual(got, c.want) { + t.Errorf("want %v; got %v", c.want, got) + } + } +}