<p>I am writing the simplest fxn possible using <code>client-go</code> that justs performs in-cluster authentication and returns a pointer to the <code>kubernetes.Clientset</code> object</p>
<pre class="lang-golang prettyprint-override"><code>// getInClusterAuth performs in cluster authentication and returns the clientset
func getInClusterAuth() (*kubernetes.Clientset, error) {
    // creates the in-cluster config
    config, err := rest.InClusterConfig()
    if err != nil {
        return nil, err
    }
    // create the clientset
    clientset, err := kubernetes.NewForConfig(config)
    if err != nil {
        return nil, err
    }

    return clientset, nil
}
</code></pre>
<p>Since this is sth that not only does it run against an external system (a <code>k8s</code> api server) but it is also supposed to be running from within a <code>Pod</code> once deployed, what is the appropriate way of unit-testing it?</p>
<p>Could it be that it is an acceptable practice to cover the case in e2e or integration tests?</p>

pkaramol
<p>you  can   use   k8s.io/client-go/kubernetes/fake.NewSimpleClientset   to  mock a clientSet   in your unit test .</p>
<pre><code>
import (
        &quot;context&quot;
        &quot;testing&quot;

        v1 &quot;k8s.io/api/core/v1&quot;
        &quot;k8s.io/apimachinery/pkg/api/errors&quot;
        metav1 &quot;k8s.io/apimachinery/pkg/apis/meta/v1&quot;
        &quot;k8s.io/client-go/kubernetes/fake&quot;
)

func TestHelloWorld(t *testing.T) {
        clientset := fake.NewSimpleClientset(&amp;v1.Pod{
                ObjectMeta: metav1.ObjectMeta{
                        Name:        &quot;influxdb-v2&quot;,
                        Namespace:   &quot;default&quot;,
                        Annotations: map[string]string{},
                },
        }, &amp;v1.Pod{
                ObjectMeta: metav1.ObjectMeta{
                        Name:        &quot;chronograf&quot;,
                        Namespace:   &quot;default&quot;,
                        Annotations: map[string]string{},
                },
        })

        _, err := clientset.CoreV1().Pods(v1.NamespaceDefault).Get(context.Background(), &quot;influxdb-v2&quot;, metav1.GetOptions{})
        if err != nil {
                if errors.IsNotFound(err) {
                        t.Error(err)
                } else {
                        t.Errorf(&quot;failed to get service from apiserver: %s&quot;, err)
                }
        }

        p := &amp;v1.Pod{ObjectMeta: metav1.ObjectMeta{Name: &quot;helloooooo&quot;}}
        _, err = clientset.CoreV1().Pods(v1.NamespaceDefault).Create(context.Background(), p, metav1.CreateOptions{})
        if err != nil {
            t.Fatalf(&quot;error injecting pod add: %v&quot;, err)
        }
}
</code></pre>
<p>this is a sample: <a href="https://stackoverflow.com/questions/57833499/how-to-write-simple-tests-for-client-go-using-a-fake-client">a fakeclient case</a></p>
