github.com/sacloud/iaas-api-go@v1.12.0/fake/pool_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 fake 16 17 import ( 18 "testing" 19 20 "github.com/stretchr/testify/require" 21 ) 22 23 func TestNextSubnet(t *testing.T) { 24 DataStore = NewInMemoryStore() 25 // internal init 26 vp = initValuePool(DataStore) 27 28 first := pool().nextSubnet(24) 29 require.Equal(t, "24.0.1.0", first.networkAddress) 30 require.Equal(t, 24, first.networkMaskLen) 31 require.Len(t, first.addresses, 251) 32 require.Equal(t, "24.0.1.4", first.addresses[0]) 33 require.Equal(t, "24.0.1.254", first.addresses[len(first.addresses)-1]) 34 35 next := pool().nextSubnet(24) 36 require.Equal(t, "24.0.2.0", next.networkAddress) 37 require.Equal(t, 24, next.networkMaskLen) 38 require.Len(t, next.addresses, 251) 39 require.Equal(t, "24.0.2.4", next.addresses[0]) 40 require.Equal(t, "24.0.2.254", next.addresses[len(next.addresses)-1]) 41 }