mock

package
v0.0.0-...-403b7d6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 1, 2024 License: AGPL-3.0 Imports: 16 Imported by: 0

Documentation

Overview

Package mock supplies various stubs and mock objects that can be used for unit testing and development deployments. nolint

nolint

Index

Constants

View Source
const (
	Recipe0Json = `` /* 448-byte string literal not displayed */
	Recipe1Json = `` /* 561-byte string literal not displayed */
	Recipe2Json = `` /* 576-byte string literal not displayed */
)
View Source
const (
	Entry1Json = `{"date":"2022-03-12T08:43:00Z","recipe":"","food":{"id":2,"amount":150}}`
	Entry2Json = `{"date":"2022-03-12T16:43:00Z","recipe":"","food":{"id":1,"amount":50}}`
	Entry3Json = `{"date":"2022-03-13T08:33:00Z","recipe":"","food":{"id":1,"amount":50}}`
)
View Source
const (
	Diary210101Json = `` /* 381-byte string literal not displayed */
	Diary210102Json = `` /* 381-byte string literal not displayed */
	Diary220301Json = `` /* 381-byte string literal not displayed */
	Diary220312Json = `` /* 493-byte string literal not displayed */
)
View Source
const (
	Instructions1 = "Cook it well."
)
View Source
const (
	List1Json = `[{"price":[0,0],"done":false,"amount":50,"aisle":0,"id":1},{"price":[0,0],"done":false,"amount":150,"aisle":0,"id":2}]`
)

Variables

