Very nice looking tests!
Signed-off-by: Kris Nóva <kris@nivenly.com>
This commit is contained in:
parent
3b41c9dd5f
commit
c1a45bf8e3
149 changed files with 1241 additions and 443 deletions
|
@ -5,11 +5,25 @@ import (
|
|||
"strings"
|
||||
"testing"
|
||||
|
||||
photoprism "github.com/kris-nova/client-go"
|
||||
|
||||
"github.com/kris-nova/logger"
|
||||
|
||||
sampleapp "github.com/kris-nova/client-go/sample-app"
|
||||
)
|
||||
|
||||
const (
|
||||
WellKnownUser = "admin"
|
||||
WellKnownPass = "missy"
|
||||
BadPassword = "charlie"
|
||||
WellKnownPhotoID = "pqnzigq351j2fqgn" // This is a photo in the persistent sample app
|
||||
WellKnownSampleAppConnectionString = "http://localhost:8080"
|
||||
)
|
||||
|
||||
// Client is a pre-authenticated client that can be used
|
||||
// internally to access the SDK
|
||||
var Client *photoprism.Client
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
logger.Level = 4
|
||||
app := sampleapp.New()
|
||||
|
@ -39,6 +53,15 @@ func TestMain(m *testing.M) {
|
|||
os.Exit(2)
|
||||
}
|
||||
|
||||
// --- [ 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
|
||||
|
||||
// --- [ Tests ] ----
|
||||
exitCode := m.Run()
|
||||
if exitCode != 0 {
|
||||
|
|
59
test/photo_test.go
Normal file
59
test/photo_test.go
Normal file
|
@ -0,0 +1,59 @@
|
|||
package test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestHappyGetPhoto(t *testing.T) {
|
||||
_, err := Client.V1().GetPhoto(WellKnownPhotoID)
|
||||
if err != nil {
|
||||
t.Errorf("expected success getting well known photo: %v", err)
|
||||
t.FailNow()
|
||||
}
|
||||
}
|
||||
|
||||
func TestSadGetPhoto(t *testing.T) {
|
||||
photo, err := Client.V1().GetPhoto("1234567890")
|
||||
if err != nil {
|
||||
t.Logf("success returning error for unknown photo: %v", err)
|
||||
return
|
||||
}
|
||||
t.Errorf("expected error for unknown photo: %s", photo.UUID)
|
||||
t.FailNow()
|
||||
}
|
||||
|
||||
func TestHappyUpdatePhoto(t *testing.T) {
|
||||
photo, err := Client.V1().GetPhoto(WellKnownPhotoID)
|
||||
if err != nil {
|
||||
t.Errorf("error getting well known photo: %v", err)
|
||||
t.FailNow()
|
||||
return
|
||||
}
|
||||
photo.PhotoDescription = fmt.Sprintf("Sample App Description: %s", time.Now().String())
|
||||
_, err = Client.V1().UpdatePhoto(photo)
|
||||
if err != nil {
|
||||
t.Errorf("error updating photo: %v", err)
|
||||
t.FailNow()
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func TestSadUpdatePhoto(t *testing.T) {
|
||||
photo, err := Client.V1().GetPhoto(WellKnownPhotoID)
|
||||
if err != nil {
|
||||
t.Errorf("error getting well known photo: %v", err)
|
||||
t.FailNow()
|
||||
return
|
||||
}
|
||||
photo.UUID = "1234567890"
|
||||
photo.PhotoDescription = fmt.Sprintf("Sample App Description: %s", time.Now().String())
|
||||
photo, err = Client.V1().UpdatePhoto(photo)
|
||||
if err != nil {
|
||||
t.Logf("expecting failure at updating photo unknown photo: %v", err)
|
||||
return
|
||||
}
|
||||
t.Errorf("expecting failure updaitng bad photo id: %s", photo.UUID)
|
||||
t.FailNow()
|
||||
}
|
|
@ -6,30 +6,22 @@ import (
|
|||
photoprism "github.com/kris-nova/client-go"
|
||||
)
|
||||
|
||||
const (
|
||||
WellKnownUser = "admin"
|
||||
WellKnownPass = "missy"
|
||||
BadPassword = "charlie"
|
||||
)
|
||||
|
||||
// TestHappyLogin should succeed with the good password "missy"
|
||||
func TestHappyLogin(t *testing.T) {
|
||||
creds := photoprism.NewClientAuthLogin(WellKnownUser, WellKnownPass)
|
||||
client := photoprism.New("localhost:8080")
|
||||
err := client.Auth(creds)
|
||||
client := photoprism.New(WellKnownSampleAppConnectionString)
|
||||
err := client.Auth(photoprism.NewClientAuthLogin(WellKnownUser, WellKnownPass))
|
||||
if err != nil {
|
||||
t.Errorf("invalid login: %v", err)
|
||||
t.Errorf("expected login: %v", err)
|
||||
t.FailNow()
|
||||
}
|
||||
}
|
||||
|
||||
// TestSadLogin should fail with the bad password "charlie"
|
||||
func TestSadLogin(t *testing.T) {
|
||||
creds := photoprism.NewClientAuthLogin(WellKnownUser, BadPassword)
|
||||
client := photoprism.New("localhost:8080")
|
||||
err := client.Auth(creds)
|
||||
client := photoprism.New(WellKnownSampleAppConnectionString)
|
||||
err := client.Auth(photoprism.NewClientAuthLogin(WellKnownUser, BadPassword))
|
||||
if err == nil {
|
||||
t.Errorf("Missing error for known bad password")
|
||||
return
|
||||
t.Errorf("expecting error for known bad password")
|
||||
t.FailNow()
|
||||
}
|
||||
t.Logf("Successful bad password auth attempt: %v", err)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue