github.com/sacloud/libsacloud/v2@v2.32.3/helper/service/proxylb/service_test.go (about)

     1  // Copyright 2016-2022 The Libsacloud Authors
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //      http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package proxylb
    16  
    17  import (
    18  	"os"
    19  	"testing"
    20  
    21  	"github.com/sacloud/libsacloud/v2/sacloud"
    22  	"github.com/sacloud/libsacloud/v2/sacloud/pointer"
    23  	"github.com/sacloud/libsacloud/v2/sacloud/testutil"
    24  	"github.com/sacloud/libsacloud/v2/sacloud/types"
    25  )
    26  
    27  func TestProxyLBService_CRUD(t *testing.T) {
    28  	svc := New(testutil.SingletonAPICaller())
    29  	name := testutil.ResourceName("proxylb")
    30  
    31  	testutil.RunCRUD(t, &testutil.CRUDTestCase{
    32  		Parallel:           true,
    33  		PreCheck:           testutil.PreCheckEnvsFunc("SAKURACLOUD_PROXYLB_SERVER0"),
    34  		SetupAPICallerFunc: testutil.SingletonAPICaller,
    35  		Setup:              nil,
    36  		IgnoreStartupWait:  true,
    37  		Create: &testutil.CRUDTestFunc{
    38  			Func: func(ctx *testutil.CRUDTestContext, _ sacloud.APICaller) (interface{}, error) {
    39  				return svc.Create(&CreateRequest{
    40  					Name:        name,
    41  					Description: "test",
    42  					Tags:        types.Tags{"tag1", "tag2"},
    43  					Plan:        types.ProxyLBPlans.CPS100,
    44  					SorryServer: &sacloud.ProxyLBSorryServer{
    45  						IPAddress: os.Getenv("SAKURACLOUD_PROXYLB_SERVER0"),
    46  						Port:      80,
    47  					},
    48  					HealthCheck: &sacloud.ProxyLBHealthCheck{
    49  						Protocol:  types.ProxyLBProtocols.TCP,
    50  						DelayLoop: 10,
    51  					},
    52  					StickySession: &sacloud.ProxyLBStickySession{
    53  						Enabled: true,
    54  						Method:  "cookie",
    55  					},
    56  					UseVIPFailover: false,
    57  					Syslog: &sacloud.ProxyLBSyslog{
    58  						Server: "",
    59  						Port:   514,
    60  					},
    61  					Timeout: &sacloud.ProxyLBTimeout{
    62  						InactiveSec: 10,
    63  					},
    64  					Region: types.ProxyLBRegions.IS1,
    65  				})
    66  			},
    67  		},
    68  		Read: &testutil.CRUDTestFunc{
    69  			Func: func(ctx *testutil.CRUDTestContext, _ sacloud.APICaller) (interface{}, error) {
    70  				return svc.Read(&ReadRequest{ID: ctx.ID})
    71  			},
    72  		},
    73  		Updates: []*testutil.CRUDTestFunc{
    74  			{
    75  				Func: func(ctx *testutil.CRUDTestContext, _ sacloud.APICaller) (interface{}, error) {
    76  					return svc.Update(&UpdateRequest{
    77  						ID:          ctx.ID,
    78  						Name:        pointer.NewString(name + "-upd"),
    79  						Description: pointer.NewString("test-upd"),
    80  					})
    81  				},
    82  			},
    83  		},
    84  		Delete: &testutil.CRUDTestDeleteFunc{
    85  			Func: func(ctx *testutil.CRUDTestContext, _ sacloud.APICaller) error {
    86  				return svc.Delete(&DeleteRequest{ID: ctx.ID})
    87  			},
    88  		},
    89  		Cleanup: nil,
    90  	})
    91  }