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
a63ecc4a
Commit
a63ecc4a
authored
Oct 30, 2017
by
Antoine Pelisse
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update `truncateBody` to not truncate with high level
And add a unit-tests to verify that it works properly.
parent
6659f2a7
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
74 additions
and
0 deletions
+74
-0
BUILD
staging/src/k8s.io/client-go/rest/BUILD
+1
-0
request.go
staging/src/k8s.io/client-go/rest/request.go
+2
-0
request_test.go
staging/src/k8s.io/client-go/rest/request_test.go
+71
-0
No files found.
staging/src/k8s.io/client-go/rest/BUILD
View file @
a63ecc4a
...
@@ -19,6 +19,7 @@ go_test(
...
@@ -19,6 +19,7 @@ go_test(
importpath = "k8s.io/client-go/rest",
importpath = "k8s.io/client-go/rest",
library = ":go_default_library",
library = ":go_default_library",
deps = [
deps = [
"//vendor/github.com/golang/glog:go_default_library",
"//vendor/github.com/google/gofuzz:go_default_library",
"//vendor/github.com/google/gofuzz:go_default_library",
"//vendor/github.com/stretchr/testify/assert:go_default_library",
"//vendor/github.com/stretchr/testify/assert:go_default_library",
"//vendor/k8s.io/api/core/v1:go_default_library",
"//vendor/k8s.io/api/core/v1:go_default_library",
...
...
staging/src/k8s.io/client-go/rest/request.go
View file @
a63ecc4a
...
@@ -827,6 +827,8 @@ func (r *Request) transformResponse(resp *http.Response, req *http.Request) Resu
...
@@ -827,6 +827,8 @@ func (r *Request) transformResponse(resp *http.Response, req *http.Request) Resu
func
truncateBody
(
body
string
)
string
{
func
truncateBody
(
body
string
)
string
{
max
:=
0
max
:=
0
switch
{
switch
{
case
bool
(
glog
.
V
(
10
))
:
return
body
case
bool
(
glog
.
V
(
9
))
:
case
bool
(
glog
.
V
(
9
))
:
max
=
10240
max
=
10240
case
bool
(
glog
.
V
(
8
))
:
case
bool
(
glog
.
V
(
8
))
:
...
...
staging/src/k8s.io/client-go/rest/request_test.go
View file @
a63ecc4a
...
@@ -20,6 +20,7 @@ import (
...
@@ -20,6 +20,7 @@ import (
"bytes"
"bytes"
"context"
"context"
"errors"
"errors"
"flag"
"fmt"
"fmt"
"io"
"io"
"io/ioutil"
"io/ioutil"
...
@@ -34,6 +35,8 @@ import (
...
@@ -34,6 +35,8 @@ import (
"testing"
"testing"
"time"
"time"
"github.com/golang/glog"
"k8s.io/api/core/v1"
"k8s.io/api/core/v1"
apiequality
"k8s.io/apimachinery/pkg/api/equality"
apiequality
"k8s.io/apimachinery/pkg/api/equality"
apierrors
"k8s.io/apimachinery/pkg/api/errors"
apierrors
"k8s.io/apimachinery/pkg/api/errors"
...
@@ -1696,6 +1699,74 @@ func TestDoContext(t *testing.T) {
...
@@ -1696,6 +1699,74 @@ func TestDoContext(t *testing.T) {
}
}
}
}
func
buildString
(
length
int
)
string
{
s
:=
make
([]
byte
,
length
)
for
i
:=
range
s
{
s
[
i
]
=
'a'
}
return
string
(
s
)
}
func
TestTruncateBody
(
t
*
testing
.
T
)
{
tests
:=
[]
struct
{
body
string
want
string
level
string
}{
// Anything below 8 is completely truncated
{
body
:
"Completely truncated below 8"
,
want
:
" [truncated 28 chars]"
,
level
:
"0"
,
},
// Small strings are not truncated by high levels
{
body
:
"Small body never gets truncated"
,
want
:
"Small body never gets truncated"
,
level
:
"10"
,
},
{
body
:
"Small body never gets truncated"
,
want
:
"Small body never gets truncated"
,
level
:
"8"
,
},
// Strings are truncated to 1024 if level is less than 9.
{
body
:
buildString
(
2000
),
level
:
"8"
,
want
:
fmt
.
Sprintf
(
"%s [truncated 976 chars]"
,
buildString
(
1024
)),
},
// Strings are truncated to 10240 if level is 9.
{
body
:
buildString
(
20000
),
level
:
"9"
,
want
:
fmt
.
Sprintf
(
"%s [truncated 9760 chars]"
,
buildString
(
10240
)),
},
// Strings are not truncated if level is 10 or higher
{
body
:
buildString
(
20000
),
level
:
"10"
,
want
:
buildString
(
20000
),
},
// Strings are not truncated if level is 10 or higher
{
body
:
buildString
(
20000
),
level
:
"11"
,
want
:
buildString
(
20000
),
},
}
l
:=
flag
.
Lookup
(
"v"
)
.
Value
.
(
flag
.
Getter
)
.
Get
()
.
(
glog
.
Level
)
for
_
,
test
:=
range
tests
{
flag
.
Set
(
"v"
,
test
.
level
)
got
:=
truncateBody
(
test
.
body
)
if
got
!=
test
.
want
{
t
.
Errorf
(
"truncateBody(%v) = %v, want %v"
,
test
.
body
,
got
,
test
.
want
)
}
}
flag
.
Set
(
"v"
,
l
.
String
())
}
func
defaultResourcePathWithPrefix
(
prefix
,
resource
,
namespace
,
name
string
)
string
{
func
defaultResourcePathWithPrefix
(
prefix
,
resource
,
namespace
,
name
string
)
string
{
var
path
string
var
path
string
path
=
"/api/"
+
v1
.
SchemeGroupVersion
.
Version
path
=
"/api/"
+
v1
.
SchemeGroupVersion
.
Version
...
...
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