generated from ViBiOh/goweb
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(docker): Adding a safer way to retrieve the next link
Signed-off-by: Vincent Boutour <[email protected]>
- Loading branch information
Showing
2 changed files
with
78 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package docker | ||
|
||
import ( | ||
"net/http" | ||
"testing" | ||
) | ||
|
||
func TestGetNextURL(t *testing.T) { | ||
type args struct { | ||
headers http.Header | ||
registry string | ||
} | ||
|
||
upperCaseHeader := http.Header{} | ||
upperCaseHeader.Add("Link", `rel="next"; /v2/test`) | ||
|
||
lowerCaseHeader := http.Header{} | ||
lowerCaseHeader.Add("link", `rel="prev"; /v2/prev`) | ||
lowerCaseHeader.Add("link", `rel="next"; /v2/next`) | ||
|
||
var cases = []struct { | ||
intention string | ||
args args | ||
want string | ||
}{ | ||
{ | ||
"empty", | ||
args{ | ||
headers: http.Header{}, | ||
registry: "http://localhost", | ||
}, | ||
"", | ||
}, | ||
{ | ||
"uppercase link with next", | ||
args{ | ||
headers: upperCaseHeader, | ||
registry: "http://localhost", | ||
}, | ||
"http://localhost/v2/test", | ||
}, | ||
{ | ||
"lowercase link with previous and next inverted", | ||
args{ | ||
headers: lowerCaseHeader, | ||
registry: "http://localhost", | ||
}, | ||
"http://localhost/v2/next", | ||
}, | ||
} | ||
|
||
for _, tc := range cases { | ||
t.Run(tc.intention, func(t *testing.T) { | ||
if got := getNextURL(tc.args.headers, tc.args.registry); got != tc.want { | ||
t.Errorf("getNextURL() =`%s`, want`%s`", got, tc.want) | ||
} | ||
}) | ||
} | ||
} |