github.com/sacloud/iaas-api-go@v1.12.0/test/note_op_test.go (about) 1 // Copyright 2022-2023 The sacloud/iaas-api-go 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 test 16 17 import ( 18 "testing" 19 20 "github.com/sacloud/iaas-api-go" 21 "github.com/sacloud/iaas-api-go/testutil" 22 "github.com/sacloud/iaas-api-go/types" 23 ) 24 25 func TestNoteOp_CRUD(t *testing.T) { 26 testutil.RunCRUD(t, &testutil.CRUDTestCase{ 27 Parallel: true, 28 IgnoreStartupWait: true, 29 SetupAPICallerFunc: singletonAPICaller, 30 Create: &testutil.CRUDTestFunc{ 31 Func: testNoteCreate, 32 CheckFunc: testutil.AssertEqualWithExpected(&testutil.CRUDTestExpect{ 33 ExpectValue: createNoteExpected, 34 IgnoreFields: ignoreNoteFields, 35 }), 36 }, 37 Read: &testutil.CRUDTestFunc{ 38 Func: testNoteRead, 39 CheckFunc: testutil.AssertEqualWithExpected(&testutil.CRUDTestExpect{ 40 ExpectValue: createNoteExpected, 41 IgnoreFields: ignoreNoteFields, 42 }), 43 }, 44 Updates: []*testutil.CRUDTestFunc{ 45 { 46 Func: testNoteUpdate, 47 CheckFunc: testutil.AssertEqualWithExpected(&testutil.CRUDTestExpect{ 48 ExpectValue: updateNoteExpected, 49 IgnoreFields: ignoreNoteFields, 50 }), 51 }, 52 { 53 Func: testNoteUpdateToMin, 54 CheckFunc: testutil.AssertEqualWithExpected(&testutil.CRUDTestExpect{ 55 ExpectValue: updateNoteToMinExpected, 56 IgnoreFields: ignoreNoteFields, 57 }), 58 }, 59 }, 60 Delete: &testutil.CRUDTestDeleteFunc{ 61 Func: testNoteDelete, 62 }, 63 }) 64 } 65 66 var ( 67 ignoreNoteFields = []string{"ID", "CreatedAt", "ModifiedAt"} 68 createNoteParam = &iaas.NoteCreateRequest{ 69 Name: testutil.ResourceName("note"), 70 Tags: []string{"tag1", "tag2"}, 71 Class: "shell", 72 Content: "test-content", 73 } 74 createNoteExpected = &iaas.Note{ 75 Name: createNoteParam.Name, 76 Tags: createNoteParam.Tags, 77 Class: createNoteParam.Class, 78 Content: createNoteParam.Content, 79 Scope: types.Scopes.User, 80 Availability: types.Availabilities.Available, 81 } 82 updateNoteParam = &iaas.NoteUpdateRequest{ 83 Name: testutil.ResourceName("note-upd"), 84 Tags: []string{"tag1-upd", "tag2-upd"}, 85 Class: "shell", 86 Content: "test-content-upd", 87 IconID: testIconID, 88 } 89 updateNoteExpected = &iaas.Note{ 90 Name: updateNoteParam.Name, 91 Tags: updateNoteParam.Tags, 92 Class: updateNoteParam.Class, 93 Content: updateNoteParam.Content, 94 Scope: types.Scopes.User, 95 Availability: types.Availabilities.Available, 96 IconID: updateNoteParam.IconID, 97 } 98 updateNoteToMinParam = &iaas.NoteUpdateRequest{ 99 Name: testutil.ResourceName("note-to-min"), 100 Class: "shell", 101 Content: "test-content-upd", 102 } 103 updateNoteToMinExpected = &iaas.Note{ 104 Name: updateNoteToMinParam.Name, 105 Class: updateNoteToMinParam.Class, 106 Content: updateNoteToMinParam.Content, 107 Scope: types.Scopes.User, 108 Availability: types.Availabilities.Available, 109 } 110 ) 111 112 func testNoteCreate(ctx *testutil.CRUDTestContext, caller iaas.APICaller) (interface{}, error) { 113 client := iaas.NewNoteOp(caller) 114 return client.Create(ctx, createNoteParam) 115 } 116 117 func testNoteRead(ctx *testutil.CRUDTestContext, caller iaas.APICaller) (interface{}, error) { 118 client := iaas.NewNoteOp(caller) 119 return client.Read(ctx, ctx.ID) 120 } 121 122 func testNoteUpdate(ctx *testutil.CRUDTestContext, caller iaas.APICaller) (interface{}, error) { 123 client := iaas.NewNoteOp(caller) 124 return client.Update(ctx, ctx.ID, updateNoteParam) 125 } 126 127 func testNoteUpdateToMin(ctx *testutil.CRUDTestContext, caller iaas.APICaller) (interface{}, error) { 128 client := iaas.NewNoteOp(caller) 129 return client.Update(ctx, ctx.ID, updateNoteToMinParam) 130 } 131 132 func testNoteDelete(ctx *testutil.CRUDTestContext, caller iaas.APICaller) error { 133 client := iaas.NewNoteOp(caller) 134 return client.Delete(ctx, ctx.ID) 135 }