Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
d6348cc1
Commit
d6348cc1
authored
Aug 04, 2017
by
Antoine Pelisse
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
c-go/transport: Add test for CacheRoundTripper
parent
e77d298f
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
61 additions
and
0 deletions
+61
-0
round_trippers_test.go
...ing/src/k8s.io/client-go/transport/round_trippers_test.go
+61
-0
No files found.
staging/src/k8s.io/client-go/transport/round_trippers_test.go
View file @
d6348cc1
...
@@ -17,7 +17,11 @@ limitations under the License.
...
@@ -17,7 +17,11 @@ limitations under the License.
package
transport
package
transport
import
(
import
(
"bytes"
"io/ioutil"
"net/http"
"net/http"
"net/url"
"os"
"reflect"
"reflect"
"strings"
"strings"
"testing"
"testing"
...
@@ -216,3 +220,60 @@ func TestAuthProxyRoundTripper(t *testing.T) {
...
@@ -216,3 +220,60 @@ func TestAuthProxyRoundTripper(t *testing.T) {
}
}
}
}
}
}
func
TestCacheRoundTripper
(
t
*
testing
.
T
)
{
rt
:=
&
testRoundTripper
{}
cacheDir
,
err
:=
ioutil
.
TempDir
(
""
,
"cache-rt"
)
defer
os
.
RemoveAll
(
cacheDir
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
cache
:=
NewCacheRoundTripper
(
cacheDir
,
rt
)
// First call, caches the response
req
:=
&
http
.
Request
{
Method
:
http
.
MethodGet
,
URL
:
&
url
.
URL
{
Host
:
"localhost"
},
}
rt
.
Response
=
&
http
.
Response
{
Header
:
http
.
Header
{
"ETag"
:
[]
string
{
`"123456"`
}},
Body
:
ioutil
.
NopCloser
(
bytes
.
NewReader
([]
byte
(
"Content"
))),
StatusCode
:
http
.
StatusOK
,
}
resp
,
err
:=
cache
.
RoundTrip
(
req
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
content
,
err
:=
ioutil
.
ReadAll
(
resp
.
Body
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
string
(
content
)
!=
"Content"
{
t
.
Errorf
(
`Expected Body to be "Content", got %q`
,
string
(
content
))
}
// Second call, returns cached response
req
=
&
http
.
Request
{
Method
:
http
.
MethodGet
,
URL
:
&
url
.
URL
{
Host
:
"localhost"
},
}
rt
.
Response
=
&
http
.
Response
{
StatusCode
:
http
.
StatusNotModified
,
Body
:
ioutil
.
NopCloser
(
bytes
.
NewReader
([]
byte
(
"Other Content"
))),
}
resp
,
err
=
cache
.
RoundTrip
(
req
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
// Read body and make sure we have the initial content
content
,
err
=
ioutil
.
ReadAll
(
resp
.
Body
)
resp
.
Body
.
Close
()
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
string
(
content
)
!=
"Content"
{
t
.
Errorf
(
"Invalid content read from cache %q"
,
string
(
content
))
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment