ocket8888 commented on a change in pull request #5071:
URL: https://github.com/apache/trafficcontrol/pull/5071#discussion_r501156381



##########
File path: lib/go-tc/deliveryservice_requests_test.go
##########
@@ -105,3 +107,116 @@ func TestRequestStatusJSON(t *testing.T) {
                t.Errorf("expected %v, got %v", RequestStatusDraft, r)
        }
 }
+
+func ExampleDSRChangeType_UnmarshalJSON() {
+       var dsrct DSRChangeType
+       raw := `"CREATE"`
+       if err := json.Unmarshal([]byte(raw), &dsrct); err != nil {
+               fmt.Printf("Error: %v\n", err)
+               return
+       }
+       fmt.Printf("Parsed DSRCT: '%s'\n", dsrct.String())
+
+       raw = `"something invalid"`
+       if err := json.Unmarshal([]byte(raw), &dsrct); err != nil {
+               fmt.Printf("Error: %v\n", err)
+               return
+       }
+       fmt.Printf("Parsed DSRCT: '%s'\n", dsrct.String())
+
+       // Output: Parsed DSRCT: 'create'
+       // Error: invalid Delivery Service Request changeType: 'something 
invalid'
+}
+
+func ExampleDeliveryServiceRequestV30_String() {
+       var dsr DeliveryServiceRequestV30
+       fmt.Println(dsr.String())
+
+       // Output: DeliveryServiceRequestV30(Assignee=<nil>, AssigneeID=<nil>, 
Author="", AuthorID=<nil>, ChangeType="", CreatedAt=0001-01-01T00:00:00Z, 
ID=<nil>, LastEditedBy="", LastEditedByID=<nil>, 
LastUpdated=0001-01-01T00:00:00Z, Status="")
+}

Review comment:
       I generally like simple, positive-case tests like this to be in 
[testable examples](https://blog.golang.org/examples)




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to