init from gitlab

This commit is contained in:
texm
2023-04-25 14:33:14 +08:00
parent 6a85a41ff0
commit c8202a5c82
281 changed files with 19861 additions and 1 deletions

41
internal/env/env.go vendored Normal file
View File

@@ -0,0 +1,41 @@
package env
import (
"github.com/labstack/echo/v4"
"github.com/texm/dokku-go"
"gitlab.com/texm/shokku/internal/server/auth"
"gorm.io/gorm"
)
const Version = "0.0.1"
type Env struct {
Version string
Router *echo.Echo
Dokku *dokku.SSHClient
DB *gorm.DB
Auth auth.Authenticator
DebugMode bool
SetupCompleted bool
}
func New(debugMode bool) *Env {
return &Env{
DebugMode: debugMode,
Version: Version,
}
}
type handlerFunc func(env *Env, c echo.Context) error
func (e *Env) H(f handlerFunc) echo.HandlerFunc {
return func(c echo.Context) error { return f(e, c) }
}
func (e *Env) Shutdown() error {
if err := e.Dokku.Close(); err != nil {
return err
}
return nil
}

42
internal/env/mock.go vendored Normal file
View File

@@ -0,0 +1,42 @@
package env
import (
"github.com/glebarez/sqlite"
"github.com/labstack/echo/v4"
"github.com/texm/dokku-go"
"gitlab.com/texm/shokku/internal/server/dto"
"gorm.io/gorm"
)
func NewTestingEnvironment() *Env {
router := echo.New()
router.Validator = dto.NewRequestValidator()
db, err := gorm.Open(sqlite.Open(":memory:"), &gorm.Config{})
if err != nil {
panic(err.Error())
}
dokkuClient := &mockDokkuClient{}
return &Env{
Router: router,
DB: db,
DebugMode: true,
Dokku: &dokkuClient.SSHClient,
}
}
type mockDokkuClient struct {
dokku.SSHClient
returnVal string
}
func (mc *mockDokkuClient) Exec(cmd string) (string, error) {
return cmd, nil
}
func (mc *mockDokkuClient) SetReturnValue(val string) {
mc.returnVal = val
}