github.com/google/go-github/v33@v33.0.0/github/event_types_test.go (about) 1 // Copyright 2020 The go-github AUTHORS. All rights reserved. 2 // 3 // Use of this source code is governed by a BSD-style 4 // license that can be found in the LICENSE file. 5 6 package github 7 8 import ( 9 "testing" 10 ) 11 12 func TestEditChange_Marshal_TitleChange(t *testing.T) { 13 testJSONMarshal(t, &EditChange{}, "{}") 14 15 TitleFrom := struct { 16 From *string `json:"from,omitempty"` 17 }{ 18 From: String("TitleFrom"), 19 } 20 21 u := &EditChange{ 22 Title: &TitleFrom, 23 Body: nil, 24 Base: nil, 25 } 26 27 want := `{ 28 "title": { 29 "from": "TitleFrom" 30 } 31 }` 32 33 testJSONMarshal(t, u, want) 34 } 35 36 func TestEditChange_Marshal_BodyChange(t *testing.T) { 37 testJSONMarshal(t, &EditChange{}, "{}") 38 39 BodyFrom := struct { 40 From *string `json:"from,omitempty"` 41 }{ 42 From: String("BodyFrom"), 43 } 44 45 u := &EditChange{ 46 Title: nil, 47 Body: &BodyFrom, 48 Base: nil, 49 } 50 51 want := `{ 52 "body": { 53 "from": "BodyFrom" 54 } 55 }` 56 57 testJSONMarshal(t, u, want) 58 } 59 60 func TestEditChange_Marshal_BaseChange(t *testing.T) { 61 testJSONMarshal(t, &EditChange{}, "{}") 62 63 RefFrom := struct { 64 From *string `json:"from,omitempty"` 65 }{ 66 From: String("BaseRefFrom"), 67 } 68 69 SHAFrom := struct { 70 From *string `json:"from,omitempty"` 71 }{ 72 From: String("BaseSHAFrom"), 73 } 74 75 Base := struct { 76 Ref *struct { 77 From *string `json:"from,omitempty"` 78 } `json:"ref,omitempty"` 79 SHA *struct { 80 From *string `json:"from,omitempty"` 81 } `json:"sha,omitempty"` 82 }{ 83 Ref: &RefFrom, 84 SHA: &SHAFrom, 85 } 86 87 u := &EditChange{ 88 Title: nil, 89 Body: nil, 90 Base: &Base, 91 } 92 93 want := `{ 94 "base": { 95 "ref": { 96 "from": "BaseRefFrom" 97 }, 98 "sha": { 99 "from": "BaseSHAFrom" 100 } 101 } 102 }` 103 104 testJSONMarshal(t, u, want) 105 }