title: SImulate runtime object mock K8S
body: <p>Im using the following function which works.
  Now I need to add a unit tests to the below function and I didn't find a simple way how to mock the runtime object of k8s.</p>
  <p><strong>This is the function</strong></p>
  <pre><code>import(
  &quot;k8s.io/apimachinery/pkg/runtime&quot;
  
  )
  
  
  func GetModified(obj runtime.Object, annotate bool, codec runtime.Encoder) ([]byte, error) {
      var modified []byte
      annotates, err := metadataAccessor.Annotations(obj)
      if err != nil {
          return nil, err
      }
  
      if annotates == nil {
          annotates = map[string]string{}
      }
  
      original := annotates[corev1.LastAppliedConfigAnnotation]
      delete(annotates, corev1.LastAppliedConfigAnnotation)
      if err := metadataAccessor.SetAnnotations(obj, annotates); err != nil {
          return nil, err
      }
  
      modified, err = runtime.Encode(codec, obj)
      if err != nil {
          return nil, err
      }
  
      if annotate {
          annotates[corev1.LastAppliedConfigAnnotation] = string(modified)
          if err := metadataAccessor.SetAnnotations(obj, annotates); err != nil {
              return nil, err
          }
  
          modified, err = runtime.Encode(codec, obj)
          if err != nil {
              return nil, err
          }
      }
      annotates[corev1.LastAppliedConfigAnnotation] = original
      if err := metadataAccessor.SetAnnotations(obj, annotates); err != nil {
          return nil, err
      }
      return modified, nil
  }
  </code></pre>
  <p>I want to create a unit test to it but not sure how to simulate the runtime</p>
  <p><code>obj runtime.Object</code>
  <code>codec runtime.Encoder</code></p>
  <p>Any idea how can I <strong>mock</strong> those two values for unit testing?</p>
  <p><strong>This is the unit test</strong></p>
  <pre><code>func TestGetModified(t *testing.T) {
      
      
      
      type args struct {
          obj      runtime.Object
          annotate bool
          codec    runtime.Encoder
      }
      // HERE I NEED TO PROVIDE THE RUNTIME OBJECT
      args{
          obj:      nil,
          annotate: false,
          codec:    nil,
      }
  
      tests := []struct {
          name    string
          args    args
          want    []byte
          wantErr bool
      }{{
          name: &quot;test&quot;,
          args: ,
          want:    nil,
          wantErr: false,
      },
  
      }
      for _, tt := range tests {
          t.Run(tt.name, func(t *testing.T) {
              got, err := GetModified(tt.args.obj, tt.args.annotate, tt.args.codec)
              if (err != nil) != tt.wantErr {
                  t.Errorf(&quot;GetModified() error = %v, wantErr %v&quot;, err, tt.wantErr)
                  return
              }
              if !reflect.DeepEqual(got, tt.want) {
                  t.Errorf(&quot;GetModified() got = %v, want %v&quot;, got, tt.want)
              }
          })
      }
  }
  </code></pre>