123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969 |
- package server
- import (
- "cfTest/cloudflareApi/zone"
- "context"
- "fmt"
- "github.com/cloudflare/cloudflare-go"
- "github.com/samber/lo"
- "log"
- "reflect"
- "testing"
- "time"
- )
- // func TestCreateRuleSet(t *testing.T) {
- // type args struct {
- // zoneID string
- // rulesetPhase string
- // ruleset cloudflare.Ruleset
- // }
- //
- // var (
- // True = true
- // CONST604800 = uint(604800)
- // )
- //
- // tests := []struct {
- // name string
- // args args
- // want interface{}
- // wantErr bool
- // }{
- // {
- // name: "Test1",
- // args: args{
- // zoneID: "e29551894461bf16e43a113e5ab09ed3",
- // rulesetPhase: "http_request_cache_settings",
- // ruleset: cloudflare.Ruleset{
- // Rules: []cloudflare.RulesetRule{
- // {
- // Expression: "(starts_with(http.request.uri.path, \"/\"))",
- // Enabled: true,
- // Description: "test1",
- // Action: "set_cache_settings",
- // ActionParameters: &cloudflare.RulesetRuleActionParameters{
- // Cache: &True,
- // CacheKey: &cloudflare.RulesetRuleActionParametersCacheKey{
- // CustomKey: &cloudflare.RulesetRuleActionParametersCustomKey{
- // Query: &cloudflare.RulesetRuleActionParametersCustomKeyQuery{
- // Exclude: &cloudflare.RulesetRuleActionParametersCustomKeyList{
- // List: []string{
- // "abc",
- // },
- // All: false,
- // },
- // },
- // },
- // },
- // EdgeTTL: &cloudflare.RulesetRuleActionParametersEdgeTTL{
- // Mode: "override_origin",
- // Default: &CONST604800,
- // },
- // },
- // },
- // },
- // },
- // },
- // want: nil,
- // wantErr: false,
- // },
- // }
- // for _, tt := range tests {
- // t.Run(tt.name, func(t *testing.T) {
- // got, err := UpdateRuleSet("", "", tt.args.zoneID, tt.args.rulesetPhase, tt.args.ruleset)
- // if (err != nil) != tt.wantErr {
- // t.Errorf("UpdateRuleSet() error = %v, wantErr %v", err, tt.wantErr)
- // return
- // }
- // if !reflect.DeepEqual(got, tt.want) {
- // t.Errorf("UpdateRuleSet() got = %v, want %v", got, tt.want)
- // }
- // })
- // }
- // }
- //
- // func newUint32(a uint32) *uint32 {
- // return &a
- // }
- //
- // func newStr(a string) *string {
- // return &a
- // }
- var (
- apiKey = "2cc87f6213a4c40e5a90c8dced3c9c577eda5"
- apiEmail = "ll@centcloud.net"
- )
- //func TestUpdatePageRule(t *testing.T) {
- //
- // type args struct {
- // apiKey string
- // apiEmail string
- // zoneID string
- // rule *zone.Rule
- // }
- // tests := []struct {
- // name string
- // args args
- // want *cloudflare.PageRule
- // wantErr bool
- // }{
- // {
- // name: "测试1",
- // args: args{
- // apiKey: apiKey,
- // apiEmail: apiEmail,
- // zoneID: "e29551894461bf16e43a113e5ab09ed3",
- // rule: &zone.Rule{
- // Expression: "www.1011test5.com.cdn.sensordb.site/*\n",
- // Ttl: newUint32(18000),
- // QueryArgsType: newStr("ExcludeAll"),
- // QueryArgs: []string{"qwe12", "78u9hi"},
- // OriginHost: newStr("www.baidu.com"),
- // OriginPath: nil,
- // OriginProtocol: newUint32(80),
- // RequestHeader: nil,
- // ResponseHeader: nil,
- // },
- // },
- // want: nil,
- // wantErr: false,
- // },
- // // TODO: Add test cases.
- // }
- // for _, tt := range tests {
- // t.Run(tt.name, func(t *testing.T) {
- // got, err := UpdatePageRule(tt.args.apiKey, tt.args.apiEmail, tt.args.zoneID, tt.args.rule)
- // if (err != nil) != tt.wantErr {
- // t.Errorf("UpdatePageRule() error = %v, wantErr %v", err, tt.wantErr)
- // return
- // }
- // print("%v", got)
- // //if !reflect.DeepEqual(got, tt.want) {
- // // t.Errorf("UpdatePageRule() got = %v, want %v", got, tt.want)
- // //}
- // })
- // }
- //}
- func TestZoneServer_GetRuleSet(t *testing.T) {
- type fields struct {
- UnimplementedZoneCloudflareServer zone.UnimplementedZoneCloudflareServer
- }
- type args struct {
- ctx context.Context
- requestCloudflare *zone.GetRuleSetRequestCloudflare
- }
- tests := []struct {
- name string
- fields fields
- args args
- want *zone.RuleList
- wantErr bool
- }{
- {
- name: "测试1",
- fields: fields{
- UnimplementedZoneCloudflareServer: zone.UnimplementedZoneCloudflareServer{},
- },
- args: args{
- ctx: context.Background(),
- requestCloudflare: &zone.GetRuleSetRequestCloudflare{
- ApiKey: "d2589c4f617b0493357ae187a7b4518171d07",
- ApiEmail: "shiqi@centcloud.net",
- ZoneId: "5801a8cbe2fdfd6c53413d0eef164d23",
- Phase: zone.Phase_http_request_cache_settings,
- },
- },
- wantErr: false,
- },
- }
- for _, tt := range tests {
- t.Run(tt.name, func(t *testing.T) {
- s := &ZoneServer{
- UnimplementedZoneCloudflareServer: tt.fields.UnimplementedZoneCloudflareServer,
- }
- got, err := s.GetRuleSet(tt.args.ctx, tt.args.requestCloudflare)
- fmt.Println(got)
- if (err != nil) != tt.wantErr {
- t.Errorf("GetRuleSet() error = %v, wantErr %v", err, tt.wantErr)
- return
- }
- log.Print(got)
- //if !reflect.DeepEqual(got, tt.want) {
- // t.Errorf("GetRuleSet() got = %v, want %v", got, tt.want)
- //}
- })
- }
- }
- func TestZoneServer_UpdateRuleSet(t *testing.T) {
- type fields struct {
- UnimplementedZoneCloudflareServer zone.UnimplementedZoneCloudflareServer
- }
- type args struct {
- ctx context.Context
- requestCloudflare *zone.UpdateRuleSetRequestCloudflare
- }
- tests := []struct {
- name string
- fields fields
- args args
- want *zone.RuleList
- wantErr bool
- }{
- {
- name: "测试1",
- fields: fields{
- UnimplementedZoneCloudflareServer: zone.UnimplementedZoneCloudflareServer{},
- },
- args: args{
- ctx: nil,
- requestCloudflare: &zone.UpdateRuleSetRequestCloudflare{
- ApiKey: apiKey,
- ApiEmail: apiEmail,
- ZoneId: "e29551894461bf16e43a113e5ab09ed3",
- Phase: zone.Phase_http_request_transform,
- Rules: []*zone.Rule{
- {
- Expression: "(http.request.uri.path contains \"www.1011test5.com.cdn.sensordb.site/\")",
- OriginPath: lo.ToPtr[string]("www.baidu.com"),
- RequestHeader: nil,
- ResponseHeader: nil,
- },
- },
- },
- },
- want: nil,
- wantErr: false,
- },
- }
- for _, tt := range tests {
- t.Run(tt.name, func(t *testing.T) {
- s := &ZoneServer{
- UnimplementedZoneCloudflareServer: tt.fields.UnimplementedZoneCloudflareServer,
- }
- got, err := s.UpdateRuleSet(tt.args.ctx, tt.args.requestCloudflare)
- if (err != nil) != tt.wantErr {
- t.Errorf("UpdateRuleSet() error = %v, wantErr %v", err, tt.wantErr)
- return
- }
- log.Print(got)
- //if !reflect.DeepEqual(got, tt.want) {
- // t.Errorf("UpdateRuleSet() got = %v, want %v", got, tt.want)
- //}
- })
- }
- }
- func TestZoneServer_GetArgoSetting(t *testing.T) {
- type fields struct {
- UnimplementedZoneCloudflareServer zone.UnimplementedZoneCloudflareServer
- }
- type args struct {
- ctx context.Context
- requestCloudflare *zone.IdRequest
- }
- tests := []struct {
- name string
- fields fields
- args args
- want *zone.ArgoSetting
- wantErr bool
- }{
- {
- name: "test1",
- fields: fields{
- UnimplementedZoneCloudflareServer: zone.UnimplementedZoneCloudflareServer{},
- },
- args: args{
- ctx: context.Background(),
- requestCloudflare: &zone.IdRequest{
- ApiKey: apiKey,
- ApiEmail: apiEmail,
- ZoneId: "f7eefa29114db32ab14397bdd5048ec8",
- },
- },
- want: &zone.ArgoSetting{Enabled: true},
- wantErr: false,
- },
- {
- name: "test1",
- fields: fields{
- UnimplementedZoneCloudflareServer: zone.UnimplementedZoneCloudflareServer{},
- },
- args: args{
- ctx: context.Background(),
- requestCloudflare: &zone.IdRequest{
- ApiKey: apiKey,
- ApiEmail: apiEmail,
- ZoneId: "f7eefa29114db32ab14397bdd5048ec8",
- },
- },
- want: &zone.ArgoSetting{Enabled: false},
- wantErr: false,
- },
- }
- for _, tt := range tests {
- t.Run(tt.name, func(t *testing.T) {
- s := &ZoneServer{
- UnimplementedZoneCloudflareServer: tt.fields.UnimplementedZoneCloudflareServer,
- }
- got, err := s.GetArgoSetting(tt.args.ctx, tt.args.requestCloudflare)
- if (err != nil) != tt.wantErr {
- t.Errorf("GetArgoSetting() error = %v, wantErr %v", err, tt.wantErr)
- return
- }
- if !reflect.DeepEqual(got, tt.want) {
- t.Errorf("GetArgoSetting() got = %v, want %v", got, tt.want)
- }
- })
- }
- }
- func TestZoneServer_UpdateArgoSetting(t *testing.T) {
- type fields struct {
- UnimplementedZoneCloudflareServer zone.UnimplementedZoneCloudflareServer
- }
- type args struct {
- ctx context.Context
- requestCloudflare *zone.UpdateArgoRequestCloudflare
- }
- tests := []struct {
- name string
- fields fields
- args args
- want *zone.ArgoSetting
- wantErr bool
- }{
- {
- name: "test1",
- fields: fields{
- UnimplementedZoneCloudflareServer: zone.UnimplementedZoneCloudflareServer{},
- },
- args: args{
- ctx: context.Background(),
- requestCloudflare: &zone.UpdateArgoRequestCloudflare{
- ApiKey: apiKey,
- ApiEmail: apiEmail,
- ZoneId: "f7eefa29114db32ab14397bdd5048ec8",
- ArgoSetting: &zone.ArgoSetting{Enabled: false},
- },
- },
- want: &zone.ArgoSetting{Enabled: false},
- wantErr: false,
- },
- {
- name: "test1",
- fields: fields{
- UnimplementedZoneCloudflareServer: zone.UnimplementedZoneCloudflareServer{},
- },
- args: args{
- ctx: context.Background(),
- requestCloudflare: &zone.UpdateArgoRequestCloudflare{
- ApiKey: apiKey,
- ApiEmail: apiEmail,
- ZoneId: "f7eefa29114db32ab14397bdd5048ec8",
- ArgoSetting: &zone.ArgoSetting{Enabled: true},
- },
- },
- want: &zone.ArgoSetting{Enabled: true},
- wantErr: false,
- },
- }
- for _, tt := range tests {
- t.Run(tt.name, func(t *testing.T) {
- s := &ZoneServer{
- UnimplementedZoneCloudflareServer: tt.fields.UnimplementedZoneCloudflareServer,
- }
- got, err := s.UpdateArgoSetting(tt.args.ctx, tt.args.requestCloudflare)
- if (err != nil) != tt.wantErr {
- t.Errorf("UpdateArgoSetting() error = %v, wantErr %v", err, tt.wantErr)
- return
- }
- if !reflect.DeepEqual(got, tt.want) {
- t.Errorf("UpdateArgoSetting() got = %v, want %v", got, tt.want)
- }
- })
- }
- }
- func TestZoneServer_GetArgoSettingSubscription(t *testing.T) {
- type fields struct {
- UnimplementedZoneCloudflareServer zone.UnimplementedZoneCloudflareServer
- }
- type args struct {
- ctx context.Context
- request *zone.IdRequest
- }
- tests := []struct {
- name string
- fields fields
- args args
- want *zone.ArgoSetting
- wantErr bool
- }{
- {
- name: "启用测试",
- fields: fields{
- UnimplementedZoneCloudflareServer: zone.UnimplementedZoneCloudflareServer{},
- },
- args: args{
- ctx: nil,
- request: &zone.IdRequest{
- ApiKey: apiKey,
- ApiEmail: apiEmail,
- ZoneId: "f7eefa29114db32ab14397bdd5048ec8",
- },
- },
- want: &zone.ArgoSetting{Enabled: true},
- wantErr: false,
- },
- {
- name: "未启用测试",
- fields: fields{
- UnimplementedZoneCloudflareServer: zone.UnimplementedZoneCloudflareServer{},
- },
- args: args{
- ctx: nil,
- request: &zone.IdRequest{
- ApiKey: apiKey,
- ApiEmail: apiEmail,
- ZoneId: "6d89e53e52a08fc51b99628ff546c7fb",
- },
- },
- want: &zone.ArgoSetting{Enabled: false},
- wantErr: false,
- },
- }
- for _, tt := range tests {
- t.Run(tt.name, func(t *testing.T) {
- s := &ZoneServer{
- UnimplementedZoneCloudflareServer: tt.fields.UnimplementedZoneCloudflareServer,
- }
- got, err := s.GetArgoSettingSubscription(tt.args.ctx, tt.args.request)
- if (err != nil) != tt.wantErr {
- t.Errorf("GetArgoSettingSubscription() error = %v, wantErr %v", err, tt.wantErr)
- return
- }
- if !reflect.DeepEqual(got, tt.want) {
- t.Errorf("GetArgoSettingSubscription() got = %v, want %v", got, tt.want)
- }
- })
- }
- }
- func TestZoneServer_CreateArgoSettingSubscription(t *testing.T) {
- type fields struct {
- UnimplementedZoneCloudflareServer zone.UnimplementedZoneCloudflareServer
- }
- type args struct {
- ctx context.Context
- request *zone.IdRequest
- }
- tests := []struct {
- name string
- fields fields
- args args
- want *zone.ArgoSetting
- wantErr bool
- }{
- {
- name: "测试",
- fields: fields{
- UnimplementedZoneCloudflareServer: zone.UnimplementedZoneCloudflareServer{},
- },
- args: args{
- ctx: nil,
- request: &zone.IdRequest{
- ApiKey: apiKey,
- ApiEmail: apiEmail,
- ZoneId: "7a25de4f4ea643e99c66e84e7498ccc6",
- },
- },
- want: &zone.ArgoSetting{Enabled: true},
- wantErr: false,
- },
- }
- for _, tt := range tests {
- t.Run(tt.name, func(t *testing.T) {
- s := &ZoneServer{
- UnimplementedZoneCloudflareServer: tt.fields.UnimplementedZoneCloudflareServer,
- }
- got, err := s.CreateArgoSettingSubscription(tt.args.ctx, tt.args.request)
- if (err != nil) != tt.wantErr {
- t.Errorf("CreateArgoSettingSubscription() error = %v, wantErr %v", err, tt.wantErr)
- return
- }
- if !reflect.DeepEqual(got, tt.want) {
- t.Errorf("CreateArgoSettingSubscription() got = %v, want %v", got, tt.want)
- }
- })
- }
- }
- func TestCreateZone(t *testing.T) {
- api, err := cloudflare.New("d2589c4f617b0493357ae187a7b4518171d07", "shiqi@centcloud.net")
- if err != nil {
- t.Fatal(err)
- }
- ctx := context.Background()
- account, r, err := api.Account(ctx, "b9145a83318cae896ad9b23bdf1681a5")
- if err != nil {
- t.Fatal(err)
- }
- t.Logf("Account Info:%+v", r)
- createZone, err := api.CreateZone(ctx, "cf004.shiqi.website", false, account, "partial")
- if err != nil {
- t.Fatal(err)
- }
- t.Logf("createZone: %+v", createZone)
- time.Sleep(time.Second)
- zoneId := createZone.ID
- err = api.ZoneSetPlan(ctx, zoneId, "PARTNERS_ENT")
- if err != nil {
- t.Fatal(err)
- }
- }
- func TestZoneServer_CreateZone(t *testing.T) {
- type fields struct {
- UnimplementedZoneCloudflareServer zone.UnimplementedZoneCloudflareServer
- }
- type args struct {
- ctx context.Context
- requestCloudflare *zone.CreateZoneRequestCloudflare
- }
- tests := []struct {
- name string
- fields fields
- args args
- want *zone.CreateZoneReplyCloudflare
- wantErr bool
- }{
- {
- name: "测试用例1",
- fields: fields{
- UnimplementedZoneCloudflareServer: zone.UnimplementedZoneCloudflareServer{},
- },
- args: args{
- ctx: context.Background(),
- requestCloudflare: &zone.CreateZoneRequestCloudflare{
- ApiKey: "d2589c4f617b0493357ae187a7b4518171d07",
- ApiEmail: "shiqi@centcloud.net",
- AccountId: "b9145a83318cae896ad9b23bdf1681a5",
- Domain: "cf005.shiqi.website",
- },
- },
- want: nil,
- wantErr: false,
- },
- }
- for _, tt := range tests {
- t.Run(tt.name, func(t *testing.T) {
- s := &ZoneServer{
- UnimplementedZoneCloudflareServer: tt.fields.UnimplementedZoneCloudflareServer,
- }
- got, err := s.CreateZone(tt.args.ctx, tt.args.requestCloudflare)
- if (err != nil) != tt.wantErr {
- t.Errorf("CreateZone() error = %v, wantErr %v", err, tt.wantErr)
- return
- }
- t.Logf("CreateZone() got = %v", got)
- })
- }
- }
- func TestZoneServer_SetZonePlan(t *testing.T) {
- type fields struct {
- UnimplementedZoneCloudflareServer zone.UnimplementedZoneCloudflareServer
- }
- type args struct {
- ctx context.Context
- requestCloudflare *zone.SetZonePlanRequestCloudflare
- }
- tests := []struct {
- name string
- fields fields
- args args
- want *zone.SetZonePlanReplyCloudflare
- wantErr bool
- }{
- {
- name: "测试用例1",
- fields: fields{
- UnimplementedZoneCloudflareServer: zone.UnimplementedZoneCloudflareServer{},
- },
- args: args{
- ctx: context.Background(),
- requestCloudflare: &zone.SetZonePlanRequestCloudflare{
- ApiKey: "d2589c4f617b0493357ae187a7b4518171d07",
- ApiEmail: "shiqi@centcloud.net",
- ZoneId: "19e7978bb9292fe11d3c75ff39f87685",
- ZonePlan: "PARTNERS_ENT",
- },
- },
- want: &zone.SetZonePlanReplyCloudflare{Success: true},
- wantErr: false,
- },
- }
- for _, tt := range tests {
- t.Run(tt.name, func(t *testing.T) {
- s := &ZoneServer{
- UnimplementedZoneCloudflareServer: tt.fields.UnimplementedZoneCloudflareServer,
- }
- got, err := s.SetZonePlan(tt.args.ctx, tt.args.requestCloudflare)
- if (err != nil) != tt.wantErr {
- t.Errorf("SetZonePlan() error = %v, wantErr %v", err, tt.wantErr)
- return
- }
- if !reflect.DeepEqual(got, tt.want) {
- t.Errorf("SetZonePlan() got = %v, want %v", got, tt.want)
- }
- })
- }
- }
- func TestZoneServer_CreateZoneRuleSet(t *testing.T) {
- type fields struct {
- UnimplementedZoneCloudflareServer zone.UnimplementedZoneCloudflareServer
- }
- type args struct {
- ctx context.Context
- requestCloudflare *zone.CreateZoneRuleSetRequestCloudflare
- }
- tests := []struct {
- name string
- fields fields
- args args
- want *zone.RuleSet
- wantErr bool
- }{
- {
- name: "测试用例1",
- fields: fields{
- UnimplementedZoneCloudflareServer: zone.UnimplementedZoneCloudflareServer{},
- },
- args: args{
- requestCloudflare: &zone.CreateZoneRuleSetRequestCloudflare{
- ApiKey: "d2589c4f617b0493357ae187a7b4518171d07",
- ApiEmail: "shiqi@centcloud.net",
- ZoneId: "5801a8cbe2fdfd6c53413d0eef164d23",
- RuleSet: &zone.RuleSet{
- Name: "rule1",
- Kind: "zone",
- Phase: zone.Phase_http_request_cache_settings,
- },
- Rules: []*zone.Rule{
- {
- Expression: "(http.request.uri.path contains \"shiqi.website/\")",
- Ttl: lo.ToPtr[uint32](604800),
- QueryArgsType: lo.ToPtr[string]("Include"),
- QueryArgs: []string{"qwe12", "78u9hi"},
- },
- },
- },
- },
- wantErr: false,
- },
- // TODO: Add test cases.
- }
- for _, tt := range tests {
- t.Run(tt.name, func(t *testing.T) {
- s := &ZoneServer{
- UnimplementedZoneCloudflareServer: tt.fields.UnimplementedZoneCloudflareServer,
- }
- got, err := s.CreateZoneRuleSet(tt.args.ctx, tt.args.requestCloudflare)
- if (err != nil) != tt.wantErr {
- t.Errorf("CreateZoneRuleSet() error = %v, wantErr %v", err, tt.wantErr)
- return
- }
- if !reflect.DeepEqual(got, tt.want) {
- t.Errorf("CreateZoneRuleSet() got = %v, want %v", got, tt.want)
- }
- })
- }
- }
- func TestZoneServer_ListZoneRuleSets(t *testing.T) {
- type fields struct {
- UnimplementedZoneCloudflareServer zone.UnimplementedZoneCloudflareServer
- }
- type args struct {
- ctx context.Context
- requestCloudflare *zone.ListZoneRuleSetsRequestCloudflare
- }
- tests := []struct {
- name string
- fields fields
- args args
- want *zone.RuleSetList
- wantErr bool
- }{
- {
- name: "测试用例1",
- fields: fields{
- UnimplementedZoneCloudflareServer: zone.UnimplementedZoneCloudflareServer{},
- },
- args: args{
- requestCloudflare: &zone.ListZoneRuleSetsRequestCloudflare{
- ApiKey: "d2589c4f617b0493357ae187a7b4518171d07",
- ApiEmail: "shiqi@centcloud.net",
- ZoneId: "5801a8cbe2fdfd6c53413d0eef164d23",
- },
- },
- wantErr: false,
- },
- }
- for _, tt := range tests {
- t.Run(tt.name, func(t *testing.T) {
- s := &ZoneServer{
- UnimplementedZoneCloudflareServer: tt.fields.UnimplementedZoneCloudflareServer,
- }
- got, err := s.ListZoneRuleSets(tt.args.ctx, tt.args.requestCloudflare)
- if (err != nil) != tt.wantErr {
- t.Errorf("ListZoneRuleSets() error = %v, wantErr %v", err, tt.wantErr)
- return
- }
- if !reflect.DeepEqual(got, tt.want) {
- t.Errorf("ListZoneRuleSets() got = %v, want %v", got, tt.want)
- }
- })
- }
- }
- func TestZoneServer_UpdateRuleSet1(t *testing.T) {
- type fields struct {
- UnimplementedZoneCloudflareServer zone.UnimplementedZoneCloudflareServer
- }
- type args struct {
- ctx context.Context
- requestCloudflare *zone.UpdateRuleSetRequestCloudflare
- }
- tests := []struct {
- name string
- fields fields
- args args
- want *zone.RuleList
- wantErr bool
- }{
- // TODO: Add test cases.
- {
- name: "测试用例1",
- fields: fields{
- UnimplementedZoneCloudflareServer: zone.UnimplementedZoneCloudflareServer{},
- },
- args: args{
- requestCloudflare: &zone.UpdateRuleSetRequestCloudflare{
- ApiKey: "d2589c4f617b0493357ae187a7b4518171d07",
- ApiEmail: "shiqi@centcloud.net",
- ZoneId: "5ee6daeeecf5c088c7517afa95c50739",
- Phase: zone.Phase_http_request_cache_settings,
- Rules: []*zone.Rule{
- {
- Expression: "(http.request.uri.path contains \"shiqi.website/\")",
- Ttl: lo.ToPtr[uint32](604800 / 7),
- QueryArgsType: lo.ToPtr[string]("Include"),
- QueryArgs: []string{"qwe12", "78u9hi"},
- },
- {
- Expression: "(http.request.uri.path contains \"shiqi.website/\")",
- Ttl: lo.ToPtr[uint32](604800),
- QueryArgsType: lo.ToPtr[string]("Include"),
- QueryArgs: []string{"qwe12"},
- },
- },
- },
- },
- wantErr: false,
- },
- }
- for _, tt := range tests {
- t.Run(tt.name, func(t *testing.T) {
- s := &ZoneServer{
- UnimplementedZoneCloudflareServer: tt.fields.UnimplementedZoneCloudflareServer,
- }
- got, err := s.UpdateRuleSet(tt.args.ctx, tt.args.requestCloudflare)
- fmt.Println(got, err)
- if (err != nil) != tt.wantErr {
- t.Errorf("UpdateRuleSet() error = %v, wantErr %v", err, tt.wantErr)
- return
- }
- if !reflect.DeepEqual(got, tt.want) {
- t.Errorf("UpdateRuleSet() got = %v, want %v", got, tt.want)
- }
- })
- }
- }
- //RuleSetId = 12371a315d344f719382becef2577d4c
- func TestZoneServer_UpdateRuleSetByRuleSetId(t *testing.T) {
- type fields struct {
- UnimplementedZoneCloudflareServer zone.UnimplementedZoneCloudflareServer
- }
- type args struct {
- ctx context.Context
- requestCloudflare *zone.UpdateRuleSetByRuleSetIdRequestCloudflare
- }
- tests := []struct {
- name string
- fields fields
- args args
- want *zone.RuleSet
- wantErr bool
- }{
- // TODO: Add test cases.
- {
- name: "测试用例1",
- fields: fields{
- UnimplementedZoneCloudflareServer: zone.UnimplementedZoneCloudflareServer{},
- },
- args: args{
- requestCloudflare: &zone.UpdateRuleSetByRuleSetIdRequestCloudflare{
- ApiKey: "d2589c4f617b0493357ae187a7b4518171d07",
- ApiEmail: "shiqi@centcloud.net",
- ZoneId: "f62e1be1fea702904da5ead2d1dc15de",
- RuleSetId: "12371a315d344f719382becef2577d4c",
- Phase: zone.Phase_http_request_cache_settings,
- Rules: []*zone.Rule{
- {
- Expression: "(http.request.uri.path contains \"shi.website/\")",
- Ttl: lo.ToPtr[uint32](604800),
- QueryArgsType: lo.ToPtr[string]("ExcludeAll"),
- QueryArgs: []string{"qwe12", "78u9hi"},
- },
- },
- },
- },
- wantErr: false,
- },
- }
- for _, tt := range tests {
- t.Run(tt.name, func(t *testing.T) {
- s := &ZoneServer{
- UnimplementedZoneCloudflareServer: tt.fields.UnimplementedZoneCloudflareServer,
- }
- got, err := s.UpdateRuleSetByRuleSetId(tt.args.ctx, tt.args.requestCloudflare)
- if (err != nil) != tt.wantErr {
- t.Errorf("UpdateRuleSetByRuleSetId() error = %v, wantErr %v", err, tt.wantErr)
- return
- }
- if !reflect.DeepEqual(got, tt.want) {
- t.Errorf("UpdateRuleSetByRuleSetId() got = %v, want %v", got, tt.want)
- }
- })
- }
- }
- func TestZoneServer_DeleteZoneRuleSet(t *testing.T) {
- type fields struct {
- UnimplementedZoneCloudflareServer zone.UnimplementedZoneCloudflareServer
- }
- type args struct {
- ctx context.Context
- requestCloudflare *zone.DeleteZoneRuleSetRequestCloudflare
- }
- tests := []struct {
- name string
- fields fields
- args args
- want *zone.DeleteZoneRuleSetReplyCloudflare
- wantErr bool
- }{
- {
- name: "测试用例1",
- fields: fields{
- UnimplementedZoneCloudflareServer: zone.UnimplementedZoneCloudflareServer{},
- },
- args: args{
- requestCloudflare: &zone.DeleteZoneRuleSetRequestCloudflare{
- ApiKey: "d2589c4f617b0493357ae187a7b4518171d07",
- ApiEmail: "shiqi@centcloud.net",
- ZoneId: "5801a8cbe2fdfd6c53413d0eef164d23",
- RuleSetId: "c9e073e5447c461da612be101d64ec04",
- },
- },
- wantErr: false,
- },
- }
- for _, tt := range tests {
- t.Run(tt.name, func(t *testing.T) {
- s := &ZoneServer{
- UnimplementedZoneCloudflareServer: tt.fields.UnimplementedZoneCloudflareServer,
- }
- got, err := s.DeleteZoneRuleSet(tt.args.ctx, tt.args.requestCloudflare)
- if (err != nil) != tt.wantErr {
- t.Errorf("DeleteZoneRuleSet() error = %v, wantErr %v", err, tt.wantErr)
- return
- }
- if !reflect.DeepEqual(got, tt.want) {
- t.Errorf("DeleteZoneRuleSet() got = %v, want %v", got, tt.want)
- }
- })
- }
- }
- func TestZoneServer_UpdateAlwaysUseHttps(t *testing.T) {
- type fields struct {
- UnimplementedZoneCloudflareServer zone.UnimplementedZoneCloudflareServer
- }
- type args struct {
- ctx context.Context
- requestCloudflare *zone.UpdateAlwaysUseHttpsRequestCloudflare
- }
- tests := []struct {
- name string
- fields fields
- args args
- want *zone.UpdateAlwaysUseHttpsReplyCloudflare
- wantErr bool
- }{
- // TODO: Add test cases.
- {
- name: "测试用例1",
- fields: fields{
- UnimplementedZoneCloudflareServer: zone.UnimplementedZoneCloudflareServer{},
- },
- args: args{
- requestCloudflare: &zone.UpdateAlwaysUseHttpsRequestCloudflare{
- ApiKey: "d2589c4f617b0493357ae187a7b4518171d07",
- ApiEmail: "shiqi@centcloud.net",
- ZoneId: "5801a8cbe2fdfd6c53413d0eef164d23",
- Enabled: false,
- },
- },
- wantErr: false,
- },
- }
- for _, tt := range tests {
- t.Run(tt.name, func(t *testing.T) {
- s := &ZoneServer{
- UnimplementedZoneCloudflareServer: tt.fields.UnimplementedZoneCloudflareServer,
- }
- got, err := s.UpdateAlwaysUseHttps(tt.args.ctx, tt.args.requestCloudflare)
- if (err != nil) != tt.wantErr {
- t.Errorf("UpdateAlwaysUseHttps() error = %v, wantErr %v", err, tt.wantErr)
- return
- }
- if !reflect.DeepEqual(got, tt.want) {
- t.Errorf("UpdateAlwaysUseHttps() got = %v, want %v", got, tt.want)
- }
- })
- }
- }
|