DnsCloudflareServer_test.go 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. package server
  2. import (
  3. "cfTest/cloudflareApi/dns"
  4. "context"
  5. "reflect"
  6. "testing"
  7. )
  8. func TestDnsServer_List(t *testing.T) {
  9. type fields struct {
  10. UnimplementedDnsCloudflareServer dns.UnimplementedDnsCloudflareServer
  11. }
  12. type args struct {
  13. ctx context.Context
  14. request *dns.ListRequest
  15. }
  16. tests := []struct {
  17. name string
  18. fields fields
  19. args args
  20. want *dns.DnsRecordList
  21. wantErr bool
  22. }{
  23. {
  24. name: "成功测试",
  25. fields: fields{
  26. UnimplementedDnsCloudflareServer: dns.UnimplementedDnsCloudflareServer{},
  27. },
  28. args: args{
  29. ctx: nil,
  30. request: &dns.ListRequest{
  31. ApiKey: "2cc87f6213a4c40e5a90c8dced3c9c577eda5",
  32. ApiEmail: "ll@centcloud.net",
  33. ZoneId: "a6383cfb80012436f261793522e811e8",
  34. },
  35. },
  36. want: nil,
  37. wantErr: false,
  38. },
  39. // TODO: Add test cases.
  40. }
  41. for _, tt := range tests {
  42. t.Run(tt.name, func(t *testing.T) {
  43. d := DnsServer{
  44. UnimplementedDnsCloudflareServer: tt.fields.UnimplementedDnsCloudflareServer,
  45. }
  46. got, err := d.List(tt.args.ctx, tt.args.request)
  47. if (err != nil) != tt.wantErr {
  48. t.Errorf("List() error = %v, wantErr %v", err, tt.wantErr)
  49. return
  50. }
  51. //if !reflect.DeepEqual(got, tt.want) {
  52. // t.Errorf("List() got = %v, want %v", got, tt.want)
  53. //}
  54. print(got)
  55. })
  56. }
  57. }
  58. func TestDnsServer_Create(t *testing.T) {
  59. type fields struct {
  60. UnimplementedDnsCloudflareServer dns.UnimplementedDnsCloudflareServer
  61. }
  62. type args struct {
  63. ctx context.Context
  64. request *dns.DnsRecordRequest
  65. }
  66. tests := []struct {
  67. name string
  68. fields fields
  69. args args
  70. want *dns.DnsRecord
  71. wantErr bool
  72. }{
  73. {
  74. name: "测试1",
  75. fields: fields{
  76. UnimplementedDnsCloudflareServer: dns.UnimplementedDnsCloudflareServer{},
  77. },
  78. args: args{
  79. ctx: nil,
  80. request: &dns.DnsRecordRequest{
  81. ApiKey: "2cc87f6213a4c40e5a90c8dced3c9c577eda5",
  82. ApiEmail: "ll@centcloud.net",
  83. ZoneId: "a6383cfb80012436f261793522e811e8",
  84. DnsRecord: &dns.DnsRecord{
  85. Id: "",
  86. Name: "recordTest1",
  87. Type: "A",
  88. Content: "11.23.11.23",
  89. Ttl: 1,
  90. ZoneId: "",
  91. ZoneName: "",
  92. Proxied: true,
  93. },
  94. },
  95. },
  96. want: nil,
  97. wantErr: false,
  98. },
  99. // TODO: Add test cases.
  100. }
  101. for _, tt := range tests {
  102. t.Run(tt.name, func(t *testing.T) {
  103. d := DnsServer{
  104. UnimplementedDnsCloudflareServer: tt.fields.UnimplementedDnsCloudflareServer,
  105. }
  106. got, err := d.Create(tt.args.ctx, tt.args.request)
  107. if (err != nil) != tt.wantErr {
  108. t.Errorf("Create() error = %v, wantErr %v", err, tt.wantErr)
  109. return
  110. }
  111. if !reflect.DeepEqual(got, tt.want) {
  112. t.Errorf("Create() got = %v, want %v", got, tt.want)
  113. }
  114. })
  115. }
  116. }
  117. func TestDnsServer_Delete(t *testing.T) {
  118. type fields struct {
  119. UnimplementedDnsCloudflareServer dns.UnimplementedDnsCloudflareServer
  120. }
  121. type args struct {
  122. ctx context.Context
  123. request *dns.DeleteRequest
  124. }
  125. tests := []struct {
  126. name string
  127. fields fields
  128. args args
  129. want *dns.Empty
  130. wantErr bool
  131. }{
  132. {
  133. name: "1",
  134. fields: fields{},
  135. args: args{
  136. ctx: nil,
  137. request: &dns.DeleteRequest{
  138. ApiKey: "2cc87f6213a4c40e5a90c8dced3c9c577eda5",
  139. ApiEmail: "ll@centcloud.net",
  140. ZoneId: "a6383cfb80012436f261793522e811e8",
  141. Id: "f406d1b89b9dc9897853e4771e9e2796",
  142. },
  143. },
  144. want: nil,
  145. wantErr: false,
  146. },
  147. // TODO: Add test cases.
  148. }
  149. for _, tt := range tests {
  150. t.Run(tt.name, func(t *testing.T) {
  151. d := DnsServer{
  152. UnimplementedDnsCloudflareServer: tt.fields.UnimplementedDnsCloudflareServer,
  153. }
  154. got, err := d.Delete(tt.args.ctx, tt.args.request)
  155. if (err != nil) != tt.wantErr {
  156. t.Errorf("Delete() error = %v, wantErr %v", err, tt.wantErr)
  157. return
  158. }
  159. if !reflect.DeepEqual(got, tt.want) {
  160. t.Errorf("Delete() got = %v, want %v", got, tt.want)
  161. }
  162. })
  163. }
  164. }
  165. func TestDnsServer_Update(t *testing.T) {
  166. type fields struct {
  167. UnimplementedDnsCloudflareServer dns.UnimplementedDnsCloudflareServer
  168. }
  169. type args struct {
  170. ctx context.Context
  171. request *dns.DnsRecordRequest
  172. }
  173. tests := []struct {
  174. name string
  175. fields fields
  176. args args
  177. want *dns.Empty
  178. wantErr bool
  179. }{
  180. {
  181. name: "1",
  182. fields: fields{
  183. UnimplementedDnsCloudflareServer: dns.UnimplementedDnsCloudflareServer{},
  184. },
  185. args: args{
  186. ctx: nil,
  187. request: &dns.DnsRecordRequest{
  188. ApiKey: "2cc87f6213a4c40e5a90c8dced3c9c577eda5",
  189. ApiEmail: "ll@centcloud.net",
  190. ZoneId: "a6383cfb80012436f261793522e811e8",
  191. DnsRecord: &dns.DnsRecord{
  192. Id: "f406d1b89b9dc9897853e4771e9e2796",
  193. Name: "recordtest2",
  194. Type: "A",
  195. Content: "23.11.23.11",
  196. Ttl: 1,
  197. ZoneId: "",
  198. ZoneName: "",
  199. Proxied: true,
  200. },
  201. },
  202. },
  203. want: nil,
  204. wantErr: false,
  205. },
  206. // TODO: Add test cases.
  207. }
  208. for _, tt := range tests {
  209. t.Run(tt.name, func(t *testing.T) {
  210. d := DnsServer{
  211. UnimplementedDnsCloudflareServer: tt.fields.UnimplementedDnsCloudflareServer,
  212. }
  213. got, err := d.Update(tt.args.ctx, tt.args.request)
  214. if (err != nil) != tt.wantErr {
  215. t.Errorf("Update() error = %v, wantErr %v", err, tt.wantErr)
  216. return
  217. }
  218. if !reflect.DeepEqual(got, tt.want) {
  219. t.Errorf("Update() got = %v, want %v", got, tt.want)
  220. }
  221. })
  222. }
  223. }