github.com/sacloud/libsacloud/v2@v2.32.3/helper/service/certificateauthority/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 certificateauthority
    16  
    17  import (
    18  	"testing"
    19  	"time"
    20  
    21  	"github.com/sacloud/libsacloud/v2/sacloud"
    22  	"github.com/sacloud/libsacloud/v2/sacloud/testutil"
    23  	"github.com/sacloud/libsacloud/v2/sacloud/types"
    24  )
    25  
    26  func TestCertificateAuthorityService_CRUD(t *testing.T) {
    27  	if !testutil.IsAccTest() {
    28  		t.Skip("TestCertificateAuthorityService_CRUD only exec when running an Acceptance Test")
    29  	}
    30  
    31  	svc := New(testutil.SingletonAPICaller())
    32  	name := testutil.ResourceName("ca")
    33  
    34  	testutil.RunCRUD(t, &testutil.CRUDTestCase{
    35  		Parallel:           true,
    36  		PreCheck:           nil,
    37  		SetupAPICallerFunc: testutil.SingletonAPICaller,
    38  		Setup:              nil,
    39  		Create: &testutil.CRUDTestFunc{
    40  			Func: func(ctx *testutil.CRUDTestContext, _ sacloud.APICaller) (interface{}, error) {
    41  				return svc.Create(&CreateRequest{
    42  					Name:             name,
    43  					Description:      "test",
    44  					Tags:             types.Tags{"tag1", "tag2"},
    45  					Country:          "JP",
    46  					Organization:     "usacloud",
    47  					OrganizationUnit: []string{"ou1", "ou2"},
    48  					CommonName:       "www.usacloud.jp",
    49  					NotAfter:         time.Now().Add(365 * 24 * time.Hour),
    50  					Clients: []*ClientCert{
    51  						{
    52  							Country:        "JP",
    53  							Organization:   "usacloud",
    54  							CommonName:     "client.usacloud.jp",
    55  							NotAfter:       time.Now().Add(365 * 24 * time.Hour),
    56  							IssuanceMethod: types.CertificateAuthorityIssuanceMethods.URL,
    57  						},
    58  					},
    59  				})
    60  			},
    61  		},
    62  		Read: &testutil.CRUDTestFunc{
    63  			Func: func(ctx *testutil.CRUDTestContext, _ sacloud.APICaller) (interface{}, error) {
    64  				return svc.Read(&ReadRequest{ID: ctx.ID})
    65  			},
    66  		},
    67  		Delete: &testutil.CRUDTestDeleteFunc{
    68  			Func: func(ctx *testutil.CRUDTestContext, _ sacloud.APICaller) error {
    69  				return svc.Delete(&DeleteRequest{ID: ctx.ID})
    70  			},
    71  		},
    72  	})
    73  }