-
-
Notifications
You must be signed in to change notification settings - Fork 13
#16 in range returns incorrect registered port #17
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| package httpref | ||
|
|
||
| import ( | ||
| "regexp" | ||
| "strings" | ||
| "testing" | ||
|
|
||
|
|
@@ -29,20 +30,34 @@ func TestReferences_ByName(t *testing.T) { | |
| } | ||
|
|
||
| func TestReferences_InRange(t *testing.T) { | ||
dnnrly marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| tests := []string{ | ||
| "19150", | ||
| "16406", | ||
| "5988", | ||
| "5989", | ||
| tests := []struct { | ||
| having string | ||
| expect string | ||
| }{ | ||
| {having: "19150", expect: "10000-20000"}, | ||
| {having: "16406", expect: "10000-20000"}, | ||
| {having: "5988", expect: "5988-5989"}, | ||
| {having: "5989", expect: "5988-5989"}, | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like this change. It says what we're testing more succinctly. |
||
| } | ||
|
|
||
| for _, tt := range tests { | ||
| t.Run(tt, func(t *testing.T) { | ||
| if got := RegisteredPorts.InRange(tt); len(got) != 1 { | ||
| t.Run(tt.having, func(t *testing.T) { | ||
| got := RegisteredPorts.InRange(tt.having) | ||
| if len(got) != 1 { | ||
| t.Errorf("References.InRange() = %v, want %v", len(got), 1) | ||
| } | ||
| if got[0].Name != tt.expect { | ||
| t.Errorf("References.InRange()[0] = %v, want %v", got[0].Name, tt.expect) | ||
| } | ||
| }) | ||
| } | ||
|
|
||
dnnrly marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| t.Run("Invalid port should not return anything", func(t *testing.T) { | ||
| got := RegisteredPorts.InRange("70000") // Invalid port, should not return anything | ||
| if len(got) != 0 { | ||
| t.Errorf("References.InRange() = %v, want %v", len(got), 0) | ||
| } | ||
| }) | ||
| } | ||
|
|
||
| func TestReference_SummarizeContainsCorrectParts(t *testing.T) { | ||
|
|
@@ -86,3 +101,13 @@ func TestReferences_Titles(t *testing.T) { | |
| n := Statuses.Titles() | ||
| assert.Equal(t, 5, len(n)) | ||
| } | ||
|
|
||
dnnrly marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| func TestPortsConsistencyValidation(t *testing.T) { | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was going to ask if this test is necessary BUT I think it actually specifies the contract for naming port mappings. Well spotted! |
||
| ports := append(WellKnownPorts[1:], RegisteredPorts[1:]...) | ||
| var validRange = regexp.MustCompile(`^\d+(-\d+)?$`) | ||
| for _, port := range ports { | ||
| if !validRange.MatchString(port.Name) { | ||
| t.Errorf("Invalid port format: %v", port.Name) | ||
| } | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.