1- package configtype
1+ package configtype_test
22
33import (
44 "encoding/json"
55 "testing"
66 "time"
7+
8+ "github.com/cloudquery/plugin-sdk/v4/configtype"
9+ "github.com/google/go-cmp/cmp"
710)
811
912func TestDuration (t * testing.T ) {
@@ -16,7 +19,7 @@ func TestDuration(t *testing.T) {
1619 {"-50m30s" , - 50 * time .Minute - 30 * time .Second },
1720 }
1821 for _ , tc := range cases {
19- var d Duration
22+ var d configtype. Duration
2023 err := json .Unmarshal ([]byte (`"` + tc .give + `"` ), & d )
2124 if err != nil {
2225 t .Fatalf ("error calling Unmarshal(%q): %v" , tc .give , err )
@@ -26,3 +29,26 @@ func TestDuration(t *testing.T) {
2629 }
2730 }
2831}
32+
33+ func TestComparability (t * testing.T ) {
34+ cases := []struct {
35+ give configtype.Duration
36+ compare configtype.Duration
37+ equal bool
38+ }{
39+ {configtype .NewDuration (0 ), configtype .NewDuration (0 ), true },
40+ {configtype .NewDuration (0 ), configtype .NewDuration (1 ), false },
41+ }
42+ for _ , tc := range cases {
43+ if (tc .give == tc .compare ) != tc .equal {
44+ t .Errorf ("comparing %v and %v should be %v" , tc .give , tc .compare , tc .equal )
45+ }
46+
47+ diff := cmp .Diff (tc .give , tc .compare )
48+ if tc .equal && diff != "" {
49+ t .Errorf ("comparing %v and %v should be equal, but diff is %s" , tc .give , tc .compare , diff )
50+ } else if ! tc .equal && diff == "" {
51+ t .Errorf ("comparing %v and %v should not be equal, but diff is empty" , tc .give , tc .compare )
52+ }
53+ }
54+ }
0 commit comments