title: What do I wrong while coding GORM API Unit Test?
body: <p>A few days ago, I started learning Golang, PostgreSQL, and Unit tests.
  I searched a lot of information about how to API unit test in GORM here and there.
  I just tried to follow up Golang documentation (<a href="https://go.dev/src/net/http/httptest/example_test.go" rel="nofollow noreferrer">https://go.dev/src/net/http/httptest/example_test.go</a>) and one of the StackOverflow posts (<a href="https://codeburst.io/unit-testing-for-rest-apis-in-go-86c70dada52d" rel="nofollow noreferrer">https://codeburst.io/unit-testing-for-rest-apis-in-go-86c70dada52d</a>)</p>
  <p>I am not sure I got this error message &quot;undefined: RegisterTodoListRoutes&quot;.</p>
  <pre><code>handler := http.HandlerFunc(RegisterTodoListRoutes) in this line 
  </code></pre>
  <p>My todolist-routes.go code is</p>
  <pre><code>package routes
  
  import (
      &quot;github.com/gorilla/mux&quot;
      &quot;github.com/jiwanjeon/go-todolist/pkg/controllers&quot;
  )
  
  var RegisterTodoListRoutes = func (router *mux.Router){
      router.HandleFunc(&quot;/todo/&quot;, controllers.CreateTodo).Methods(&quot;POST&quot;)
      router.HandleFunc(&quot;/todo/&quot;, controllers.GetTodo).Methods(&quot;GET&quot;)
      router.HandleFunc(&quot;/todo/{todoId}&quot;, controllers.GetTodoById).Methods(&quot;GET&quot;)
      router.HandleFunc(&quot;/todo/{todoId}&quot;, controllers.UpdateTodo).Methods(&quot;PUT&quot;)
      router.HandleFunc(&quot;/todo/{todoId}&quot;, controllers.DeleteTodo).Methods(&quot;DELETE&quot;)
      router.HandleFunc(&quot;/complete/{todoId}&quot;, controllers.CompleteTodo).Methods(&quot;PUT&quot;)
      router.HandleFunc(&quot;/incomplete/{todoId}&quot;, controllers.InCompleteTodo).Methods(&quot;PUT&quot;)
  } 
  </code></pre>
  <p>and my todolist-routes_test.go test code is</p>
  <pre><code>package routes_test
  
  import (
      &quot;net/http/httptest&quot;
      &quot;testing&quot;
      &quot;net/http&quot;
      
  )
  
  func TestRegisterTodoListRoutes(t *testing.T) {
      req, err := http.NewRequest(&quot;GET&quot;, &quot;/todo/&quot;, nil)
      if err != nil {
          t.Fatal(err)
      }
      rr := httptest.NewRecorder()
      handler := http.HandlerFunc(RegisterTodoListRoutes)
  
          handler.ServeHTTP(rr, req)
  
    // Check the status code is what we expect.
    if status := rr.Code; status != http.StatusOK {
        t.Errorf(&quot;handler returned wrong status code: got %v want %v&quot;,
            status, http.StatusOK)
      }
      
      expected := `[{&quot;ID&quot;:46,&quot;title&quot;:&quot;test-title-console-check&quot;,&quot;last_name&quot;:&quot;test-description-console-check&quot;, &quot;conditions&quot;: true]`
      if rr.Body.String() != expected {
          t.Errorf(&quot;handler returned unexpected body: got %v want %v&quot;,
              rr.Body.String(), expected)
      }
  }
  
  </code></pre>
  <p>Here is a link for todolist_routes.go : <a href="https://go.dev/play/p/XoVMbK7PnLu" rel="nofollow noreferrer">https://go.dev/play/p/XoVMbK7PnLu</a>
  this is for test code : <a href="https://go.dev/play/p/NddwrU5m6ss" rel="nofollow noreferrer">https://go.dev/play/p/NddwrU5m6ss</a></p>
  <p>I really appreciate your help!!</p>
  <p>Edit 1] I found the reason why I got this error. When I remove _test above at package and run it. I got this error &quot;cannot convert Routes (type func(*mux.Router)) to type http.HandlerFunc&quot;</p>