View Source
var (
	Date1 = time.Date(2022, 3, 12, 8, 43, 0, 0, time.UTC)
	Date2 = time.Date(2022, 3, 12, 16, 43, 0, 0, time.UTC)
	Date3 = time.Date(2022, 3, 13, 8, 33, 0, 0, time.UTC)
	Date4 = time.Date(2022, 3, 13, 16, 33, 0, 0, time.UTC)

	Date1p2 = Date1.Add(time.Minute * 2)
	Date2p2 = Date2.Add(time.Minute * 2)

	Date1ISO = Date1.Format(time.RFC3339)
	Date2ISO = Date2.Format(time.RFC3339)

	Date1Date = Date1.Format("2006-01-02")
	Date2Date = Date2.Format("2006-01-02")
	Date3Date = Date3.Format("2006-01-02")

	Date1Time = Date1.Format("15:04")
	Date2Time = Date2.Format("15:04")

	Day1 = Date1.Truncate(time.Hour * 24)
	Day2 = Date3.Truncate(time.Hour * 24)
)
View Source
var (
	Food0 = core.Food{
		ID: 42,
	}

	// apple
	Food1 = core.Food{
		ID:       1,
		Category: 9,
		Flags:    core.FlagVegan | core.FlagVegetarian,
		KCal:     54,
		Fat:      0.1,
		Carbs:    14.4,
		Sugar:    10.3,
		Fructose: 5,
		Glucose:  3,
		Sucrose:  2.3,
		Protein:  0.3,
		Fiber:    2,

		Iron:       0.2,
		Zinc:       0.1,
		Magnesium:  5,
		Chlorine:   2.2,
		Sodium:     1,
		Calcium:    5.3,
		Potassium:  119,
		Phosphorus: 11,
		Copper:     0.1,
		Iodine:     0.008,

		VitA:  0.01,
		VitB1: 0.04,
		VitB2: 0.03,
		VitB6: 0.1,
		VitC:  12,
		VitE:  0.49,
	}

	// banana
	Food2 = core.Food{
		ID:       2,
		Category: 9,
		Flags:    core.FlagVegan | core.FlagVegetarian,
		KCal:     93,
		Fat:      0.2,
		Carbs:    20,
		Sugar:    17,
		Fructose: 10,
		Glucose:  4,
		Sucrose:  3,
		Protein:  1,
		Fiber:    2,

		Iron:       0.4,
		Zinc:       0.2,
		Magnesium:  30,
		Chlorine:   109,
		Sodium:     1,
		Calcium:    7,
		Potassium:  367,
		Phosphorus: 22,
		Copper:     0.1,
		Iodine:     0.003,
		Manganse:   0.3,

		VitA:  0.01,
		VitB1: 0.04,
		VitB2: 0.06,
		VitB6: 0.36,
		VitC:  11,
		VitE:  0.27,
	}

	Food0Json = `` /* 397-byte string literal not displayed */
	Food1Json = `` /* 441-byte string literal not displayed */
	Food2Json = `` /* 436-byte string literal not displayed */
)
View Source
var (
	User1 = app.User{
		ID:    1,
		Email: "a@a.a",
		Name:  "AnnoyingOrange",
		Pass:  "$2a$10$CpVy94BcePvhBH3QS/mMnOtFVrfN0DvwdooEUc0T8tWdKNi3ayFXC",
		Lang:  "en",
		Perm:  app.PermLogin,
	}

	User1Pass = "Tr0ub4dor&3"
	User1Json = `` /* 139-byte string literal not displayed */

	User2 = app.User{
		ID:    2,
		Email: "b@b.b",
		Name:  "BadApple",
		Pass:  "$2a$10$CpVy94BcePvhBH3QS/mMnOtFVrfN0DvwdooEUc0T8tWdKNi3ayFXC",
		Lang:  "de",
		Perm:  app.PermAdmin,
	}
)
View Source
var (
	Prefs1 = app.Prefs{
		Account: app.AccountPrefs{
			Email: User1.Email,
			Name:  User1.Name,
		},
		Macros: [7]app.MacroPrefs{
			{KCal: 2200, Fat: 60, Carbs: 270, Protein: 80},
			{KCal: 2200, Fat: 60, Carbs: 270, Protein: 80},
			{KCal: 2600, Fat: 60, Carbs: 270, Protein: 80},
			{KCal: 2200, Fat: 60, Carbs: 270, Protein: 80},
			{KCal: 2200, Fat: 60, Carbs: 270, Protein: 80},
			{KCal: 2200, Fat: 60, Carbs: 270, Protein: 80},
			{KCal: 2600, Fat: 60, Carbs: 270, Protein: 80},
		},
		RDI: app.RDIPrefs{
			Fiber:      32,
			Salt:       5.8,
			FatSat:     22,
			FatO3:      1.6,
			FatO6:      3.2,
			VitA:       0.9,
			VitB1:      1.2,
			VitB2:      1.3,
			VitB3:      16,
			VitB5:      5,
			VitB6:      1.7,
			VitB7:      0.03,
			VitB9:      0.4,
			VitB12:     0.003,
			VitC:       90,
			VitD:       0.015,
			VitE:       15,
			VitK:       0.12,
			Potassium:  3400,
			Chlorine:   2300,
			Sodium:     2300,
			Calcium:    1000,
			Phosphorus: 700,
			Magnesium:  400,
			Iron:       8,
			Zinc:       11,
			Manganse:   2.3,
			Copper:     0.9,
			Iodine:     0.15,
			Chromium:   0.035,
			Molybdenum: 0.045,
			Selenium:   0.055,
		},
	}

	StoredPrefs1 = app.StoredPrefs{
		Macros: [7]app.MacroPrefs{
			{KCal: 2200, Fat: 60, Carbs: 270, Protein: 80},
			{KCal: 2200, Fat: 60, Carbs: 270, Protein: 80},
			{KCal: 2600, Fat: 60, Carbs: 270, Protein: 80},
			{KCal: 2200, Fat: 60, Carbs: 270, Protein: 80},
			{KCal: 2200, Fat: 60, Carbs: 270, Protein: 80},
			{KCal: 2200, Fat: 60, Carbs: 270, Protein: 80},
			{KCal: 2600, Fat: 60, Carbs: 270, Protein: 80},
		},
	}

	Prefs1Json       = `` /* 797-byte string literal not displayed */
	StoredPrefs1Json = `` /* 368-byte string literal not displayed */
)
View Source
var (
	ErrDOS = errors.New("dos")
)

Error definitions

View Source
var (
	ErrFailSessionDestroy = errors.New("faildestroy")
)
View Source
var (
	ErrMarshalFail = errors.New("fail")
)

Error definitions

Functions

func Diary210101

func Diary210101() core.DiaryDay

func Diary210102

func Diary210102() core.DiaryDay

func Diary210201

func Diary210201() core.DiaryDay

func Diary210202

func Diary210202() core.DiaryDay

func Diary220301

func Diary220301() core.DiaryDay

func Diary220302

func Diary220302() core.DiaryDay

func Diary220312

func Diary220312() core.DiaryDay

func Diary220313

func Diary220313() core.DiaryDay

func Entry1

func Entry1() core.DiaryEntry

func Entry1New

func Entry1New() core.DiaryEntry

func Entry1Rec1

func Entry1Rec1() core.DiaryEntry

func Entry2

