Coder Social home page Coder Social logo

Comments (7)

tjarratt avatar tjarratt commented on May 27, 2024

I like this idea a lot, it basically takes a single function and creates the interface from it. Certainly would save one from the trouble of declaring an interface with an associated struct when they really just care about a stateless function.

Are you interested in submitting a PR for this @chendrix ?

from counterfeiter.

chendrix avatar chendrix commented on May 27, 2024

I tried looking at the codebase yesterday and I couldn't really make my way around it quickly.

I could certainly try putting in the effort, but it would probably take me more time than someone more familiar with the code.

from counterfeiter.

tjarratt avatar tjarratt commented on May 27, 2024

I just started looking into this and realized it needs some cleanup, some tests need to be backfilled, and there's certainly some care that could be applied to some of the existing abstractions.

I'm happy to work on this, just thought I'd ask :)

from counterfeiter.

tjarratt avatar tjarratt commented on May 27, 2024

Hey @chendrix -- I just implemented this and merged it into master. If you want to kick the tires on this, provide feedback, or identify anything else that would be nice to do here, I'd be really happy to hear your thoughts on it.

I basically turned your example code into a test case for the code generator in counterfeiter, and then verified it worked with a few simple throw-away specs. It should work, although I haven't tried using it exhaustively.

from counterfeiter.

chendrix avatar chendrix commented on May 27, 2024

Will check it out now, thanks Tim

from counterfeiter.

chendrix avatar chendrix commented on May 27, 2024

There's a bug.

Running the newest version created

// This file was generated by counterfeiter
package apifakes

import (
    "net/http"
    "sync"

    "github.com/cloudfoundry-incubator/diego-enabler/api"
)

type FakeRequestFactory struct {
    Stub        func(Filter, map[string]interface{}) (*http.Request, error)
    mutex       sync.RWMutex
    argsForCall []struct {
        arg1 Filter
        arg2 map[string]interface{}
    }
    returns struct {
        result1 *http.Request
        result2 error
    }
}

func (fake *FakeRequestFactory) Spy(arg1 Filter, arg2 map[string]interface{}) (*http.Request, error) {
    fake.mutex.Lock()
    fake.argsForCall = append(fake.argsForCall, struct {
        arg1 Filter
        arg2 map[string]interface{}
    }{arg1, arg2})
    fake.mutex.Unlock()
    if fake.Stub != nil {
        return fake.Stub(arg1, arg2)
    } else {
        return fake.returns.result1, fake.returns.result2
    }
}

func (fake *FakeRequestFactory) CallCount() int {
    fake.mutex.RLock()
    defer fake.mutex.RUnlock()
    return len(fake.argsForCall)
}

func (fake *FakeRequestFactory) ArgsForCall(i int) (Filter, map[string]interface{}) {
    fake.mutex.RLock()
    defer fake.mutex.RUnlock()
    return fake.argsForCall[i].arg1, fake.argsForCall[i].arg2
}

func (fake *FakeRequestFactory) Returns(result1 *http.Request, result2 error) {
    fake.Stub = nil
    fake.returns = struct {
        result1 *http.Request
        result2 error
    }{result1, result2}
}

var _ api.RequestFactory = new(FakeRequestFactory).Spy

This actually doesn't compile, because the function definitions, e.g. func (fake *FakeRequestFactory) ArgsForCall(i int) (Filter, map[string]interface{}) { are missing package qualification for types, i.e. it should be api.Filter, not just Filter, if you're not doing a dot import of the api package.

from counterfeiter.

tjarratt avatar tjarratt commented on May 27, 2024

Okay, this only happens when the type is from the same package. Weird. Thanks for the feedback Chris. Will keep working on this.

from counterfeiter.

Related Issues (20)

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.