2014-10-09 22:21:44 +00:00
|
|
|
/*
|
2016-06-03 00:25:58 +00:00
|
|
|
Copyright 2014 The Kubernetes Authors.
|
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"
|
|
|
|
|
2017-01-17 03:38:19 +00:00
|
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
2017-01-11 14:09:48 +00:00
|
|
|
"k8s.io/apimachinery/pkg/util/diff"
|
2015-08-05 22:03:47 +00:00
|
|
|
"k8s.io/kubernetes/pkg/api"
|
2015-10-29 16:34:59 +00:00
|
|
|
apitesting "k8s.io/kubernetes/pkg/api/testing"
|
2015-08-05 22:03:47 +00:00
|
|
|
"k8s.io/kubernetes/pkg/fields"
|
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{
|
2017-01-17 03:38:19 +00:00
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
2014-11-14 04:20:42 +00:00
|
|
|
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{
|
2017-01-17 03:38:19 +00:00
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
2015-10-15 23:53:26 +00:00
|
|
|
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",
|
2017-01-12 18:17:43 +00:00
|
|
|
APIVersion: api.Registry.GroupOrDie(api.GroupName).GroupVersion.String(),
|
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
|
|
|
}
|
2016-08-23 14:34:02 +00:00
|
|
|
field := EventToSelectableFields(eventA)
|
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",
|
2017-01-12 18:17:43 +00:00
|
|
|
"involvedObject.apiVersion": api.Registry.GroupOrDie(api.GroupName).GroupVersion.String(),
|
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) {
|
2016-03-11 02:43:55 +00:00
|
|
|
t.Errorf("diff: %s", diff.ObjectDiff(e, a))
|
2014-10-09 22:21:44 +00:00
|
|
|
}
|
|
|
|
}
|
2015-10-29 16:34:59 +00:00
|
|
|
|
|
|
|
func TestSelectableFieldLabelConversions(t *testing.T) {
|
2016-08-23 14:34:02 +00:00
|
|
|
fset := EventToSelectableFields(&api.Event{})
|
2015-10-29 16:34:59 +00:00
|
|
|
apitesting.TestSelectableFieldLabelConversionsOfKind(t,
|
2017-01-12 18:17:43 +00:00
|
|
|
api.Registry.GroupOrDie(api.GroupName).GroupVersion.String(),
|
2015-10-29 16:34:59 +00:00
|
|
|
"Event",
|
2016-08-12 18:50:51 +00:00
|
|
|
fset,
|
2015-10-29 16:34:59 +00:00
|
|
|
nil,
|
|
|
|
)
|
|
|
|
}
|