-
Notifications
You must be signed in to change notification settings - Fork 387
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tidy message undone, plus some new script changes
Signed-off-by: Dhruv-J <[email protected]>
- Loading branch information
Showing
8 changed files
with
173 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package fqdncache | ||
|
||
import ( | ||
"encoding/json" | ||
"net" | ||
"net/http" | ||
"net/http/httptest" | ||
"testing" | ||
"time" | ||
|
||
"antrea.io/antrea/pkg/agent/apis" | ||
queriertest "antrea.io/antrea/pkg/agent/querier/testing" | ||
"antrea.io/antrea/pkg/agent/types" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
"go.uber.org/mock/gomock" | ||
) | ||
|
||
func TestFqdnCacheQuery(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
expectedStatus int | ||
expectedResponse []types.DnsCacheEntry | ||
}{ | ||
{ | ||
name: "FQDN cache exists", | ||
expectedStatus: http.StatusOK, | ||
expectedResponse: []types.DnsCacheEntry{ | ||
{ | ||
FqdnName: "google.com", | ||
IpAddress: net.ParseIP("10.0.0.1"), | ||
ExpirationTime: time.Date(2025, 12, 25, 15, 0, 0, 0, time.Now().Location()), | ||
}, | ||
}, | ||
}, | ||
{ | ||
name: "FQDN cache does not exist", | ||
expectedStatus: http.StatusNotFound, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
ctrl := gomock.NewController(t) | ||
q := queriertest.NewMockAgentQuerier(ctrl) | ||
q.EXPECT().GetFqdnCache().Return(tt.expectedResponse[0]) | ||
handler := HandleFunc(q) | ||
|
||
req, err := http.NewRequest(http.MethodGet, "", nil) | ||
require.NoError(t, err) | ||
|
||
recorder := httptest.NewRecorder() | ||
handler.ServeHTTP(recorder, req) | ||
assert.Equal(t, tt.expectedStatus, recorder.Code) | ||
|
||
if tt.expectedStatus == http.StatusOK { | ||
var received []apis.FqdnCacheResponse | ||
err = json.Unmarshal(recorder.Body.Bytes(), &received) | ||
require.NoError(t, err) | ||
assert.Equal(t, tt.expectedResponse, received) | ||
} | ||
}) | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
package fqdncache | ||
|
||
import ( | ||
"bytes" | ||
"encoding/json" | ||
"net" | ||
"testing" | ||
"time" | ||
|
||
"antrea.io/antrea/pkg/agent/types" | ||
"github.com/stretchr/testify/require" | ||
"gotest.tools/assert" | ||
) | ||
|
||
func TestTrasnform(t *testing.T) { | ||
var fqdn1 = types.DnsCacheEntry{ | ||
FqdnName: "google.com", | ||
IpAddress: net.ParseIP("10.0.0.1"), | ||
ExpirationTime: time.Date(2025, 12, 25, 15, 0, 0, 0, time.Now().Location()), | ||
} | ||
var fqdn2 = types.DnsCacheEntry{ | ||
FqdnName: "google.com", | ||
IpAddress: net.ParseIP("10.0.0.2"), | ||
ExpirationTime: time.Date(2025, 12, 25, 15, 0, 0, 0, time.Now().Location()), | ||
} | ||
var fqdn3 = types.DnsCacheEntry{ | ||
FqdnName: "google.com", | ||
IpAddress: net.ParseIP("10.0.0.3"), | ||
ExpirationTime: time.Date(2025, 12, 25, 15, 0, 0, 0, time.Now().Location()), | ||
} | ||
var fqdn4 = types.DnsCacheEntry{ | ||
FqdnName: "example.com", | ||
IpAddress: net.ParseIP("10.0.0.4"), | ||
ExpirationTime: time.Date(2025, 12, 25, 15, 0, 0, 0, time.Now().Location()), | ||
} | ||
var fqdn5 = types.DnsCacheEntry{ | ||
FqdnName: "antrea.io", | ||
IpAddress: net.ParseIP("10.0.0.5"), | ||
ExpirationTime: time.Date(2025, 12, 25, 15, 0, 0, 0, time.Now().Location()), | ||
} | ||
var fqdnList = []types.DnsCacheEntry{fqdn1, fqdn2, fqdn3, fqdn4, fqdn5} | ||
|
||
tests := []struct { | ||
name string | ||
opts map[string]string | ||
fqdnList []types.DnsCacheEntry | ||
expectedResponse interface{} | ||
expectedError string | ||
}{ | ||
{ | ||
name: "all", | ||
fqdnList: fqdnList, | ||
expectedResponse: []Response{{&fqdn1}, {&fqdn2}, {&fqdn3}, {&fqdn4}, {&fqdn5}}, | ||
}, | ||
{ | ||
name: "only google.com domain name", | ||
opts: map[string]string{ | ||
"domain": "google.com", | ||
}, | ||
fqdnList: fqdnList, | ||
expectedResponse: []Response{{&fqdn1}, {&fqdn2}, {&fqdn3}}, | ||
}, | ||
{ | ||
name: "only antrea.io domain name", | ||
opts: map[string]string{ | ||
"domain": "antrea.io", | ||
}, | ||
fqdnList: fqdnList, | ||
expectedResponse: []Response{{&fqdn5}}, | ||
}, | ||
{ | ||
name: "domain name that doesn't exist", | ||
opts: map[string]string{ | ||
"domain": "bing.com", | ||
}, | ||
fqdnList: fqdnList, | ||
expectedResponse: []Response{}, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
reqByte, _ := json.Marshal(tt.fqdnList) | ||
reqReader := bytes.NewReader(reqByte) | ||
result, err := Transform(reqReader, false, tt.opts) | ||
if tt.expectedError == "" { | ||
require.NoError(t, err) | ||
assert.Equal(t, tt.expectedResponse, result) | ||
} else { | ||
assert.ErrorContains(t, err, tt.expectedError) | ||
} | ||
}) | ||
} | ||
} |