Merge pull request #51130 from luxas/fake_discovery
Automatic merge from submit-queue (batch tested with PRs 51335, 51364, 51130, 48075, 50920) Add the possibility to set return values for the FakeDiscovery implementation **What this PR does / why we need it**: As an user of the fake clientset (with the fake discovery), I want to be able to set the fake server's version on demand like this for example: ```go func TestFakingServerVersion(t *testing.T) { client := fakeclientset.NewSimpleClientset() fakeDiscovery, ok := client.Discovery().(*fakediscovery.FakeDiscovery) if !ok { t.Fatalf("couldn't convert Discovery() to *FakeDiscovery") } testGitCommit := "v1.0.0" fakeDiscovery.FakedServerVersion = &version.Info{ GitCommit: testGitCommit, } sv, err := client.Discovery().ServerVersion() if err != nil { t.Fatalf("unexpected error: %v", err) } if sv.GitCommit != testGitCommit { t.Fatalf("unexpected faked discovery return value: %q", sv.GitCommit) } } ``` This PR makes that possible, in wait for a more sophisticated FakeDiscovery implementation generally. **Which issue this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close that issue when PR gets merged)*: fixes # **Special notes for your reviewer**: **Release note**: ```release-note NONE ``` @kubernetes/sig-api-machinery-pr-reviews
This commit is contained in:
@@ -69,10 +69,9 @@ func NewSimpleClientset(objects ...runtime.Object) *Clientset {
|
||||
|
||||
fakePtr := testing.Fake{}
|
||||
fakePtr.AddReactor("*", "*", testing.ObjectReaction(o))
|
||||
|
||||
fakePtr.AddWatchReactor("*", testing.DefaultWatchReactor(watch.NewFake(), nil))
|
||||
|
||||
return &Clientset{fakePtr}
|
||||
return &Clientset{fakePtr, &fakediscovery.FakeDiscovery{Fake: &fakePtr}}
|
||||
}
|
||||
|
||||
// Clientset implements clientset.Interface. Meant to be embedded into a
|
||||
@@ -80,10 +79,11 @@ func NewSimpleClientset(objects ...runtime.Object) *Clientset {
|
||||
// you want to test easier.
|
||||
type Clientset struct {
|
||||
testing.Fake
|
||||
discovery *fakediscovery.FakeDiscovery
|
||||
}
|
||||
|
||||
func (c *Clientset) Discovery() discovery.DiscoveryInterface {
|
||||
return &fakediscovery.FakeDiscovery{Fake: &c.Fake}
|
||||
return c.discovery
|
||||
}
|
||||
|
||||
var _ clientset.Interface = &Clientset{}
|
||||
|
Reference in New Issue
Block a user