2014-10-09 22:21:44 +00:00
|
|
|
/*
|
2015-05-01 16:19:44 +00:00
|
|
|
Copyright 2014 The Kubernetes Authors All rights reserved.
|
2014-10-09 22:21:44 +00:00
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package event
|
|
|
|
|
|
|
|
import (
|
|
|
|
"reflect"
|
|
|
|
"testing"
|
|
|
|
|
2015-08-05 22:03:47 +00:00
|
|
|
"k8s.io/kubernetes/pkg/api"
|
|
|
|
"k8s.io/kubernetes/pkg/api/testapi"
|
|
|
|
"k8s.io/kubernetes/pkg/fields"
|
|
|
|
"k8s.io/kubernetes/pkg/labels"
|
|
|
|
"k8s.io/kubernetes/pkg/util"
|
2014-10-09 22:21:44 +00:00
|
|
|
)
|
|
|
|
|
2014-11-14 04:20:42 +00:00
|
|
|
func testEvent(name string) *api.Event {
|
|
|
|
return &api.Event{
|
|
|
|
ObjectMeta: api.ObjectMeta{
|
|
|
|
Name: name,
|
|
|
|
Namespace: "default",
|
|
|
|
},
|
|
|
|
InvolvedObject: api.ObjectReference{
|
|
|
|
Namespace: "default",
|
|
|
|
},
|
|
|
|
Reason: "forTesting",
|
2014-10-09 22:21:44 +00:00
|
|
|
}
|
2014-11-14 04:20:42 +00:00
|
|
|
}
|
|
|
|
|
2015-08-11 09:21:00 +00:00
|
|
|
func TestGetAttrs(t *testing.T) {
|
2014-10-09 22:21:44 +00:00
|
|
|
eventA := &api.Event{
|
2015-10-15 23:53:26 +00:00
|
|
|
ObjectMeta: api.ObjectMeta{
|
|
|
|
Name: "f0118",
|
|
|
|
Namespace: "default",
|
|
|
|
},
|
2014-10-09 22:21:44 +00:00
|
|
|
InvolvedObject: api.ObjectReference{
|
|
|
|
Kind: "Pod",
|
|
|
|
Name: "foo",
|
2014-11-11 01:46:40 +00:00
|
|
|
Namespace: "baz",
|
2014-10-09 22:21:44 +00:00
|
|
|
UID: "long uid string",
|
2015-09-04 07:06:01 +00:00
|
|
|
APIVersion: testapi.Default.Version(),
|
2014-10-09 22:21:44 +00:00
|
|
|
ResourceVersion: "0",
|
|
|
|
FieldPath: "",
|
|
|
|
},
|
2015-01-14 01:10:57 +00:00
|
|
|
Reason: "ForTesting",
|
|
|
|
Source: api.EventSource{Component: "test"},
|
2015-11-26 07:32:54 +00:00
|
|
|
Type: api.EventTypeNormal,
|
2014-10-09 22:21:44 +00:00
|
|
|
}
|
2015-08-11 09:21:00 +00:00
|
|
|
label, field, err := getAttrs(eventA)
|
2014-10-09 22:21:44 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Unexpected error %v", err)
|
|
|
|
}
|
|
|
|
if e, a := label, (labels.Set{}); !reflect.DeepEqual(e, a) {
|
2014-10-09 22:55:15 +00:00
|
|
|
t.Errorf("diff: %s", util.ObjectDiff(e, a))
|
2014-10-09 22:21:44 +00:00
|
|
|
}
|
2015-03-06 23:29:03 +00:00
|
|
|
expect := fields.Set{
|
2015-04-23 23:02:22 +00:00
|
|
|
"metadata.name": "f0118",
|
2015-10-15 23:53:26 +00:00
|
|
|
"metadata.namespace": "default",
|
2014-10-10 22:46:30 +00:00
|
|
|
"involvedObject.kind": "Pod",
|
|
|
|
"involvedObject.name": "foo",
|
2014-11-11 01:46:40 +00:00
|
|
|
"involvedObject.namespace": "baz",
|
2014-10-10 22:46:30 +00:00
|
|
|
"involvedObject.uid": "long uid string",
|
2015-09-04 07:06:01 +00:00
|
|
|
"involvedObject.apiVersion": testapi.Default.Version(),
|
2014-10-10 22:46:30 +00:00
|
|
|
"involvedObject.resourceVersion": "0",
|
|
|
|
"involvedObject.fieldPath": "",
|
2014-12-12 21:27:25 +00:00
|
|
|
"reason": "ForTesting",
|
2014-11-11 01:46:40 +00:00
|
|
|
"source": "test",
|
2015-11-26 07:32:54 +00:00
|
|
|
"type": api.EventTypeNormal,
|
2014-10-09 22:21:44 +00:00
|
|
|
}
|
|
|
|
if e, a := expect, field; !reflect.DeepEqual(e, a) {
|
2014-10-09 22:55:15 +00:00
|
|
|
t.Errorf("diff: %s", util.ObjectDiff(e, a))
|
2014-10-09 22:21:44 +00:00
|
|
|
}
|
|
|
|
}
|