parent
3ccaa2ec9b
commit
de26a3acd5
|
@ -45,6 +45,33 @@ func (a *SampleApplication) Stop() error {
|
||||||
return script.Interpret()
|
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 {
|
func (a *SampleApplication) GetAuth() photoprism.ClientAuthenticator {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,6 +35,10 @@ func NewScriptFromPath(path string) (*Script, error) {
|
||||||
// NewScriptFromString is used to build an executable script from the content in string form.
|
// NewScriptFromString is used to build an executable script from the content in string form.
|
||||||
func NewScriptFromString(str string) *Script {
|
func NewScriptFromString(str string) *Script {
|
||||||
script := &Script{}
|
script := &Script{}
|
||||||
|
|
||||||
|
// "\\\n"
|
||||||
|
// ""
|
||||||
|
//str = strings.Replace(str, "\\\n", "", -1)
|
||||||
spl := strings.Split(str, "\n")
|
spl := strings.Split(str, "\n")
|
||||||
//logger.Info("Script lines: %d", len(spl))
|
//logger.Info("Script lines: %d", len(spl))
|
||||||
for _, line := range spl {
|
for _, line := range spl {
|
||||||
|
@ -47,12 +51,6 @@ func NewScriptFromString(str string) *Script {
|
||||||
// and can error at any point in the executation path.
|
// and can error at any point in the executation path.
|
||||||
func (s *Script) Interpret() error {
|
func (s *Script) Interpret() error {
|
||||||
//logger.Info("Running script...")
|
//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 {
|
for i, cmdStr := range s.commands {
|
||||||
// Exec will hang for output
|
// Exec will hang for output
|
||||||
|
|
||||||
|
|
|
@ -8,12 +8,4 @@
|
||||||
# Startup Script for the Application
|
# Startup Script for the Application
|
||||||
####################################
|
####################################
|
||||||
echo "Creating [SampleApp]"
|
echo "Creating [SampleApp]"
|
||||||
|
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
|
||||||
docker run -d \
|
|
||||||
--name photoprism \
|
|
||||||
-p 8080:2342 \
|
|
||||||
-e PHOTOPRISM_UPLOAD_NSFW="true" \
|
|
||||||
-e PHOTOPRISM_ADMIN_PASSWORD="missy" \
|
|
||||||
-v photoprism:/photoprism \
|
|
||||||
photoprism/photoprism:latest
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,68 @@
|
||||||
|
package test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/kris-nova/logger"
|
||||||
|
|
||||||
|
sampleapp "github.com/kris-nova/client-go/sample-app"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestMain(m *testing.M) {
|
||||||
|
logger.Level = 4
|
||||||
|
app := sampleapp.New()
|
||||||
|
err := app.Create()
|
||||||
|
// This System will create a new cluster
|
||||||
|
// if needed. Otherwise it will log the
|
||||||
|
// error at the INFO level.
|
||||||
|
if err != nil {
|
||||||
|
if !strings.Contains(err.Error(), "The container name \"/photoprism\" is already in use") {
|
||||||
|
logger.Critical("Unable to create app: %v", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
///logger.Debug(err.Error())
|
||||||
|
}
|
||||||
|
err = app.Start()
|
||||||
|
defer func() {
|
||||||
|
//err := app.Stop()
|
||||||
|
//if err != nil {
|
||||||
|
// logger.Critical("Failure stopping application: %v", err)
|
||||||
|
// os.Exit(100)
|
||||||
|
//}
|
||||||
|
logger.Always("Success!")
|
||||||
|
os.Exit(0)
|
||||||
|
}()
|
||||||
|
if err != nil {
|
||||||
|
logger.Critical("Unable to start app: %v", err)
|
||||||
|
os.Exit(2)
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- [ Tests ] ----
|
||||||
|
exitCode := m.Run()
|
||||||
|
if exitCode != 0 {
|
||||||
|
logger.Critical("Failure!")
|
||||||
|
os.Exit(100)
|
||||||
|
}
|
||||||
|
// --- [ Tests ] ---
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestHappyAPI(t *testing.T) {
|
||||||
|
// Code to validate the API
|
||||||
|
if true {
|
||||||
|
t.Logf("Success!\n")
|
||||||
|
} else {
|
||||||
|
t.Errorf("Failure!\n")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestSadAPI(t *testing.T) {
|
||||||
|
// Code to validate the API
|
||||||
|
if !false {
|
||||||
|
t.Logf("Success!\n")
|
||||||
|
} else {
|
||||||
|
t.Errorf("Failure!\n")
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue