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
b5583db1
Commit
b5583db1
authored
Jun 09, 2015
by
James DeFelice
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add UnversionedPath() to fix ServerAPIVersions()
parent
79bb4eda
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
62 additions
and
1 deletion
+62
-1
client.go
pkg/client/client.go
+1
-1
request.go
pkg/client/request.go
+17
-0
request_test.go
pkg/client/request_test.go
+44
-0
No files found.
pkg/client/client.go
View file @
b5583db1
...
@@ -140,7 +140,7 @@ func (c *Client) ServerVersion() (*version.Info, error) {
...
@@ -140,7 +140,7 @@ func (c *Client) ServerVersion() (*version.Info, error) {
// ServerAPIVersions retrieves and parses the list of API versions the server supports.
// ServerAPIVersions retrieves and parses the list of API versions the server supports.
func
(
c
*
Client
)
ServerAPIVersions
()
(
*
api
.
APIVersions
,
error
)
{
func
(
c
*
Client
)
ServerAPIVersions
()
(
*
api
.
APIVersions
,
error
)
{
body
,
err
:=
c
.
Get
()
.
AbsPath
(
"/api
"
)
.
Do
()
.
Raw
()
body
,
err
:=
c
.
Get
()
.
UnversionedPath
(
"
"
)
.
Do
()
.
Raw
()
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
...
...
pkg/client/request.go
View file @
b5583db1
...
@@ -210,6 +210,23 @@ func (r *Request) NamespaceIfScoped(namespace string, scoped bool) *Request {
...
@@ -210,6 +210,23 @@ func (r *Request) NamespaceIfScoped(namespace string, scoped bool) *Request {
return
r
return
r
}
}
// UnversionedPath strips the apiVersion from the baseURL before appending segments.
func
(
r
*
Request
)
UnversionedPath
(
segments
...
string
)
*
Request
{
if
r
.
err
!=
nil
{
return
r
}
upath
:=
path
.
Clean
(
r
.
baseURL
.
Path
)
//TODO(jdef) this is a pretty hackish version test
if
strings
.
HasPrefix
(
path
.
Base
(
upath
),
"v"
)
{
upath
=
path
.
Dir
(
upath
)
if
upath
==
"."
{
upath
=
"/"
}
}
r
.
path
=
path
.
Join
(
append
([]
string
{
upath
},
segments
...
)
...
)
return
r
}
// AbsPath overwrites an existing path with the segments provided. Trailing slashes are preserved
// AbsPath overwrites an existing path with the segments provided. Trailing slashes are preserved
// when a single segment is passed.
// when a single segment is passed.
func
(
r
*
Request
)
AbsPath
(
segments
...
string
)
*
Request
{
func
(
r
*
Request
)
AbsPath
(
segments
...
string
)
*
Request
{
...
...
pkg/client/request_test.go
View file @
b5583db1
...
@@ -1005,6 +1005,50 @@ func TestVerbs(t *testing.T) {
...
@@ -1005,6 +1005,50 @@ func TestVerbs(t *testing.T) {
}
}
}
}
func
TestUnversionedPath
(
t
*
testing
.
T
)
{
tt
:=
[]
struct
{
host
string
prefix
string
unversioned
string
expectedPath
string
}{
{
""
,
""
,
""
,
"/api"
},
{
""
,
""
,
"versions"
,
"/api/versions"
},
{
""
,
"/"
,
""
,
"/"
},
{
""
,
"/versions"
,
""
,
"/versions"
},
{
""
,
"/api"
,
""
,
"/api"
},
{
""
,
"/api/vfake"
,
""
,
"/api/vfake"
},
{
""
,
"/api/vfake"
,
"v1beta100"
,
"/api/vfake/v1beta100"
},
{
""
,
"/api"
,
"/versions"
,
"/api/versions"
},
{
""
,
"/api"
,
"versions"
,
"/api/versions"
},
{
""
,
"/a/api"
,
""
,
"/a/api"
},
{
""
,
"/a/api"
,
"/versions"
,
"/a/api/versions"
},
{
""
,
"/a/api"
,
"/versions/d/e"
,
"/a/api/versions/d/e"
},
{
""
,
"/a/api/vfake"
,
"/versions/d/e"
,
"/a/api/vfake/versions/d/e"
},
}
for
i
,
tc
:=
range
tt
{
c
:=
NewOrDie
(
&
Config
{
Host
:
tc
.
host
,
Prefix
:
tc
.
prefix
})
r
:=
c
.
Post
()
.
Prefix
(
"/alpha"
)
.
UnversionedPath
(
tc
.
unversioned
)
if
r
.
path
!=
tc
.
expectedPath
{
t
.
Errorf
(
"test case %d failed: unexpected path: %s, expected %s"
,
i
+
1
,
r
.
path
,
tc
.
expectedPath
)
}
}
for
i
,
tc
:=
range
tt
{
c
:=
NewOrDie
(
&
Config
{
Host
:
tc
.
host
,
Prefix
:
tc
.
prefix
,
Version
:
"v1"
})
r
:=
c
.
Post
()
.
Prefix
(
"/alpha"
)
.
UnversionedPath
(
tc
.
unversioned
)
if
r
.
path
!=
tc
.
expectedPath
{
t
.
Errorf
(
"test case %d failed: unexpected path: %s, expected %s"
,
i
+
1
,
r
.
path
,
tc
.
expectedPath
)
}
}
for
i
,
tc
:=
range
tt
{
c
:=
NewOrDie
(
&
Config
{
Host
:
tc
.
host
,
Prefix
:
tc
.
prefix
,
Version
:
"v1beta3"
})
r
:=
c
.
Post
()
.
Prefix
(
"/alpha"
)
.
UnversionedPath
(
tc
.
unversioned
)
if
r
.
path
!=
tc
.
expectedPath
{
t
.
Errorf
(
"test case %d failed: unexpected path: %s, expected %s"
,
i
+
1
,
r
.
path
,
tc
.
expectedPath
)
}
}
}
func
TestAbsPath
(
t
*
testing
.
T
)
{
func
TestAbsPath
(
t
*
testing
.
T
)
{
expectedPath
:=
"/bar/foo"
expectedPath
:=
"/bar/foo"
c
:=
NewOrDie
(
&
Config
{})
c
:=
NewOrDie
(
&
Config
{})
...
...
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