| 1 |
/* |
| 2 |
Copyright 2017 The Kubernetes Authors. |
| 3 |
|
| 4 |
Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 |
you may not use this file except in compliance with the License. |
| 6 |
You may obtain a copy of the License at |
| 7 |
|
| 8 |
http://www.apache.org/licenses/LICENSE-2.0 |
| 9 |
|
| 10 |
Unless required by applicable law or agreed to in writing, software |
| 11 |
distributed under the License is distributed on an "AS IS" BASIS, |
| 12 |
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 |
See the License for the specific language governing permissions and |
| 14 |
limitations under the License. |
| 15 |
*/ |
| 16 |
|
| 17 |
package initializer |
| 18 |
|
| 19 |
import ( |
| 20 |
"net/url" |
| 21 |
"testing" |
| 22 |
|
| 23 |
"k8s.io/apiserver/pkg/admission" |
| 24 |
"k8s.io/apiserver/pkg/util/webhook" |
| 25 |
) |
| 26 |
|
| 27 |
type doNothingAdmission struct{} |
| 28 |
|
| 29 |
func (doNothingAdmission) Handles(o admission.Operation) bool { return false } |
| 30 |
|
| 31 |
type fakeServiceResolver struct{} |
| 32 |
|
| 33 |
func (f *fakeServiceResolver) ResolveEndpoint(namespace, name string, port int32) (*url.URL, error) { |
| 34 |
return nil, nil |
| 35 |
} |
| 36 |
|
| 37 |
type serviceWanter struct { |
| 38 |
doNothingAdmission |
| 39 |
got ServiceResolver |
| 40 |
} |
| 41 |
|
| 42 |
func (s *serviceWanter) SetServiceResolver(sr webhook.ServiceResolver) { s.got = sr } |
| 43 |
|
| 44 |
func TestWantsServiceResolver(t *testing.T) { |
| 45 |
sw := &serviceWanter{} |
| 46 |
fsr := &fakeServiceResolver{} |
| 47 |
i := NewPluginInitializer(nil, fsr) |
| 48 |
i.Initialize(sw) |
| 49 |
if got, ok := sw.got.(*fakeServiceResolver); !ok || got != fsr { |
| 50 |
t.Errorf("plumbing fail - %v %v#", ok, got) |
| 51 |
} |
| 52 |
} |