Working unit test start/stop app

Signed-off-by: Kris Nóva <kris@nivenly.com>
This commit is contained in:
Kris Nóva 2021-02-03 17:00:31 -08:00
parent 3ccaa2ec9b
commit de26a3acd5
4 changed files with 100 additions and 15 deletions

View file

@ -45,6 +45,33 @@ func (a *SampleApplication) Stop() error {
return script.Interpret()
}
func (a *SampleApplication) Create() error {
logger.Info("Create Application...")
script, err := NewScriptFromPath(filepath.Join(PrintWorkingDirectory(), CreateCommand))
if err != nil {
return err
}
return script.Interpret()
}
func (a *SampleApplication) Destroy() error {
logger.Info("Destroying Application...")
script, err := NewScriptFromPath(filepath.Join(PrintWorkingDirectory(), DestroyCommand))
if err != nil {
return err
}
return script.Interpret()
}
func (a *SampleApplication) Logs() error {
logger.Info("Logging Application...")
script, err := NewScriptFromPath(filepath.Join(PrintWorkingDirectory(), LogsCommand))
if err != nil {
return err
}
return script.Interpret()
}
func (a *SampleApplication) GetAuth() photoprism.ClientAuthenticator {
return nil
}

View file

@ -35,6 +35,10 @@ func NewScriptFromPath(path string) (*Script, error) {
// NewScriptFromString is used to build an executable script from the content in string form.
func NewScriptFromString(str string) *Script {
script := &Script{}
// "\\\n"
// ""
//str = strings.Replace(str, "\\\n", "", -1)
spl := strings.Split(str, "\n")
//logger.Info("Script lines: %d", len(spl))
for _, line := range spl {
@ -47,12 +51,6 @@ func NewScriptFromString(str string) *Script {
// and can error at any point in the executation path.
func (s *Script) Interpret() error {
//logger.Info("Running script...")
chResult := make(chan *ExecResult)
chError := make(chan error)
chBreak := make(chan bool)
defer close(chResult)
defer close(chError)
defer close(chBreak)
for i, cmdStr := range s.commands {
// Exec will hang for output

View file

@ -8,12 +8,4 @@
# Startup Script for the Application
####################################
echo "Creating [SampleApp]"
docker run -d \
--name photoprism \
-p 8080:2342 \
-e PHOTOPRISM_UPLOAD_NSFW="true" \
-e PHOTOPRISM_ADMIN_PASSWORD="missy" \
-v photoprism:/photoprism \
photoprism/photoprism:latest
docker run -d --name photoprism -p 8080:2342 -e PHOTOPRISM_UPLOAD_NSFW="true" -e PHOTOPRISM_ADMIN_PASSWORD="missy" -v "/home/nova/go/src/github.com/kris-nova/client-go/sample-app/photoprism":"/photoprism" photoprism/photoprism