123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228 |
- package server
- import (
- "cfTest/cloudflareApi/dns"
- "context"
- "reflect"
- "testing"
- )
- func TestDnsServer_List(t *testing.T) {
- type fields struct {
- UnimplementedDnsCloudflareServer dns.UnimplementedDnsCloudflareServer
- }
- type args struct {
- ctx context.Context
- request *dns.ListRequest
- }
- tests := []struct {
- name string
- fields fields
- args args
- want *dns.DnsRecordList
- wantErr bool
- }{
- {
- name: "成功测试",
- fields: fields{
- UnimplementedDnsCloudflareServer: dns.UnimplementedDnsCloudflareServer{},
- },
- args: args{
- ctx: nil,
- request: &dns.ListRequest{
- ApiKey: "2cc87f6213a4c40e5a90c8dced3c9c577eda5",
- ApiEmail: "ll@centcloud.net",
- ZoneId: "a6383cfb80012436f261793522e811e8",
- },
- },
- want: nil,
- wantErr: false,
- },
- // TODO: Add test cases.
- }
- for _, tt := range tests {
- t.Run(tt.name, func(t *testing.T) {
- d := DnsServer{
- UnimplementedDnsCloudflareServer: tt.fields.UnimplementedDnsCloudflareServer,
- }
- got, err := d.List(tt.args.ctx, tt.args.request)
- if (err != nil) != tt.wantErr {
- t.Errorf("List() error = %v, wantErr %v", err, tt.wantErr)
- return
- }
- //if !reflect.DeepEqual(got, tt.want) {
- // t.Errorf("List() got = %v, want %v", got, tt.want)
- //}
- print(got)
- })
- }
- }
- func TestDnsServer_Create(t *testing.T) {
- type fields struct {
- UnimplementedDnsCloudflareServer dns.UnimplementedDnsCloudflareServer
- }
- type args struct {
- ctx context.Context
- request *dns.DnsRecordRequest
- }
- tests := []struct {
- name string
- fields fields
- args args
- want *dns.DnsRecord
- wantErr bool
- }{
- {
- name: "测试1",
- fields: fields{
- UnimplementedDnsCloudflareServer: dns.UnimplementedDnsCloudflareServer{},
- },
- args: args{
- ctx: nil,
- request: &dns.DnsRecordRequest{
- ApiKey: "2cc87f6213a4c40e5a90c8dced3c9c577eda5",
- ApiEmail: "ll@centcloud.net",
- ZoneId: "a6383cfb80012436f261793522e811e8",
- DnsRecord: &dns.DnsRecord{
- Id: "",
- Name: "recordTest1",
- Type: "A",
- Content: "11.23.11.23",
- Ttl: 1,
- ZoneId: "",
- ZoneName: "",
- Proxied: true,
- },
- },
- },
- want: nil,
- wantErr: false,
- },
- // TODO: Add test cases.
- }
- for _, tt := range tests {
- t.Run(tt.name, func(t *testing.T) {
- d := DnsServer{
- UnimplementedDnsCloudflareServer: tt.fields.UnimplementedDnsCloudflareServer,
- }
- got, err := d.Create(tt.args.ctx, tt.args.request)
- if (err != nil) != tt.wantErr {
- t.Errorf("Create() error = %v, wantErr %v", err, tt.wantErr)
- return
- }
- if !reflect.DeepEqual(got, tt.want) {
- t.Errorf("Create() got = %v, want %v", got, tt.want)
- }
- })
- }
- }
- func TestDnsServer_Delete(t *testing.T) {
- type fields struct {
- UnimplementedDnsCloudflareServer dns.UnimplementedDnsCloudflareServer
- }
- type args struct {
- ctx context.Context
- request *dns.DeleteRequest
- }
- tests := []struct {
- name string
- fields fields
- args args
- want *dns.Empty
- wantErr bool
- }{
- {
- name: "1",
- fields: fields{},
- args: args{
- ctx: nil,
- request: &dns.DeleteRequest{
- ApiKey: "2cc87f6213a4c40e5a90c8dced3c9c577eda5",
- ApiEmail: "ll@centcloud.net",
- ZoneId: "a6383cfb80012436f261793522e811e8",
- Id: "f406d1b89b9dc9897853e4771e9e2796",
- },
- },
- want: nil,
- wantErr: false,
- },
- // TODO: Add test cases.
- }
- for _, tt := range tests {
- t.Run(tt.name, func(t *testing.T) {
- d := DnsServer{
- UnimplementedDnsCloudflareServer: tt.fields.UnimplementedDnsCloudflareServer,
- }
- got, err := d.Delete(tt.args.ctx, tt.args.request)
- if (err != nil) != tt.wantErr {
- t.Errorf("Delete() error = %v, wantErr %v", err, tt.wantErr)
- return
- }
- if !reflect.DeepEqual(got, tt.want) {
- t.Errorf("Delete() got = %v, want %v", got, tt.want)
- }
- })
- }
- }
- func TestDnsServer_Update(t *testing.T) {
- type fields struct {
- UnimplementedDnsCloudflareServer dns.UnimplementedDnsCloudflareServer
- }
- type args struct {
- ctx context.Context
- request *dns.DnsRecordRequest
- }
- tests := []struct {
- name string
- fields fields
- args args
- want *dns.Empty
- wantErr bool
- }{
- {
- name: "1",
- fields: fields{
- UnimplementedDnsCloudflareServer: dns.UnimplementedDnsCloudflareServer{},
- },
- args: args{
- ctx: nil,
- request: &dns.DnsRecordRequest{
- ApiKey: "2cc87f6213a4c40e5a90c8dced3c9c577eda5",
- ApiEmail: "ll@centcloud.net",
- ZoneId: "a6383cfb80012436f261793522e811e8",
- DnsRecord: &dns.DnsRecord{
- Id: "f406d1b89b9dc9897853e4771e9e2796",
- Name: "recordtest2",
- Type: "A",
- Content: "23.11.23.11",
- Ttl: 1,
- ZoneId: "",
- ZoneName: "",
- Proxied: true,
- },
- },
- },
- want: nil,
- wantErr: false,
- },
- // TODO: Add test cases.
- }
- for _, tt := range tests {
- t.Run(tt.name, func(t *testing.T) {
- d := DnsServer{
- UnimplementedDnsCloudflareServer: tt.fields.UnimplementedDnsCloudflareServer,
- }
- got, err := d.Update(tt.args.ctx, tt.args.request)
- if (err != nil) != tt.wantErr {
- t.Errorf("Update() error = %v, wantErr %v", err, tt.wantErr)
- return
- }
- if !reflect.DeepEqual(got, tt.want) {
- t.Errorf("Update() got = %v, want %v", got, tt.want)
- }
- })
- }
- }
|