-
Notifications
You must be signed in to change notification settings - Fork 260
Change expected code to 200, since DNC returns 200 #2301
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
32deebc
change expected code to 200, since DNC returns 200
smittal22 12b8dd4
Use http client interface instead of passing in a client directly
smittal22 8e87927
Write test case
smittal22 9ff3c1b
Write test case
smittal22 19c82d4
Write test cases
smittal22 9a1b590
Write test cases
smittal22 afcddaa
Write test cases
smittal22 4b58f0e
Write test cases
smittal22 53756d5
Write test cases
smittal22 f51a0ee
Write test cases
smittal22 d218420
Write test cases
smittal22 0fd2790
fix linter issues
smittal22 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,71 @@ | ||
| package main | ||
|
|
||
| import ( | ||
| "bytes" | ||
| "context" | ||
| "io" | ||
| "net/http" | ||
| "testing" | ||
|
|
||
| "github.com/Azure/azure-container-networking/cns" | ||
| "github.com/Azure/azure-container-networking/cns/fakes" | ||
| "github.com/Azure/azure-container-networking/cns/logger" | ||
| "github.com/stretchr/testify/assert" | ||
| ) | ||
|
|
||
| // MockHTTPClient is a mock implementation of HTTPClient | ||
| type MockHTTPClient struct { | ||
| Response *http.Response | ||
| Err error | ||
| } | ||
|
|
||
| // Post is the implementation of the Post method for MockHTTPClient | ||
| func (m *MockHTTPClient) Do(_ *http.Request) (*http.Response, error) { | ||
| return m.Response, m.Err | ||
| } | ||
|
|
||
| func TestSendRegisterNodeRequest_StatusOK(t *testing.T) { | ||
| ctx := context.Background() | ||
| logger.InitLogger("testlogs", 0, 0, "./") | ||
| httpServiceFake := fakes.NewHTTPServiceFake() | ||
| nodeRegisterReq := cns.NodeRegisterRequest{ | ||
| NumCores: 2, | ||
| NmAgentSupportedApis: nil, | ||
| } | ||
|
|
||
| url := "https://localhost:9000/api" | ||
|
|
||
| // Create a mock HTTP client | ||
| mockResponse := &http.Response{ | ||
| StatusCode: http.StatusOK, | ||
| Body: io.NopCloser(bytes.NewBufferString(`{"status": "success", "OrchestratorType": "Kubernetes", "DncPartitionKey": "1234", "NodeID": "5678"}`)), | ||
| Header: make(http.Header), | ||
| } | ||
|
|
||
| mockClient := &MockHTTPClient{Response: mockResponse, Err: nil} | ||
|
|
||
| assert.NoError(t, sendRegisterNodeRequest(ctx, mockClient, httpServiceFake, nodeRegisterReq, url)) | ||
| } | ||
|
|
||
| func TestSendRegisterNodeRequest_StatusAccepted(t *testing.T) { | ||
| ctx := context.Background() | ||
| logger.InitLogger("testlogs", 0, 0, "./") | ||
| httpServiceFake := fakes.NewHTTPServiceFake() | ||
| nodeRegisterReq := cns.NodeRegisterRequest{ | ||
| NumCores: 2, | ||
| NmAgentSupportedApis: nil, | ||
| } | ||
|
|
||
| url := "https://localhost:9000/api" | ||
|
|
||
| // Create a mock HTTP client | ||
| mockResponse := &http.Response{ | ||
| StatusCode: http.StatusAccepted, | ||
| Body: io.NopCloser(bytes.NewBufferString(`{"status": "accepted", "OrchestratorType": "Kubernetes", "DncPartitionKey": "1234", "NodeID": "5678"}`)), | ||
| Header: make(http.Header), | ||
| } | ||
|
|
||
| mockClient := &MockHTTPClient{Response: mockResponse, Err: nil} | ||
|
|
||
| assert.Error(t, sendRegisterNodeRequest(ctx, mockClient, httpServiceFake, nodeRegisterReq, url)) | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.