2021-02-04 02:00:31 +01:00
|
|
|
package test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
|
2021-02-10 01:00:02 +01:00
|
|
|
photoprism "github.com/kris-nova/client-go"
|
|
|
|
|
2021-02-04 02:00:31 +01:00
|
|
|
"github.com/kris-nova/logger"
|
|
|
|
|
|
|
|
sampleapp "github.com/kris-nova/client-go/sample-app"
|
|
|
|
)
|
|
|
|
|
2021-02-10 01:00:02 +01:00
|
|
|
const (
|
|
|
|
WellKnownUser = "admin"
|
|
|
|
WellKnownPass = "missy"
|
|
|
|
BadPassword = "charlie"
|
|
|
|
WellKnownPhotoID = "pqnzigq351j2fqgn" // This is a photo in the persistent sample app
|
2021-02-10 03:33:05 +01:00
|
|
|
UnknownPhotoID = "1234567890"
|
2021-02-11 22:46:28 +01:00
|
|
|
WellKnownAlbumID = "aqnzih81icziiyae"
|
|
|
|
UnknownAlbumID = "1234567890"
|
2021-02-10 01:00:02 +01:00
|
|
|
WellKnownSampleAppConnectionString = "http://localhost:8080"
|
2021-02-11 23:21:44 +01:00
|
|
|
UnknownCategory = "Furries"
|
2021-02-12 00:32:03 +01:00
|
|
|
WellKnownAlbumTitle = "TestAlbum"
|
2021-02-10 01:00:02 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
// Client is a pre-authenticated client that can be used
|
|
|
|
// internally to access the SDK
|
|
|
|
var Client *photoprism.Client
|
|
|
|
|
2021-02-04 02:00:31 +01:00
|
|
|
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()
|
2021-02-11 20:25:45 +01:00
|
|
|
if err == nil {
|
|
|
|
logger.Always("Stopping Photoprism Sample App for Unit Tests")
|
|
|
|
defer func() {
|
|
|
|
err := app.Stop()
|
|
|
|
if err != nil {
|
|
|
|
logger.Critical("Failure stopping application: %v", err)
|
|
|
|
os.Exit(100)
|
|
|
|
}
|
|
|
|
logger.Always("Success!")
|
|
|
|
os.Exit(0)
|
|
|
|
}()
|
2021-02-11 22:46:28 +01:00
|
|
|
} else {
|
2021-02-11 20:25:45 +01:00
|
|
|
logger.Always("Photoprism already running...")
|
2021-02-04 02:00:31 +01:00
|
|
|
}
|
|
|
|
|
2021-02-10 01:00:02 +01:00
|
|
|
// --- [ Client ] ---
|
|
|
|
client := photoprism.New(WellKnownSampleAppConnectionString)
|
|
|
|
err = client.Auth(photoprism.NewClientAuthLogin(WellKnownUser, WellKnownPass))
|
|
|
|
if err != nil {
|
|
|
|
logger.Critical("Error during testing auth: %v", err)
|
|
|
|
os.Exit(3)
|
|
|
|
}
|
|
|
|
Client = client
|
|
|
|
|
2021-02-04 02:00:31 +01:00
|
|
|
// --- [ Tests ] ----
|
|
|
|
exitCode := m.Run()
|
|
|
|
if exitCode != 0 {
|
|
|
|
logger.Critical("Failure!")
|
|
|
|
os.Exit(100)
|
|
|
|
}
|
|
|
|
// --- [ Tests ] ---
|
|
|
|
|
|
|
|
}
|