mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-05 10:19:50 +00:00
duplicate iteration variable in go func
This commit is contained in:
parent
e3dde36e14
commit
c6ac8ea5f7
@ -50,28 +50,29 @@ func TestDecoder(t *testing.T) {
|
|||||||
decoder := restclientwatch.NewDecoder(streaming.NewDecoder(out, getDecoder()), getDecoder())
|
decoder := restclientwatch.NewDecoder(streaming.NewDecoder(out, getDecoder()), getDecoder())
|
||||||
expect := &v1.Pod{ObjectMeta: metav1.ObjectMeta{Name: "foo"}}
|
expect := &v1.Pod{ObjectMeta: metav1.ObjectMeta{Name: "foo"}}
|
||||||
encoder := json.NewEncoder(in)
|
encoder := json.NewEncoder(in)
|
||||||
go func(eventType interface{}) {
|
eType := eventType
|
||||||
|
go func() {
|
||||||
data, err := runtime.Encode(scheme.Codecs.LegacyCodec(v1.SchemeGroupVersion), expect)
|
data, err := runtime.Encode(scheme.Codecs.LegacyCodec(v1.SchemeGroupVersion), expect)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Unexpected error %v", err)
|
t.Fatalf("Unexpected error %v", err)
|
||||||
}
|
}
|
||||||
event := metav1.WatchEvent{
|
event := metav1.WatchEvent{
|
||||||
Type: string(eventType),
|
Type: string(eType),
|
||||||
Object: runtime.RawExtension{Raw: json.RawMessage(data)},
|
Object: runtime.RawExtension{Raw: json.RawMessage(data)},
|
||||||
}
|
}
|
||||||
if err := encoder.Encode(&event); err != nil {
|
if err := encoder.Encode(&event); err != nil {
|
||||||
t.Errorf("Unexpected error %v", err)
|
t.Errorf("Unexpected error %v", err)
|
||||||
}
|
}
|
||||||
in.Close()
|
in.Close()
|
||||||
}(eventType)
|
}()
|
||||||
|
|
||||||
done := make(chan struct{})
|
done := make(chan struct{})
|
||||||
go func(eventType interface{}) {
|
go func() {
|
||||||
action, got, err := decoder.Decode()
|
action, got, err := decoder.Decode()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Unexpected error %v", err)
|
t.Fatalf("Unexpected error %v", err)
|
||||||
}
|
}
|
||||||
if e, a := eventType, action; e != a {
|
if e, a := eType, action; e != a {
|
||||||
t.Errorf("Expected %v, got %v", e, a)
|
t.Errorf("Expected %v, got %v", e, a)
|
||||||
}
|
}
|
||||||
if e, a := expect, got; !apiequality.Semantic.DeepDerivative(e, a) {
|
if e, a := expect, got; !apiequality.Semantic.DeepDerivative(e, a) {
|
||||||
@ -79,7 +80,7 @@ func TestDecoder(t *testing.T) {
|
|||||||
}
|
}
|
||||||
t.Logf("Exited read")
|
t.Logf("Exited read")
|
||||||
close(done)
|
close(done)
|
||||||
}(eventType)
|
}()
|
||||||
<-done
|
<-done
|
||||||
|
|
||||||
done = make(chan struct{})
|
done = make(chan struct{})
|
||||||
|
Loading…
Reference in New Issue
Block a user