Giter Club home page Giter Club logo

Comments (3)

skipor avatar skipor commented on May 28, 2024 1

Seems github.com/bouk/monkey can replace original functions and methods.

from go-forceexport.

alangpierce avatar alangpierce commented on May 28, 2024

Hmm, good question. TBH I haven't used Go in a while (this project is from two years ago), but my impression is that code like time.Now() compiles to a direct call to a function in the code segment (read-only memory), so there's no opportunity to modify its behavior. This project (accessing an arbitrary function) is an easier problem since it's more just a matter of finding the right pointer and then finding a way to call that function from Go.

If your goal is to stub out time for tests, I imagine the best approach is to make all calls through some indirection that you introduce, like your own interface/wrapper, so you can modify it for tests.

from go-forceexport.

lokhman avatar lokhman commented on May 28, 2024

@alangpierce You were right regarding read-only memory, however as @skipor mentioned, monkey patching library can hack it. Very interesting approach! I was missing getting access part for writing into memory. Thank you both for help!

from go-forceexport.

Related Issues (3)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.