openstack: remove unused code

This commit is contained in:
Malte Poll 2024-02-12 09:38:49 +01:00
parent c5b17fb828
commit bab27fbc69
6 changed files with 7 additions and 219 deletions

View file

@ -338,124 +338,6 @@ func TestVPCIP(t *testing.T) {
}
}
func TestNetworkIDs(t *testing.T) {
someErr := errors.New("failed")
testCases := map[string]struct {
cache networkResponse
cacheTime time.Time
client *stubHTTPClient
wantResult []string
wantCall bool
wantErr bool
}{
"cached": {
cache: networkResponse{Networks: []metadataNetwork{
{ID: "net0", NetworkID: "0000000-00000-0000-0000-000000000000"},
{ID: "net1", NetworkID: "1111111-11111-1111-1111-111111111111"},
{ID: "invalid"},
}},
cacheTime: time.Now(),
wantResult: []string{
"0000000-00000-0000-0000-000000000000",
"1111111-11111-1111-1111-111111111111",
},
wantCall: false,
},
"from http": {
client: &stubHTTPClient{
response: `
{
"networks": [
{
"id": "net0",
"network_id": "0000000-00000-0000-0000-000000000000"
},
{
"id": "net1",
"network_id": "1111111-11111-1111-1111-111111111111"
}
]
}`,
},
wantResult: []string{
"0000000-00000-0000-0000-000000000000",
"1111111-11111-1111-1111-111111111111",
},
wantCall: true,
},
"cache outdated": {
cache: networkResponse{Networks: []metadataNetwork{
{ID: "net0", NetworkID: "0000000-00000-0000-0000-000000000000"},
}},
cacheTime: time.Now().AddDate(0, 0, -1),
client: &stubHTTPClient{
response: `
{
"networks": [
{
"id": "net1",
"network_id": "1111111-11111-1111-1111-111111111111"
}
]
}`,
},
wantResult: []string{"1111111-11111-1111-1111-111111111111"},
wantCall: true,
},
"cache empty": {
cacheTime: time.Now(),
client: &stubHTTPClient{
response: `
{
"networks": [
{
"id": "net0",
"network_id": "0000000-00000-0000-0000-000000000000"
}
]
}`,
},
wantResult: []string{"0000000-00000-0000-0000-000000000000"},
wantCall: true,
},
"http error": {
client: &stubHTTPClient{err: someErr},
wantCall: true,
wantErr: true,
},
"http empty response": {
client: &stubHTTPClient{},
wantCall: true,
wantErr: true,
},
}
for name, tc := range testCases {
t.Run(name, func(t *testing.T) {
assert := assert.New(t)
imds := &imdsClient{
client: tc.client,
networkCache: tc.cache,
networkCacheTime: tc.cacheTime,
}
result, err := imds.networkIDs(context.Background())
if tc.wantErr {
assert.Error(err)
} else {
assert.NoError(err)
assert.Equal(tc.wantResult, result)
if tc.client != nil {
assert.Equal(tc.wantCall, tc.client.called)
}
}
})
}
}
func TestTimeForUpdate(t *testing.T) {
testCases := map[string]struct {
cacheTime time.Time