-
Notifications
You must be signed in to change notification settings - Fork 7
Adding exported functions for few of the windows errors. #26
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
3 commits
Select commit
Hold shift + click to select a range
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
Some comments aren't visible on the classic Files Changed page.
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
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,151 @@ | ||
| //go:build windows | ||
|
princepereira marked this conversation as resolved.
|
||
| // +build windows | ||
|
|
||
| package hcn | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "testing" | ||
|
|
||
| "golang.org/x/sys/windows" | ||
| ) | ||
|
|
||
| func TestHCNErrorHelpers(t *testing.T) { | ||
| for _, tc := range []struct { | ||
| name string | ||
| err error | ||
| checkFn func(error) bool | ||
| expected bool | ||
| }{ | ||
| // IsElementNotFoundError | ||
| { | ||
| name: "IsElementNotFoundError with matching error", | ||
| err: newHcnError(windows.Errno(windows.ERROR_NOT_FOUND), "test", ""), | ||
| checkFn: IsElementNotFoundError, | ||
|
princepereira marked this conversation as resolved.
|
||
| expected: true, | ||
| }, | ||
| { | ||
| name: "IsElementNotFoundError with non-matching error", | ||
| err: newHcnError(windows.Errno(windows.E_NOTIMPL), "test", ""), | ||
| checkFn: IsElementNotFoundError, | ||
| expected: false, | ||
| }, | ||
|
|
||
| // IsPortAlreadyExistsError | ||
| { | ||
| name: "IsPortAlreadyExistsError with matching error", | ||
| err: newHcnError(windows.Errno(windows.HCN_E_PORT_ALREADY_EXISTS), "test", ""), | ||
| checkFn: IsPortAlreadyExistsError, | ||
| expected: true, | ||
| }, | ||
| { | ||
| name: "IsPortAlreadyExistsError with non-matching error", | ||
| err: newHcnError(windows.Errno(windows.ERROR_NOT_FOUND), "test", ""), | ||
| checkFn: IsPortAlreadyExistsError, | ||
| expected: false, | ||
| }, | ||
|
|
||
| // IsNotImplemented | ||
| { | ||
| name: "IsNotImplemented with matching error", | ||
| err: newHcnError(windows.Errno(windows.E_NOTIMPL), "test", ""), | ||
| checkFn: IsNotImplemented, | ||
| expected: true, | ||
| }, | ||
| { | ||
| name: "IsNotImplemented with non-matching error", | ||
| err: newHcnError(windows.Errno(windows.ERROR_NOT_FOUND), "test", ""), | ||
| checkFn: IsNotImplemented, | ||
| expected: false, | ||
| }, | ||
|
|
||
| // IsNetworkNotFound | ||
| { | ||
| name: "IsNetworkNotFoundError with matching error", | ||
| err: newHcnError(windows.Errno(windows.HCN_E_NETWORK_NOT_FOUND), "test", ""), | ||
| checkFn: IsNetworkNotFoundError, | ||
| expected: true, | ||
| }, | ||
| { | ||
| name: "IsNetworkNotFoundError with non-matching error", | ||
| err: newHcnError(windows.Errno(windows.ERROR_NOT_FOUND), "test", ""), | ||
| checkFn: IsNetworkNotFoundError, | ||
| expected: false, | ||
| }, | ||
|
|
||
| // IsEndpointNotFoundError | ||
| { | ||
| name: "IsEndpointNotFoundError with matching error", | ||
| err: newHcnError(windows.Errno(windows.HCN_E_ENDPOINT_NOT_FOUND), "test", ""), | ||
| checkFn: IsEndpointNotFoundError, | ||
| expected: true, | ||
| }, | ||
| { | ||
| name: "IsEndpointNotFoundError with non-matching error", | ||
| err: newHcnError(windows.Errno(windows.ERROR_NOT_FOUND), "test", ""), | ||
| checkFn: IsEndpointNotFoundError, | ||
| expected: false, | ||
| }, | ||
|
|
||
| // IsPortNotFoundError | ||
| { | ||
| name: "IsPortNotFoundError with matching error", | ||
| err: newHcnError(windows.Errno(windows.HCN_E_PORT_NOT_FOUND), "test", ""), | ||
| checkFn: IsPortNotFoundError, | ||
| expected: true, | ||
| }, | ||
| { | ||
| name: "IsPortNotFoundError with non-matching error", | ||
| err: newHcnError(windows.Errno(windows.ERROR_NOT_FOUND), "test", ""), | ||
| checkFn: IsPortNotFoundError, | ||
| expected: false, | ||
| }, | ||
|
|
||
| // IsInvalidIPError | ||
| { | ||
| name: "IsInvalidIPError with matching error", | ||
| err: newHcnError(windows.Errno(windows.HCN_E_INVALID_IP), "test", ""), | ||
| checkFn: IsInvalidIPError, | ||
| expected: true, | ||
| }, | ||
| { | ||
| name: "IsInvalidIPError with non-matching error", | ||
| err: newHcnError(windows.Errno(windows.ERROR_NOT_FOUND), "test", ""), | ||
| checkFn: IsInvalidIPError, | ||
| expected: false, | ||
| }, | ||
|
|
||
| // IsAdapterNotFoundError | ||
| { | ||
| name: "IsAdapterNotFoundError with matching error", | ||
| err: newHcnError(windows.Errno(windows.HCN_E_ADAPTER_NOT_FOUND), "test", ""), | ||
| checkFn: IsAdapterNotFoundError, | ||
| expected: true, | ||
| }, | ||
| { | ||
| name: "IsAdapterNotFoundError with non-matching error", | ||
| err: newHcnError(windows.Errno(windows.ERROR_NOT_FOUND), "test", ""), | ||
| checkFn: IsAdapterNotFoundError, | ||
| expected: false, | ||
| }, | ||
|
|
||
| // Non-HcnError | ||
| { | ||
| name: "non-HcnError returns false", | ||
| err: fmt.Errorf("random error"), | ||
| checkFn: IsPortAlreadyExistsError, | ||
| expected: false, | ||
| }, | ||
| } { | ||
| t.Run(tc.name, func(t *testing.T) { | ||
| if got := tc.checkFn(tc.err); got != tc.expected { | ||
| t.Errorf("expected %t, got %t for error: %v", tc.expected, got, tc.err) | ||
| } | ||
| // Also test wrapped error | ||
| wrapped := fmt.Errorf("wrapped: %w", tc.err) | ||
| if got := tc.checkFn(wrapped); got != tc.expected { | ||
| t.Errorf("expected %t for wrapped error, got %t for error: %v", tc.expected, got, wrapped) | ||
| } | ||
| }) | ||
| } | ||
| } | ||
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,11 @@ | ||
| //go:build windows | ||
| // +build windows | ||
|
|
||
| package hcn | ||
|
|
||
| const ( | ||
| NatTestNetworkName string = "GoTestNat" | ||
| NatTestEndpointName string = "GoTestNatEndpoint" | ||
| OverlayTestNetworkName string = "GoTestOverlay" | ||
| BridgeTestNetworkName string = "GoTestL2Bridge" | ||
| ) |
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
Oops, something went wrong.
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.