title: Asserting for a specific error using only standard library in golang
body: <p>Let's suppose I have a function which return <code>base64</code> encoded string for a file which is located at a specific <code>path</code>. </p>
  
  <pre><code>func getFile(path string) (string, error) {
      imgFile, err := ioutil.ReadFile(path)
      if err != nil {
          return "", fmt.Errorf("Error opening image file: %s", err)
      }
  
      base64 := base64.StdEncoding.EncodeToString(imgFile)
      return base64, nil
  }
  </code></pre>
  
  <p>Now, I'm writing table driven tests for this function and they right now look like this. </p>
  
  <pre><code>func TestGetFile(t *testing.T) {
      type getFileTest struct {
          Path   string
          Base64 string
          Err    error
      }
  
      getFileTests := []getFileTest{
          {"", "", nil},
      }
      for _, td := range getFileTests {
          base64, err := getFile(td.Path)
          if err != nil {
              t.Errorf("TestGetFile: Error calling getFile: %s", err)
          }
          if base64 != td.Base64 {
              t.Errorf("TestGetFile: Return values from getFile is not expected: Expected: %s, Returned: %s", td.Base64, base64)
          }
      }
  
  }
  </code></pre>
  
  <p>Now, current test fails with:- </p>
  
  <pre><code>test.go:18: TestGetFile: Error calling getFile: Error opening image file: open : no such file or directory
  </code></pre>
  
  <p>How do I assert that I get the right error when I pass empty path to <code>getFile</code>?</p>