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
38bf2f30
Commit
38bf2f30
authored
Oct 13, 2014
by
Daniel Smith
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix missing error type in watch decode
parent
d3491451
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
51 additions
and
47 deletions
+51
-47
decoder.go
pkg/watch/json/decoder.go
+1
-1
decoder_test.go
pkg/watch/json/decoder_test.go
+50
-46
No files found.
pkg/watch/json/decoder.go
View file @
38bf2f30
...
@@ -51,7 +51,7 @@ func (d *Decoder) Decode() (watch.EventType, runtime.Object, error) {
...
@@ -51,7 +51,7 @@ func (d *Decoder) Decode() (watch.EventType, runtime.Object, error) {
return
""
,
nil
,
err
return
""
,
nil
,
err
}
}
switch
got
.
Type
{
switch
got
.
Type
{
case
watch
.
Added
,
watch
.
Modified
,
watch
.
Deleted
:
case
watch
.
Added
,
watch
.
Modified
,
watch
.
Deleted
,
watch
.
Error
:
default
:
default
:
return
""
,
nil
,
fmt
.
Errorf
(
"got invalid watch event type: %v"
,
got
.
Type
)
return
""
,
nil
,
fmt
.
Errorf
(
"got invalid watch event type: %v"
,
got
.
Type
)
}
}
...
...
pkg/watch/json/decoder_test.go
View file @
38bf2f30
...
@@ -24,61 +24,65 @@ import (
...
@@ -24,61 +24,65 @@ import (
"time"
"time"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/
v1beta1
"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/
testapi
"
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
"github.com/GoogleCloudPlatform/kubernetes/pkg/watch"
"github.com/GoogleCloudPlatform/kubernetes/pkg/watch"
)
)
func
TestDecoder
(
t
*
testing
.
T
)
{
func
TestDecoder
(
t
*
testing
.
T
)
{
out
,
in
:=
io
.
Pipe
()
table
:=
[]
watch
.
EventType
{
watch
.
Added
,
watch
.
Deleted
,
watch
.
Modified
,
watch
.
Error
}
decoder
:=
NewDecoder
(
out
,
v1beta1
.
Codec
)
for
_
,
eventType
:=
range
table
{
expect
:=
&
api
.
Pod
{
TypeMeta
:
api
.
TypeMeta
{
ID
:
"foo"
}}
out
,
in
:=
io
.
Pipe
()
encoder
:=
json
.
NewEncoder
(
in
)
decoder
:=
NewDecoder
(
out
,
testapi
.
Codec
())
go
func
()
{
data
,
err
:=
v1beta1
.
Codec
.
Encode
(
expect
)
expect
:=
&
api
.
Pod
{
TypeMeta
:
api
.
TypeMeta
{
ID
:
"foo"
}}
if
err
!=
nil
{
encoder
:=
json
.
NewEncoder
(
in
)
t
.
Fatalf
(
"Unexpected error %v"
,
err
)
go
func
()
{
}
data
,
err
:=
testapi
.
Codec
()
.
Encode
(
expect
)
if
err
:=
encoder
.
Encode
(
&
watchEvent
{
watch
.
Added
,
runtime
.
RawExtension
{
json
.
RawMessage
(
data
)}});
err
!=
nil
{
if
err
!=
nil
{
t
.
Errorf
(
"Unexpected error %v"
,
err
)
t
.
Fatalf
(
"Unexpected error %v"
,
err
)
}
}
in
.
Close
()
if
err
:=
encoder
.
Encode
(
&
watchEvent
{
eventType
,
runtime
.
RawExtension
{
json
.
RawMessage
(
data
)}});
err
!=
nil
{
}()
t
.
Errorf
(
"Unexpected error %v"
,
err
)
}
done
:=
make
(
chan
struct
{})
in
.
Close
()
go
func
()
{
}()
action
,
got
,
err
:=
decoder
.
Decode
()
if
err
!=
nil
{
done
:=
make
(
chan
struct
{})
t
.
Fatalf
(
"Unexpected error %v"
,
err
)
go
func
()
{
}
action
,
got
,
err
:=
decoder
.
Decode
()
if
e
,
a
:=
watch
.
Added
,
action
;
e
!=
a
{
if
err
!=
nil
{
t
.
Errorf
(
"Expected %v, got %v"
,
e
,
a
)
t
.
Fatalf
(
"Unexpected error %v"
,
err
)
}
}
if
e
,
a
:=
expect
,
got
;
!
reflect
.
DeepEqual
(
e
,
a
)
{
if
e
,
a
:=
eventType
,
action
;
e
!=
a
{
t
.
Errorf
(
"Expected %v, got %v"
,
e
,
a
)
t
.
Errorf
(
"Expected %v, got %v"
,
e
,
a
)
}
}
t
.
Logf
(
"Exited read"
)
if
e
,
a
:=
expect
,
got
;
!
reflect
.
DeepEqual
(
e
,
a
)
{
close
(
done
)
t
.
Errorf
(
"Expected %v, got %v"
,
e
,
a
)
}()
}
<-
done
t
.
Logf
(
"Exited read"
)
close
(
done
)
done
=
make
(
chan
struct
{})
}()
go
func
()
{
<-
done
_
,
_
,
err
:=
decoder
.
Decode
()
if
err
==
nil
{
done
=
make
(
chan
struct
{})
t
.
Errorf
(
"Unexpected nil error"
)
go
func
()
{
}
_
,
_
,
err
:=
decoder
.
Decode
()
close
(
done
)
if
err
==
nil
{
}()
t
.
Errorf
(
"Unexpected nil error"
)
<-
done
}
close
(
done
)
decoder
.
Close
()
}()
<-
done
decoder
.
Close
()
}
}
}
func
TestDecoder_SourceClose
(
t
*
testing
.
T
)
{
func
TestDecoder_SourceClose
(
t
*
testing
.
T
)
{
out
,
in
:=
io
.
Pipe
()
out
,
in
:=
io
.
Pipe
()
decoder
:=
NewDecoder
(
out
,
v1beta1
.
Codec
)
decoder
:=
NewDecoder
(
out
,
testapi
.
Codec
()
)
done
:=
make
(
chan
struct
{})
done
:=
make
(
chan
struct
{})
...
...
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