diff --git a/sample-app/app.go b/sample-app/app.go index f0cde38..fc1d7c3 100644 --- a/sample-app/app.go +++ b/sample-app/app.go @@ -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 } diff --git a/sample-app/exec.go b/sample-app/exec.go index ce66f36..a3b5d4a 100644 --- a/sample-app/exec.go +++ b/sample-app/exec.go @@ -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 diff --git a/sample-app/pcreate b/sample-app/pcreate index 3965564..556c164 100755 --- a/sample-app/pcreate +++ b/sample-app/pcreate @@ -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 diff --git a/test/main_test.go b/test/main_test.go new file mode 100644 index 0000000..1a8287d --- /dev/null +++ b/test/main_test.go @@ -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") + } +}