Documentation
¶
Index ¶
- func AppStarted()
- func GetTestRunner() *mrunner.Runner
- func PrepareTesting(t *testing.M, config Config)
- func Ptr[T any](obj T) *T
- func Start(config Config)
- type Config
- type Factory
- func (f *Factory) IsProfileLocked(profile string) bool
- func (f *Factory) LockFile(profile string) string
- func (f *Factory) MagicDirectory() string
- func (f *Factory) PlanFile(profile string) string
- func (f *Factory) TryLockProfile(profile string) error
- func (f *Factory) Unlock() error
- func (f *Factory) WarnIfNotIgnored()
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AppStarted ¶
func AppStarted()
This function has to be called when your app successfully started.
It's used to start the test once your app is up and running in testing. The test runner does have a timeout of 10 seconds though, so if you're app takes longer than that to startup, you can modify the timeout in your Magic config.
func GetTestRunner ¶
Get the current runner active while testing.
For this to work, please make sure you call PrepareTesting in your TestMain function.
func PrepareTesting ¶
Call this function in any TestMain function if you want some tests to rely on your actual app or database.
When calling this method, Magic will automatically start your app and any required containers, just like when you normally run your app.
Please make sure to call the magic.AppStarted() function for the test runner to work properly. You can read its comments if you should still have questions about what it does. You can adjust the timeout for exiting in the Magic config.
The handler will be called once everything is ready.
Types ¶
type Config ¶
type Config struct {
// Required. This app name will be used in the container name of databases or other services we may start for you automatically. Make sure you have no other project using the same name.
AppName string
// Required. This function will be executed to plan all the containers you want to start. You may create databases and more using the context passed into this function.
PlanDeployment func(ctx *mconfig.Context)
// Required. This should start your app like normal. Expect all the database and other containers to be started at this point. Magic will make sure they're all ready by doing health checks and stuff.
StartFunction func()
// Add scripts that could be useful while developing this app.
Scripts []scripting.Script
// This is how long Magic waits for your app to finally start up before just killing any test runner. Default: 10 seconds.
//
// Hint: You can use magic.Ptr(duration) to convert your duration to a pointer, we use a pointer here to be able to detect it being not set.
TestAppTimeout *time.Duration
}
type Factory ¶
type Factory struct {
// contains filtered or unexported fields
}
func (*Factory) IsProfileLocked ¶
Check if a profile is locked (a magic instance is running)
func (*Factory) MagicDirectory ¶
Get the current magic cache directory
func (*Factory) TryLockProfile ¶
Trys to lock the lock file for the profile. If no error is returned, the profile was locked.
func (*Factory) WarnIfNotIgnored ¶
func (f *Factory) WarnIfNotIgnored()
Print a warning in case .magic is not in the current .gitignore