<p>I'm trying to write a controller and I'm having a few issues writing tests. </p>

<p>I've used some code from the k8s HPA in my controller and I'm seeing something weird when using the <code>testrestmapper</code>.</p>

<p>basically when running this <a href="https://github.com/kubernetes/kubernetes/blob/c6ebd126a77e75e6f80e1cd59da6b887e783c7c4/pkg/controller/podautoscaler/horizontal_test.go#L852" rel="nofollow noreferrer">test</a> with a breakpoint <a href="https://github.com/kubernetes/kubernetes/blob/7498c14218403c9a713f9e0747f2c6794a0da9c7/pkg/controller/podautoscaler/horizontal.go#L512" rel="nofollow noreferrer">here</a> I see the mappings are returned. </p>

<p>When I do the same the mappings are not returned. </p>

<p>What magic is happening here?</p>

<p>The following test fails</p>

<pre class="lang-golang prettyprint-override"><code>package main

import (
    "github.com/stretchr/testify/assert"
    "k8s.io/apimachinery/pkg/api/meta/testrestmapper"
    "k8s.io/apimachinery/pkg/runtime/schema"
    "k8s.io/kubernetes/pkg/api/legacyscheme"
    "testing"
)

func TestT(t *testing.T) {
    mapper := testrestmapper.TestOnlyStaticRESTMapper(legacyscheme.Scheme)

    gk := schema.FromAPIVersionAndKind("apps/v1", "Deployment").GroupKind()
    mapping, err := mapper.RESTMapping(gk)

    assert.NoError(t, err)
    assert.NotNil(t, mapping)
}

</code></pre>

Mark
<p>I think this is because you are missing an import of <code>_ "k8s.io/kubernetes/pkg/apis/apps/install"</code>.</p>

<p>Without importing this path, there are no API groups or versions registered with the <code>schema</code> you are using to obtain the REST mapping.</p>

<p>By importing the path, the API group will be registered, allowing the call to <code>schema.FromAPIVersionAndKind("apps/v1", "Deployment").GroupKind()</code> to return a valid GroupKind.</p>
