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
3d63c71c
Commit
3d63c71c
authored
Jun 15, 2015
by
nikhiljindal
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Removing legacyBehavior param from pkg/client
parent
19a7e87c
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
42 additions
and
97 deletions
+42
-97
fake.go
pkg/client/fake.go
+4
-5
helper.go
pkg/client/helper.go
+1
-7
helper_test.go
pkg/client/helper_test.go
+5
-6
request.go
pkg/client/request.go
+4
-22
request_test.go
pkg/client/request_test.go
+7
-16
restclient.go
pkg/client/restclient.go
+5
-15
restclient_test.go
pkg/client/restclient_test.go
+15
-24
config_test.go
pkg/config/config_test.go
+1
-2
No files found.
pkg/client/fake.go
View file @
3d63c71c
...
@@ -34,26 +34,25 @@ func (f HTTPClientFunc) Do(req *http.Request) (*http.Response, error) {
...
@@ -34,26 +34,25 @@ func (f HTTPClientFunc) Do(req *http.Request) (*http.Response, error) {
type
FakeRESTClient
struct
{
type
FakeRESTClient
struct
{
Client
HTTPClient
Client
HTTPClient
Codec
runtime
.
Codec
Codec
runtime
.
Codec
Legacy
bool
Req
*
http
.
Request
Req
*
http
.
Request
Resp
*
http
.
Response
Resp
*
http
.
Response
Err
error
Err
error
}
}
func
(
c
*
FakeRESTClient
)
Get
()
*
Request
{
func
(
c
*
FakeRESTClient
)
Get
()
*
Request
{
return
NewRequest
(
c
,
"GET"
,
&
url
.
URL
{
Host
:
"localhost"
},
testapi
.
Version
(),
c
.
Codec
,
c
.
Legacy
,
c
.
Legacy
)
return
NewRequest
(
c
,
"GET"
,
&
url
.
URL
{
Host
:
"localhost"
},
testapi
.
Version
(),
c
.
Codec
)
}
}
func
(
c
*
FakeRESTClient
)
Put
()
*
Request
{
func
(
c
*
FakeRESTClient
)
Put
()
*
Request
{
return
NewRequest
(
c
,
"PUT"
,
&
url
.
URL
{
Host
:
"localhost"
},
testapi
.
Version
(),
c
.
Codec
,
c
.
Legacy
,
c
.
Legacy
)
return
NewRequest
(
c
,
"PUT"
,
&
url
.
URL
{
Host
:
"localhost"
},
testapi
.
Version
(),
c
.
Codec
)
}
}
func
(
c
*
FakeRESTClient
)
Post
()
*
Request
{
func
(
c
*
FakeRESTClient
)
Post
()
*
Request
{
return
NewRequest
(
c
,
"POST"
,
&
url
.
URL
{
Host
:
"localhost"
},
testapi
.
Version
(),
c
.
Codec
,
c
.
Legacy
,
c
.
Legacy
)
return
NewRequest
(
c
,
"POST"
,
&
url
.
URL
{
Host
:
"localhost"
},
testapi
.
Version
(),
c
.
Codec
)
}
}
func
(
c
*
FakeRESTClient
)
Delete
()
*
Request
{
func
(
c
*
FakeRESTClient
)
Delete
()
*
Request
{
return
NewRequest
(
c
,
"DELETE"
,
&
url
.
URL
{
Host
:
"localhost"
},
testapi
.
Version
(),
c
.
Codec
,
c
.
Legacy
,
c
.
Legacy
)
return
NewRequest
(
c
,
"DELETE"
,
&
url
.
URL
{
Host
:
"localhost"
},
testapi
.
Version
(),
c
.
Codec
)
}
}
func
(
c
*
FakeRESTClient
)
Do
(
req
*
http
.
Request
)
(
*
http
.
Response
,
error
)
{
func
(
c
*
FakeRESTClient
)
Do
(
req
*
http
.
Request
)
(
*
http
.
Response
,
error
)
{
...
...
pkg/client/helper.go
View file @
3d63c71c
...
@@ -46,11 +46,6 @@ type Config struct {
...
@@ -46,11 +46,6 @@ type Config struct {
// a RESTClient directly. When initializing a Client, will be set with the default
// a RESTClient directly. When initializing a Client, will be set with the default
// code version.
// code version.
Version
string
Version
string
// LegacyBehavior defines whether the RESTClient should follow conventions that
// existed prior to v1beta3 in Kubernetes - namely, namespace (if specified)
// not being part of the path, and resource names allowing mixed case. Set to
// true when using Kubernetes v1beta1 or v1beta2.
LegacyBehavior
bool
// Codec specifies the encoding and decoding behavior for runtime.Objects passed
// Codec specifies the encoding and decoding behavior for runtime.Objects passed
// to a RESTClient or Client. Required when initializing a RESTClient, optional
// to a RESTClient or Client. Required when initializing a RESTClient, optional
// when initializing a Client.
// when initializing a Client.
...
@@ -218,7 +213,6 @@ func SetKubernetesDefaults(config *Config) error {
...
@@ -218,7 +213,6 @@ func SetKubernetesDefaults(config *Config) error {
if
config
.
Codec
==
nil
{
if
config
.
Codec
==
nil
{
config
.
Codec
=
versionInterfaces
.
Codec
config
.
Codec
=
versionInterfaces
.
Codec
}
}
config
.
LegacyBehavior
=
(
version
==
"v1beta1"
||
version
==
"v1beta2"
)
if
config
.
QPS
==
0.0
{
if
config
.
QPS
==
0.0
{
config
.
QPS
=
5.0
config
.
QPS
=
5.0
}
}
...
@@ -245,7 +239,7 @@ func RESTClientFor(config *Config) (*RESTClient, error) {
...
@@ -245,7 +239,7 @@ func RESTClientFor(config *Config) (*RESTClient, error) {
return
nil
,
err
return
nil
,
err
}
}
client
:=
NewRESTClient
(
baseURL
,
config
.
Version
,
config
.
Codec
,
config
.
LegacyBehavior
,
config
.
QPS
,
config
.
Burst
)
client
:=
NewRESTClient
(
baseURL
,
config
.
Version
,
config
.
Codec
,
config
.
QPS
,
config
.
Burst
)
transport
,
err
:=
TransportFor
(
config
)
transport
,
err
:=
TransportFor
(
config
)
if
err
!=
nil
{
if
err
!=
nil
{
...
...
pkg/client/helper_test.go
View file @
3d63c71c
...
@@ -269,12 +269,11 @@ func TestSetKubernetesDefaults(t *testing.T) {
...
@@ -269,12 +269,11 @@ func TestSetKubernetesDefaults(t *testing.T) {
{
{
Config
{},
Config
{},
Config
{
Config
{
Prefix
:
"/api"
,
Prefix
:
"/api"
,
Version
:
latest
.
Version
,
Version
:
latest
.
Version
,
Codec
:
latest
.
Codec
,
Codec
:
latest
.
Codec
,
LegacyBehavior
:
(
latest
.
Version
==
"v1beta1"
||
latest
.
Version
==
"v1beta2"
),
QPS
:
5
,
QPS
:
5
,
Burst
:
10
,
Burst
:
10
,
},
},
false
,
false
,
},
},
...
...
pkg/client/request.go
View file @
3d63c71c
...
@@ -72,13 +72,6 @@ type Request struct {
...
@@ -72,13 +72,6 @@ type Request struct {
baseURL
*
url
.
URL
baseURL
*
url
.
URL
codec
runtime
.
Codec
codec
runtime
.
Codec
// If true, add "?namespace=<namespace>" as a query parameter, if false put namespaces/<namespace> in path
// Query parameter is considered legacy behavior
namespaceInQuery
bool
// If true, lowercase resource prior to inserting into a path, if false, leave it as is. Preserving
// case is considered legacy behavior.
preserveResourceCase
bool
// generic components accessible via method setters
// generic components accessible via method setters
path
string
path
string
subpath
string
subpath
string
...
@@ -107,7 +100,7 @@ type Request struct {
...
@@ -107,7 +100,7 @@ type Request struct {
// NewRequest creates a new request helper object for accessing runtime.Objects on a server.
// NewRequest creates a new request helper object for accessing runtime.Objects on a server.
func
NewRequest
(
client
HTTPClient
,
verb
string
,
baseURL
*
url
.
URL
,
apiVersion
string
,
func
NewRequest
(
client
HTTPClient
,
verb
string
,
baseURL
*
url
.
URL
,
apiVersion
string
,
codec
runtime
.
Codec
,
namespaceInQuery
bool
,
preserveResourceCase
bool
)
*
Request
{
codec
runtime
.
Codec
)
*
Request
{
metrics
.
Register
()
metrics
.
Register
()
return
&
Request
{
return
&
Request
{
client
:
client
,
client
:
client
,
...
@@ -115,10 +108,7 @@ func NewRequest(client HTTPClient, verb string, baseURL *url.URL, apiVersion str
...
@@ -115,10 +108,7 @@ func NewRequest(client HTTPClient, verb string, baseURL *url.URL, apiVersion str
baseURL
:
baseURL
,
baseURL
:
baseURL
,
path
:
baseURL
.
Path
,
path
:
baseURL
.
Path
,
apiVersion
:
apiVersion
,
apiVersion
:
apiVersion
,
codec
:
codec
,
codec
:
codec
,
namespaceInQuery
:
namespaceInQuery
,
preserveResourceCase
:
preserveResourceCase
,
}
}
}
}
...
@@ -490,15 +480,11 @@ func (r *Request) Body(obj interface{}) *Request {
...
@@ -490,15 +480,11 @@ func (r *Request) Body(obj interface{}) *Request {
// URL returns the current working URL.
// URL returns the current working URL.
func
(
r
*
Request
)
URL
()
*
url
.
URL
{
func
(
r
*
Request
)
URL
()
*
url
.
URL
{
p
:=
r
.
path
p
:=
r
.
path
if
r
.
namespaceSet
&&
!
r
.
namespaceInQuery
&&
len
(
r
.
namespace
)
>
0
{
if
r
.
namespaceSet
&&
len
(
r
.
namespace
)
>
0
{
p
=
path
.
Join
(
p
,
"namespaces"
,
r
.
namespace
)
p
=
path
.
Join
(
p
,
"namespaces"
,
r
.
namespace
)
}
}
if
len
(
r
.
resource
)
!=
0
{
if
len
(
r
.
resource
)
!=
0
{
resource
:=
r
.
resource
p
=
path
.
Join
(
p
,
strings
.
ToLower
(
r
.
resource
))
if
!
r
.
preserveResourceCase
{
resource
=
strings
.
ToLower
(
resource
)
}
p
=
path
.
Join
(
p
,
resource
)
}
}
// Join trims trailing slashes, so preserve r.path's trailing slash for backwards compat if nothing was changed
// Join trims trailing slashes, so preserve r.path's trailing slash for backwards compat if nothing was changed
if
len
(
r
.
resourceName
)
!=
0
||
len
(
r
.
subpath
)
!=
0
||
len
(
r
.
subresource
)
!=
0
{
if
len
(
r
.
resourceName
)
!=
0
||
len
(
r
.
subpath
)
!=
0
||
len
(
r
.
subresource
)
!=
0
{
...
@@ -518,10 +504,6 @@ func (r *Request) URL() *url.URL {
...
@@ -518,10 +504,6 @@ func (r *Request) URL() *url.URL {
}
}
}
}
if
r
.
namespaceSet
&&
r
.
namespaceInQuery
{
query
.
Set
(
"namespace"
,
r
.
namespace
)
}
// timeout is handled specially here.
// timeout is handled specially here.
if
r
.
timeout
!=
0
{
if
r
.
timeout
!=
0
{
query
.
Set
(
"timeout"
,
r
.
timeout
.
String
())
query
.
Set
(
"timeout"
,
r
.
timeout
.
String
())
...
...
pkg/client/request_test.go
View file @
3d63c71c
...
@@ -70,14 +70,14 @@ func TestRequestWithErrorWontChange(t *testing.T) {
...
@@ -70,14 +70,14 @@ func TestRequestWithErrorWontChange(t *testing.T) {
}
}
func
TestRequestPreservesBaseTrailingSlash
(
t
*
testing
.
T
)
{
func
TestRequestPreservesBaseTrailingSlash
(
t
*
testing
.
T
)
{
r
:=
&
Request
{
baseURL
:
&
url
.
URL
{},
path
:
"/path/"
,
namespaceInQuery
:
true
}
r
:=
&
Request
{
baseURL
:
&
url
.
URL
{},
path
:
"/path/"
}
if
s
:=
r
.
URL
()
.
String
();
s
!=
"/path/"
{
if
s
:=
r
.
URL
()
.
String
();
s
!=
"/path/"
{
t
.
Errorf
(
"trailing slash should be preserved: %s"
,
s
)
t
.
Errorf
(
"trailing slash should be preserved: %s"
,
s
)
}
}
}
}
func
TestRequestAbsPathPreservesTrailingSlash
(
t
*
testing
.
T
)
{
func
TestRequestAbsPathPreservesTrailingSlash
(
t
*
testing
.
T
)
{
r
:=
(
&
Request
{
baseURL
:
&
url
.
URL
{}
,
namespaceInQuery
:
true
})
.
AbsPath
(
"/foo/"
)
r
:=
(
&
Request
{
baseURL
:
&
url
.
URL
{}})
.
AbsPath
(
"/foo/"
)
if
s
:=
r
.
URL
()
.
String
();
s
!=
"/foo/"
{
if
s
:=
r
.
URL
()
.
String
();
s
!=
"/foo/"
{
t
.
Errorf
(
"trailing slash should be preserved: %s"
,
s
)
t
.
Errorf
(
"trailing slash should be preserved: %s"
,
s
)
}
}
...
@@ -89,7 +89,7 @@ func TestRequestAbsPathPreservesTrailingSlash(t *testing.T) {
...
@@ -89,7 +89,7 @@ func TestRequestAbsPathPreservesTrailingSlash(t *testing.T) {
}
}
func
TestRequestAbsPathJoins
(
t
*
testing
.
T
)
{
func
TestRequestAbsPathJoins
(
t
*
testing
.
T
)
{
r
:=
(
&
Request
{
baseURL
:
&
url
.
URL
{}
,
namespaceInQuery
:
true
})
.
AbsPath
(
"foo/bar"
,
"baz"
)
r
:=
(
&
Request
{
baseURL
:
&
url
.
URL
{}})
.
AbsPath
(
"foo/bar"
,
"baz"
)
if
s
:=
r
.
URL
()
.
String
();
s
!=
"foo/bar/baz"
{
if
s
:=
r
.
URL
()
.
String
();
s
!=
"foo/bar/baz"
{
t
.
Errorf
(
"trailing slash should be preserved: %s"
,
s
)
t
.
Errorf
(
"trailing slash should be preserved: %s"
,
s
)
}
}
...
@@ -100,20 +100,11 @@ func TestRequestSetsNamespace(t *testing.T) {
...
@@ -100,20 +100,11 @@ func TestRequestSetsNamespace(t *testing.T) {
baseURL
:
&
url
.
URL
{
baseURL
:
&
url
.
URL
{
Path
:
"/"
,
Path
:
"/"
,
},
},
namespaceInQuery
:
true
,
})
.
Namespace
(
"foo"
)
})
.
Namespace
(
"foo"
)
if
r
.
namespace
==
""
{
if
r
.
namespace
==
""
{
t
.
Errorf
(
"namespace should be set: %#v"
,
r
)
t
.
Errorf
(
"namespace should be set: %#v"
,
r
)
}
}
if
s
:=
r
.
URL
()
.
String
();
s
!=
"?namespace=foo"
{
t
.
Errorf
(
"namespace should be in params: %s"
,
s
)
}
r
=
(
&
Request
{
baseURL
:
&
url
.
URL
{
Path
:
"/"
,
},
})
.
Namespace
(
"foo"
)
if
s
:=
r
.
URL
()
.
String
();
s
!=
"namespaces/foo"
{
if
s
:=
r
.
URL
()
.
String
();
s
!=
"namespaces/foo"
{
t
.
Errorf
(
"namespace should be in path: %s"
,
s
)
t
.
Errorf
(
"namespace should be in path: %s"
,
s
)
}
}
...
@@ -217,7 +208,7 @@ func TestResultIntoWithErrReturnsErr(t *testing.T) {
...
@@ -217,7 +208,7 @@ func TestResultIntoWithErrReturnsErr(t *testing.T) {
func
TestURLTemplate
(
t
*
testing
.
T
)
{
func
TestURLTemplate
(
t
*
testing
.
T
)
{
uri
,
_
:=
url
.
Parse
(
"http://localhost"
)
uri
,
_
:=
url
.
Parse
(
"http://localhost"
)
r
:=
NewRequest
(
nil
,
"POST"
,
uri
,
"test"
,
nil
,
false
,
false
)
r
:=
NewRequest
(
nil
,
"POST"
,
uri
,
"test"
,
nil
)
r
.
Prefix
(
"pre1"
)
.
Resource
(
"r1"
)
.
Namespace
(
"ns"
)
.
Name
(
"nm"
)
.
Param
(
"p0"
,
"v0"
)
r
.
Prefix
(
"pre1"
)
.
Resource
(
"r1"
)
.
Namespace
(
"ns"
)
.
Name
(
"nm"
)
.
Param
(
"p0"
,
"v0"
)
full
:=
r
.
URL
()
full
:=
r
.
URL
()
if
full
.
String
()
!=
"http://localhost/pre1/namespaces/ns/r1/nm?p0=v0"
{
if
full
.
String
()
!=
"http://localhost/pre1/namespaces/ns/r1/nm?p0=v0"
{
...
@@ -278,7 +269,7 @@ func TestTransformResponse(t *testing.T) {
...
@@ -278,7 +269,7 @@ func TestTransformResponse(t *testing.T) {
{
Response
:
&
http
.
Response
{
StatusCode
:
200
,
Body
:
ioutil
.
NopCloser
(
bytes
.
NewReader
(
invalid
))},
Data
:
invalid
},
{
Response
:
&
http
.
Response
{
StatusCode
:
200
,
Body
:
ioutil
.
NopCloser
(
bytes
.
NewReader
(
invalid
))},
Data
:
invalid
},
}
}
for
i
,
test
:=
range
testCases
{
for
i
,
test
:=
range
testCases
{
r
:=
NewRequest
(
nil
,
""
,
uri
,
testapi
.
Version
(),
testapi
.
Codec
()
,
true
,
true
)
r
:=
NewRequest
(
nil
,
""
,
uri
,
testapi
.
Version
(),
testapi
.
Codec
())
if
test
.
Response
.
Body
==
nil
{
if
test
.
Response
.
Body
==
nil
{
test
.
Response
.
Body
=
ioutil
.
NopCloser
(
bytes
.
NewReader
([]
byte
{}))
test
.
Response
.
Body
=
ioutil
.
NopCloser
(
bytes
.
NewReader
([]
byte
{}))
}
}
...
@@ -638,7 +629,7 @@ func TestRequestUpgrade(t *testing.T) {
...
@@ -638,7 +629,7 @@ func TestRequestUpgrade(t *testing.T) {
Err
:
true
,
Err
:
true
,
},
},
{
{
Request
:
NewRequest
(
nil
,
""
,
uri
,
testapi
.
Version
(),
testapi
.
Codec
()
,
true
,
true
),
Request
:
NewRequest
(
nil
,
""
,
uri
,
testapi
.
Version
(),
testapi
.
Codec
()),
Config
:
&
Config
{
Config
:
&
Config
{
Username
:
"u"
,
Username
:
"u"
,
Password
:
"p"
,
Password
:
"p"
,
...
@@ -647,7 +638,7 @@ func TestRequestUpgrade(t *testing.T) {
...
@@ -647,7 +638,7 @@ func TestRequestUpgrade(t *testing.T) {
Err
:
false
,
Err
:
false
,
},
},
{
{
Request
:
NewRequest
(
nil
,
""
,
uri
,
testapi
.
Version
(),
testapi
.
Codec
()
,
true
,
true
),
Request
:
NewRequest
(
nil
,
""
,
uri
,
testapi
.
Version
(),
testapi
.
Codec
()),
Config
:
&
Config
{
Config
:
&
Config
{
BearerToken
:
"b"
,
BearerToken
:
"b"
,
},
},
...
...
pkg/client/restclient.go
View file @
3d63c71c
...
@@ -38,11 +38,6 @@ type RESTClient struct {
...
@@ -38,11 +38,6 @@ type RESTClient struct {
// A string identifying the version of the API this client is expected to use.
// A string identifying the version of the API this client is expected to use.
apiVersion
string
apiVersion
string
// LegacyBehavior controls if URLs should encode the namespace as a query param,
// and if resource case is preserved for supporting older API conventions of
// Kubernetes. Newer clients should leave this false.
LegacyBehavior
bool
// Codec is the encoding and decoding scheme that applies to a particular set of
// Codec is the encoding and decoding scheme that applies to a particular set of
// REST resources.
// REST resources.
Codec
runtime
.
Codec
Codec
runtime
.
Codec
...
@@ -59,9 +54,8 @@ type RESTClient struct {
...
@@ -59,9 +54,8 @@ type RESTClient struct {
// NewRESTClient creates a new RESTClient. This client performs generic REST functions
// NewRESTClient creates a new RESTClient. This client performs generic REST functions
// such as Get, Put, Post, and Delete on specified paths. Codec controls encoding and
// such as Get, Put, Post, and Delete on specified paths. Codec controls encoding and
// decoding of responses from the server. If this client should use the older, legacy
// decoding of responses from the server.
// API conventions from Kubernetes API v1beta1 and v1beta2, set legacyBehavior true.
func
NewRESTClient
(
baseURL
*
url
.
URL
,
apiVersion
string
,
c
runtime
.
Codec
,
maxQPS
float32
,
maxBurst
int
)
*
RESTClient
{
func
NewRESTClient
(
baseURL
*
url
.
URL
,
apiVersion
string
,
c
runtime
.
Codec
,
legacyBehavior
bool
,
maxQPS
float32
,
maxBurst
int
)
*
RESTClient
{
base
:=
*
baseURL
base
:=
*
baseURL
if
!
strings
.
HasSuffix
(
base
.
Path
,
"/"
)
{
if
!
strings
.
HasSuffix
(
base
.
Path
,
"/"
)
{
base
.
Path
+=
"/"
base
.
Path
+=
"/"
...
@@ -76,12 +70,8 @@ func NewRESTClient(baseURL *url.URL, apiVersion string, c runtime.Codec, legacyB
...
@@ -76,12 +70,8 @@ func NewRESTClient(baseURL *url.URL, apiVersion string, c runtime.Codec, legacyB
return
&
RESTClient
{
return
&
RESTClient
{
baseURL
:
&
base
,
baseURL
:
&
base
,
apiVersion
:
apiVersion
,
apiVersion
:
apiVersion
,
Codec
:
c
,
Codec
:
c
,
Throttle
:
throttle
,
LegacyBehavior
:
legacyBehavior
,
Throttle
:
throttle
,
}
}
}
}
...
@@ -101,7 +91,7 @@ func (c *RESTClient) Verb(verb string) *Request {
...
@@ -101,7 +91,7 @@ func (c *RESTClient) Verb(verb string) *Request {
if
c
.
Throttle
!=
nil
{
if
c
.
Throttle
!=
nil
{
c
.
Throttle
.
Accept
()
c
.
Throttle
.
Accept
()
}
}
return
NewRequest
(
c
.
Client
,
verb
,
c
.
baseURL
,
c
.
apiVersion
,
c
.
Codec
,
c
.
LegacyBehavior
,
c
.
LegacyBehavior
)
.
Timeout
(
c
.
Timeout
)
return
NewRequest
(
c
.
Client
,
verb
,
c
.
baseURL
,
c
.
apiVersion
,
c
.
Codec
)
.
Timeout
(
c
.
Timeout
)
}
}
// Post begins a POST request. Short for c.Verb("POST").
// Post begins a POST request. Short for c.Verb("POST").
...
...
pkg/client/restclient_test.go
View file @
3d63c71c
...
@@ -119,11 +119,9 @@ func TestDoRequestBearer(t *testing.T) {
...
@@ -119,11 +119,9 @@ func TestDoRequestBearer(t *testing.T) {
defer
testServer
.
Close
()
defer
testServer
.
Close
()
request
,
_
:=
http
.
NewRequest
(
"GET"
,
testServer
.
URL
,
nil
)
request
,
_
:=
http
.
NewRequest
(
"GET"
,
testServer
.
URL
,
nil
)
c
,
err
:=
RESTClientFor
(
&
Config
{
c
,
err
:=
RESTClientFor
(
&
Config
{
Host
:
testServer
.
URL
,
Host
:
testServer
.
URL
,
Version
:
testapi
.
Version
(),
Version
:
testapi
.
Version
(),
Codec
:
testapi
.
Codec
(),
Codec
:
testapi
.
Codec
(),
LegacyBehavior
:
true
,
BearerToken
:
"test"
,
BearerToken
:
"test"
,
})
})
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -149,11 +147,9 @@ func TestDoRequestWithoutPassword(t *testing.T) {
...
@@ -149,11 +147,9 @@ func TestDoRequestWithoutPassword(t *testing.T) {
testServer
:=
httptest
.
NewServer
(
&
fakeHandler
)
testServer
:=
httptest
.
NewServer
(
&
fakeHandler
)
defer
testServer
.
Close
()
defer
testServer
.
Close
()
c
,
err
:=
RESTClientFor
(
&
Config
{
c
,
err
:=
RESTClientFor
(
&
Config
{
Host
:
testServer
.
URL
,
Host
:
testServer
.
URL
,
Version
:
testapi
.
Version
(),
Version
:
testapi
.
Version
(),
Codec
:
testapi
.
Codec
(),
Codec
:
testapi
.
Codec
(),
LegacyBehavior
:
true
,
Username
:
"test"
,
Username
:
"test"
,
})
})
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -190,11 +186,9 @@ func TestDoRequestSuccess(t *testing.T) {
...
@@ -190,11 +186,9 @@ func TestDoRequestSuccess(t *testing.T) {
testServer
:=
httptest
.
NewServer
(
&
fakeHandler
)
testServer
:=
httptest
.
NewServer
(
&
fakeHandler
)
defer
testServer
.
Close
()
defer
testServer
.
Close
()
c
,
err
:=
RESTClientFor
(
&
Config
{
c
,
err
:=
RESTClientFor
(
&
Config
{
Host
:
testServer
.
URL
,
Host
:
testServer
.
URL
,
Version
:
testapi
.
Version
(),
Version
:
testapi
.
Version
(),
Codec
:
testapi
.
Codec
(),
Codec
:
testapi
.
Codec
(),
LegacyBehavior
:
true
,
Username
:
"user"
,
Username
:
"user"
,
Password
:
"pass"
,
Password
:
"pass"
,
})
})
...
@@ -235,10 +229,9 @@ func TestDoRequestFailed(t *testing.T) {
...
@@ -235,10 +229,9 @@ func TestDoRequestFailed(t *testing.T) {
testServer
:=
httptest
.
NewServer
(
&
fakeHandler
)
testServer
:=
httptest
.
NewServer
(
&
fakeHandler
)
defer
testServer
.
Close
()
defer
testServer
.
Close
()
c
,
err
:=
RESTClientFor
(
&
Config
{
c
,
err
:=
RESTClientFor
(
&
Config
{
Host
:
testServer
.
URL
,
Host
:
testServer
.
URL
,
Version
:
testapi
.
Version
(),
Version
:
testapi
.
Version
(),
Codec
:
testapi
.
Codec
(),
Codec
:
testapi
.
Codec
(),
LegacyBehavior
:
true
,
})
})
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
...
@@ -268,11 +261,9 @@ func TestDoRequestCreated(t *testing.T) {
...
@@ -268,11 +261,9 @@ func TestDoRequestCreated(t *testing.T) {
testServer
:=
httptest
.
NewServer
(
&
fakeHandler
)
testServer
:=
httptest
.
NewServer
(
&
fakeHandler
)
defer
testServer
.
Close
()
defer
testServer
.
Close
()
c
,
err
:=
RESTClientFor
(
&
Config
{
c
,
err
:=
RESTClientFor
(
&
Config
{
Host
:
testServer
.
URL
,
Host
:
testServer
.
URL
,
Version
:
testapi
.
Version
(),
Version
:
testapi
.
Version
(),
Codec
:
testapi
.
Codec
(),
Codec
:
testapi
.
Codec
(),
LegacyBehavior
:
true
,
Username
:
"user"
,
Username
:
"user"
,
Password
:
"pass"
,
Password
:
"pass"
,
})
})
...
...
pkg/config/config_test.go
View file @
3d63c71c
...
@@ -49,8 +49,7 @@ func getFakeClient(t *testing.T, validURLs []string) (ClientPosterFunc, *httptes
...
@@ -49,8 +49,7 @@ func getFakeClient(t *testing.T, validURLs []string) (ClientPosterFunc, *httptes
return
func
(
mapping
*
meta
.
RESTMapping
)
(
RESTClientPoster
,
error
)
{
return
func
(
mapping
*
meta
.
RESTMapping
)
(
RESTClientPoster
,
error
)
{
fakeCodec
:=
testapi
.
Codec
()
fakeCodec
:=
testapi
.
Codec
()
fakeUri
,
_
:=
url
.
Parse
(
server
.
URL
+
"/api/"
+
testapi
.
Version
())
fakeUri
,
_
:=
url
.
Parse
(
server
.
URL
+
"/api/"
+
testapi
.
Version
())
legacyBehavior
:=
api
.
PreV1Beta3
(
testapi
.
Version
())
return
client
.
NewRESTClient
(
fakeUri
,
testapi
.
Version
(),
fakeCodec
,
5
,
10
),
nil
return
client
.
NewRESTClient
(
fakeUri
,
testapi
.
Version
(),
fakeCodec
,
legacyBehavior
,
5
,
10
),
nil
},
server
},
server
}
}
...
...
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