|
| 1 | +/* |
| 2 | +Copyright 2023 The Kubernetes Authors. |
| 3 | +
|
| 4 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +you may not use this file except in compliance with the License. |
| 6 | +You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | +Unless required by applicable law or agreed to in writing, software |
| 11 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +See the License for the specific language governing permissions and |
| 14 | +limitations under the License. |
| 15 | +*/ |
| 16 | + |
| 17 | +package oci |
| 18 | + |
| 19 | +import ( |
| 20 | + "github.com/oracle/oci-go-sdk/v65/dns" |
| 21 | + "github.com/stretchr/testify/assert" |
| 22 | + "testing" |
| 23 | + "time" |
| 24 | +) |
| 25 | + |
| 26 | +func TestZoneCache(t *testing.T) { |
| 27 | + now := time.Now() |
| 28 | + var testCases = map[string]struct { |
| 29 | + z *zoneCache |
| 30 | + expired bool |
| 31 | + }{ |
| 32 | + "inactive-zone-cache": { |
| 33 | + &zoneCache{ |
| 34 | + duration: 0 * time.Second, |
| 35 | + }, |
| 36 | + true, |
| 37 | + }, |
| 38 | + "empty-active-zone-cache": { |
| 39 | + &zoneCache{ |
| 40 | + duration: 30 * time.Second, |
| 41 | + }, |
| 42 | + true, |
| 43 | + }, |
| 44 | + "expired-zone-cache": { |
| 45 | + &zoneCache{ |
| 46 | + age: now.Add(300 * time.Second), |
| 47 | + duration: 30 * time.Second, |
| 48 | + }, |
| 49 | + true, |
| 50 | + }, |
| 51 | + "active-zone-cache": { |
| 52 | + &zoneCache{ |
| 53 | + zones: map[string]dns.ZoneSummary{ |
| 54 | + zoneIdBaz: testPrivateZoneSummaryBaz, |
| 55 | + }, |
| 56 | + duration: 30 * time.Second, |
| 57 | + }, |
| 58 | + true, |
| 59 | + }, |
| 60 | + } |
| 61 | + |
| 62 | + for name, testCase := range testCases { |
| 63 | + t.Run(name, func(t *testing.T) { |
| 64 | + assert.Equal(t, testCase.expired, testCase.z.Expired()) |
| 65 | + var resetZoneLength = 1 |
| 66 | + if testCase.z.duration == 0 { |
| 67 | + resetZoneLength = 0 |
| 68 | + } |
| 69 | + testCase.z.Reset(map[string]dns.ZoneSummary{ |
| 70 | + zoneIdQux: testPrivateZoneSummaryQux, |
| 71 | + }) |
| 72 | + assert.Len(t, testCase.z.Get(), resetZoneLength) |
| 73 | + }) |
| 74 | + } |
| 75 | +} |
0 commit comments