func Entry2() core.DiaryEntry

func Entry2New

func Entry2New() core.DiaryEntry

func Entry2Rec1

func Entry2Rec1() core.DiaryEntry

func Entry3

func Entry3() core.DiaryEntry

func Entry3New

func Entry3New() core.DiaryEntry

func Entry4

func Entry4() core.DiaryEntry

func Entry4New

func Entry4New() core.DiaryEntry

func List1

func List1() []core.ShopItem

func List12

func List12() []core.ShopItem

func Prefs0

func Prefs0(user app.User) app.Prefs

func Recipe0

func Recipe0() core.Recipe

Recipes need to be functions to make sure the underlying data of the Items slice is unique for every call.

func Recipe1

func Recipe1() core.Recipe

func Recipe2

func Recipe2() core.Recipe

func USDA1

func USDA1() []byte

Types

type Access

type Access struct {
	User     int
	Resource int
	Perms    int
}

type DB

type DB struct {
	User         app.User
	Prefs        app.StoredPrefs
	Tok          app.Token
	FoodItem     core.Food
	FoodItems    []core.Food
	RecipeItem   core.Recipe
	RecipeItems  []core.Recipe
	Entries      []core.DiaryEntry
	Days         []core.DiaryDay
	ShopList     []core.ShopItem
	Access       Access
	Instructions Instructions

	Err  []error
	ID   int
	Name string

	Filter core.Filter
	// contains filtered or unexported fields
}

func NewDB

func NewDB() *DB

func (*DB) DelDiaryEntries

func (db *DB) DelDiaryEntries(id int, entries ...core.DiaryEntry) error

func (*DB) DelRecipeInstructions

func (db *DB) DelRecipeInstructions(id int) error

func (*DB) DelToken

func (db *DB) DelToken(string) error

func (*DB) DelUser

func (db *DB) DelUser(id int) error

func (*DB) DiaryDays

func (db *DB) DiaryDays(id, year, month, day int) ([]core.DiaryDay, error)

func (*DB) DiaryEntries

func (db *DB) DiaryEntries(id int, date time.Time) ([]core.DiaryEntry, error)

func (*DB) Execute

func (db *DB) Execute(c app.Command) error

func (*DB) Fetch

func (db *DB) Fetch(q app.Query) error

func (*DB) Food

func (db *DB) Food(id int) (core.Food, error)

func (*DB) FoodExists

func (db *DB) FoodExists(id int) (bool, error)

func (*DB) Foods

func (db *DB) Foods(f core.Filter) ([]core.Food, error)

func (*DB) NewDiaryEntries

func (db *DB) NewDiaryEntries(id int, entries ...core.DiaryEntry) error

func (*DB) NewFood

func (db *DB) NewFood() (int, error)

func (*DB) NewRecipe

func (db *DB) NewRecipe(name string) (int, error)

func (*DB) NewToken

func (db *DB) NewToken(id int, hash string, data interface{}) error

func (*DB) NewUser

func (db *DB) NewUser(email, hash, token string) (int, error)

func (*DB) Recipe

func (db *DB) Recipe(id int) (core.Recipe, error)

func (*DB) RecipeAccess

func (db *DB) RecipeAccess(user, rec int) (int, error)

func (*DB) RecipeInstructions

func (db *DB) RecipeInstructions(id int) (string, error)

func (*DB) Recipes

func (db *DB) Recipes(uid int, f core.Filter) ([]core.Recipe, error)

func (*DB) SetDiaryEntries

func (db *DB) SetDiaryEntries(id int, entries ...core.DiaryEntry) error

func (*DB) SetFood

func (db *DB) SetFood(food core.Food) error

func (*DB) SetRecipe

func (db *DB) SetRecipe(rec core.Recipe) error

func (*DB) SetRecipeAccess

func (db *DB) SetRecipeAccess(user, rec, perms int) error

func (*DB) SetRecipeInstructions

func (db *DB) SetRecipeInstructions(id int, text string) error

func (*DB) SetShoppingListDone

func (db *DB) SetShoppingListDone(id int, done map[int]bool) error

func (*DB) SetUser

func (db *DB) SetUser(user app.User) error

func (*DB) ShoppingList

func (db *DB) ShoppingList(id int, date ...time.Time) ([]core.ShopItem, error)

func (*DB) Token

func (db *DB) Token(string) (app.Token, error)

func (*DB) UserByEmail

func (db *DB) UserByEmail(email string) (app.User, error)

func (*DB) UserByID

func (db *DB) UserByID(id int) (app.User, error)

func (*DB) UserByName

func (db *DB) UserByName(name string) (app.User, error)

func (*DB) UserNames

func (db *DB) UserNames(prefix string) ([]string, error)

func (*DB) UserPrefs

func (db *DB) UserPrefs(id int) (app.StoredPrefs, error)

func (*DB) WithAccess

func (db *DB) WithAccess(a Access) *DB

func (*DB) WithDate

func (db *DB) WithDate(date time.Time) *DB

func (*DB) WithDays

func (db *DB) WithDays(days ...core.DiaryDay) *DB

func (*DB) WithEntries

func (db *DB) WithEntries(ents ...core.DiaryEntry) *DB

func (*DB) WithError

func (db *DB) WithError(e ...error) *DB

func (*DB) WithFood

func (db *DB) WithFood(food core.Food) *DB

func (*DB) WithFoods

func (db *DB) WithFoods(foods ...core.Food) *DB

func (*DB) WithID

func (db *DB) WithID(id int) *DB

func (*DB) WithInstructions

func (db *DB) WithInstructions(id int, text string) *DB

func (*DB) WithName

func (db *DB) WithName(name string) *DB

func (*DB) WithPrefs

func (db *DB) WithPrefs(prefs app.StoredPrefs) *DB

func (*DB) WithRecipe

func (db *DB) WithRecipe(rec core.Recipe) *DB

func (*DB) WithRecipes

func (db *DB) WithRecipes(recs ...core.Recipe) *DB

func (*DB) WithShoppingList

func (db *DB) WithShoppingList(items ...core.ShopItem) *DB

func (*DB) WithToken

func (db *DB) WithToken(tok app.Token) *DB

func (*DB) WithUser

func (db *DB) WithUser(user app.User) *DB

type EmailNotifier

type EmailNotifier struct {
	Email  *email.Email
	Server string

	Err error
}

func NewEmailNotifier

func NewEmailNotifier() *EmailNotifier

func (*EmailNotifier) SendFunc

func (e *EmailNotifier) SendFunc(em *email.Email, server string, auth smtp.Auth) error

func (*EmailNotifier) WithError

func (e *EmailNotifier) WithError(err error) *EmailNotifier

type Handler

type Handler struct {
	Body string
}

func (Handler) Handle

func (h Handler) Handle() func(w http.ResponseWriter, r *http.Request, ps httprouter.Params)

func (Handler) ServeHTTP

func (h Handler) ServeHTTP(w http.ResponseWriter, r *http.Request)

type Instructions

type Instructions struct {
	Recipe       int
	Instructions string
}

type Job

type Job struct {
	Done  bool
	Delay time.Duration
}

func NewJob

func NewJob(delay time.Duration) *Job

func (*Job) Run

func (j *Job) Run()

type Log

type Log struct {
	Message string
	Warning string
	Err     string
}

func NewLog

func NewLog() *Log

func (*Log) Error

func (l *Log) Error(i interface{})

func (*Log) Log

func (l *Log) Log(i interface{})

func (*Log) Warn

func (l *Log) Warn(i interface{})

type MarshalFailer

type MarshalFailer struct{}

func (MarshalFailer) MarshalJSON

func (t MarshalFailer) MarshalJSON() ([]byte, error)

type Notifier

type Notifier struct {
	To   string
	Msg  app.Notification
	Data app.NotificationData

	Err error
}

func NewNotifier

func NewNotifier() *Notifier

func (*Notifier) Send

func (n *Notifier) Send(to string, msg app.Notification, data app.NotificationData) error

func (*Notifier) WithError

func (n *Notifier) WithError(err error) *Notifier

type SessionStore

type SessionStore struct {
	memstore.MemStore
	// contains filtered or unexported fields
}

func NewSessionStore

func NewSessionStore() *SessionStore

func (*SessionStore) DeleteCtx

func (s *SessionStore) DeleteCtx(ctx context.Context, token string) error

func (*SessionStore) WithFailDestroy

func (s *SessionStore) WithFailDestroy() *SessionStore

type Translator

type Translator struct {
	Map         map[string]interface{}
	Lang        string
	DefaultLang string
}

func NewTranslator

func NewTranslator() *Translator

func (*Translator) Default

func (t *Translator) Default() string

func (*Translator) Get

func (t *Translator) Get(lang string) map[string]interface{}

func (*Translator) Translate

func (t *Translator) Translate(input interface{}, lang string) string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL