MCPcopy
hub / github.com/livebud/bud / TestInject

Function TestInject

framework/controller/controller_test.go:2230–2324  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

2228}
2229
2230func TestInject(t *testing.T) {
2231 is := is.New(t)
2232 ctx := context.Background()
2233 dir := t.TempDir()
2234 td := testdir.New(dir)
2235 td.Files["log/log.go"] = `
2236 package log
2237 func New() *Logger { return &Logger{} }
2238 type Logger struct {}
2239 func (l *Logger) Info(msg string) {}
2240 `
2241 td.Files["session/session.go"] = `
2242 package session
2243 import "errors"
2244 import "net/http"
2245 import "app.com/log"
2246 func New(log *log.Logger, w http.ResponseWriter, r *http.Request) *Session {
2247 return &Session{log, w, r}
2248 }
2249 type Session struct {
2250 log *log.Logger
2251 w http.ResponseWriter
2252 r *http.Request
2253 }
2254 func (s *Session) Set(key, value string) {
2255 s.log.Info("setting session")
2256 http.SetCookie(s.w, &http.Cookie{Name: key, Value: value })
2257 }
2258 func (s *Session) Clear() error {
2259 return errors.New("session: unable to clear")
2260 }
2261 `
2262 td.Files["db/db.go"] = `
2263 package db
2264 import "context"
2265 var loaded = 0
2266 func Load(ctx context.Context) (*Client, error) {
2267 loaded++
2268 return &Client{}, nil
2269 }
2270 type Client struct{}
2271 func (c *Client) Loaded() int {
2272 return loaded
2273 }
2274 `
2275 td.Files["controller/controller.go"] = `
2276 package controller
2277 import "app.com/session"
2278 import "app.com/db"
2279 type Controller struct {
2280 Session *session.Session
2281 DB *db.Client
2282 }
2283 func (c *Controller) Create() error {
2284 c.Session.Set("sessionid", "some-key")
2285 return nil
2286 }
2287 func (c *Controller) Delete() error {

Callers

nothing calls this directly

Calls 11

NewFunction · 0.92
NewFunction · 0.92
NewFunction · 0.92
NoErrMethod · 0.80
DeleteJSONMethod · 0.80
DiffMethod · 0.80
PostJSONMethod · 0.80
GetJSONMethod · 0.80
CloseMethod · 0.65
WriteMethod · 0.45
StartMethod · 0.45

Tested by

no test coverage detected