title: How to mock standard package function for unit test
body: <p>I have three functions:</p>
  
  <pre><code>func IsSymlinks(path string) {
     ...
     ...
  }
  
  func (c *MyClass) myFunc1(path string) {
    ...more code
    ...more code
    if IsSymlinks(path) {
      realPath := filepath.EvalSymlinks(path)
    }
    ...more code
    ...more code
  }
  
  func myFunc2(path string) {
        ...more code
        ...more code
        if IsSymlinks(path) {
          realPath := filepath.EvalSymlinks(path)
        }
        ...more code
        ...more code
      }
  </code></pre>
  
  <p>How do I test myFunc1 and myFunc2 by mocking filepath.EvalSymlinks and IsSymlinks? I searched some posts and saw several solutions.</p>
  
  <ol>
  <li><p>Create a EvalSymlinks variable of function type, initialized with filepath.EvalSymlinks, and then in the test package, change it to my implementation. However, I prefer not to use this approach.</p></li>
  <li><p>Pass in filepath.EvalSymlinks and IsSymlinks into myFunc as parameter. I prefer not to use this way either.</p></li>
  <li><p>A lot of people talk about mocking use interface. Could you please help? Or another approach that could test myFunc? Thank you!</p></li>
  <li><p>Another option I am thinking is if it is a good practice to create a symlink in os to a path before I do the function test, and then delete the symlink right after testing?</p></li>
  </ol>