Initial commit

This commit is contained in:
Hayden 2022-08-29 18:30:36 -08:00
commit 29f583e936
135 changed files with 18463 additions and 0 deletions

View 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
}

View 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(),
}
}

View 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)
}

View 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)
}

View 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
}