mirror of
https://github.com/hay-kot/homebox.git
synced 2025-07-03 17:18:36 +00:00
Initial commit
This commit is contained in:
commit
29f583e936
135 changed files with 18463 additions and 0 deletions
30
backend/internal/mocks/chimocker/chimocker.go
Normal file
30
backend/internal/mocks/chimocker/chimocker.go
Normal file
|
@ -0,0 +1,30 @@
|
|||
package chimocker
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
|
||||
"github.com/go-chi/chi/v5"
|
||||
)
|
||||
|
||||
type Params map[string]string
|
||||
|
||||
// WithUrlParam returns a pointer to a request object with the given URL params
|
||||
// added to a new chi.Context object.
|
||||
func WithUrlParam(r *http.Request, key, value string) *http.Request {
|
||||
chiCtx := chi.NewRouteContext()
|
||||
req := r.WithContext(context.WithValue(r.Context(), chi.RouteCtxKey, chiCtx))
|
||||
chiCtx.URLParams.Add(key, value)
|
||||
return req
|
||||
}
|
||||
|
||||
// WithUrlParams returns a pointer to a request object with the given URL params
|
||||
// added to a new chi.Context object. for single param assignment see WithUrlParam
|
||||
func WithUrlParams(r *http.Request, params Params) *http.Request {
|
||||
chiCtx := chi.NewRouteContext()
|
||||
req := r.WithContext(context.WithValue(r.Context(), chi.RouteCtxKey, chiCtx))
|
||||
for key, value := range params {
|
||||
chiCtx.URLParams.Add(key, value)
|
||||
}
|
||||
return req
|
||||
}
|
16
backend/internal/mocks/factories/users.go
Normal file
16
backend/internal/mocks/factories/users.go
Normal file
|
@ -0,0 +1,16 @@
|
|||
package factories
|
||||
|
||||
import (
|
||||
"github.com/hay-kot/git-web-template/backend/internal/types"
|
||||
"github.com/hay-kot/git-web-template/backend/pkgs/faker"
|
||||
)
|
||||
|
||||
func UserFactory() types.UserCreate {
|
||||
f := faker.NewFaker()
|
||||
return types.UserCreate{
|
||||
Name: f.RandomString(10),
|
||||
Email: f.RandomEmail(),
|
||||
Password: f.RandomString(10),
|
||||
IsSuperuser: f.RandomBool(),
|
||||
}
|
||||
}
|
11
backend/internal/mocks/mock_logger.go
Normal file
11
backend/internal/mocks/mock_logger.go
Normal file
|
@ -0,0 +1,11 @@
|
|||
package mocks
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"github.com/hay-kot/git-web-template/backend/pkgs/logger"
|
||||
)
|
||||
|
||||
func GetStructLogger() *logger.Logger {
|
||||
return logger.New(os.Stdout, logger.LevelDebug)
|
||||
}
|
10
backend/internal/mocks/mocker_services.go
Normal file
10
backend/internal/mocks/mocker_services.go
Normal file
|
@ -0,0 +1,10 @@
|
|||
package mocks
|
||||
|
||||
import (
|
||||
"github.com/hay-kot/git-web-template/backend/internal/repo"
|
||||
"github.com/hay-kot/git-web-template/backend/internal/services"
|
||||
)
|
||||
|
||||
func GetMockServices(repos *repo.AllRepos) *services.AllServices {
|
||||
return services.NewServices(repos)
|
||||
}
|
22
backend/internal/mocks/mocks_ent_repo.go
Normal file
22
backend/internal/mocks/mocks_ent_repo.go
Normal file
|
@ -0,0 +1,22 @@
|
|||
package mocks
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/hay-kot/git-web-template/backend/ent"
|
||||
"github.com/hay-kot/git-web-template/backend/internal/repo"
|
||||
_ "github.com/mattn/go-sqlite3"
|
||||
)
|
||||
|
||||
func GetEntRepos() (*repo.AllRepos, func() error) {
|
||||
c, err := ent.Open("sqlite3", "file:ent?mode=memory&cache=shared&_fk=1")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
if err := c.Schema.Create(context.Background()); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return repo.EntAllRepos(c), c.Close
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue