adding more tests and method to receive an item's actual path identifier
This commit is contained in:
parent
56ba974dec
commit
cf354c3fa9
@ -258,6 +258,22 @@ func (c *Collection) Modified() (modified time.Time, isChanged bool, err error)
|
||||
return
|
||||
}
|
||||
|
||||
/*
|
||||
PathName returns the "real" name of a Collection.
|
||||
In some cases, the Collection.Label may not be the actual *name* of the collection
|
||||
(i.e. the label is different from the name used in the Dbus path).
|
||||
This is a thin wrapper around simply extracting the last item from
|
||||
the Collection.Dbus.Path().
|
||||
*/
|
||||
func (c *Collection) PathName() (realName string) {
|
||||
|
||||
var pathSplit []string = strings.Split(string(c.Dbus.Path()), "/")
|
||||
|
||||
realName = pathSplit[len(pathSplit)-1]
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
/*
|
||||
setModify updates the Collection's modification time (as specified by Collection.Modified).
|
||||
It seems that this does not update automatically.
|
||||
|
@ -39,52 +39,6 @@ func TestNewCollection(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
TestCollection_Label tests the following internal functions/methods via nested calls:
|
||||
(all calls in TestNewCollection)
|
||||
Service.GetCollection
|
||||
Collection.Label
|
||||
|
||||
*/
|
||||
func TestCollection_Label(t *testing.T) {
|
||||
|
||||
var svc *Service
|
||||
var collection *Collection
|
||||
var collLabel string
|
||||
var err error
|
||||
|
||||
if svc, err = NewService(); err != nil {
|
||||
t.Fatalf("NewService failed: %v", err.Error())
|
||||
}
|
||||
|
||||
if collection, err = svc.GetCollection(defaultCollectionLabel); err != nil {
|
||||
t.Errorf(
|
||||
"failed when fetching collection '%v': %v",
|
||||
defaultCollectionLabel, err.Error(),
|
||||
)
|
||||
err = nil
|
||||
if err = svc.Close(); err != nil {
|
||||
t.Errorf("could not close Service.Session: %v", err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
if collLabel, err = collection.Label(); err != nil {
|
||||
t.Errorf("cannot fetch label for '%v': %v", string(collection.Dbus.Path()), err.Error())
|
||||
if err = svc.Close(); err != nil {
|
||||
t.Fatalf("could not close Service.Session: %v", err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
if defaultCollection != collLabel {
|
||||
t.Errorf("fetched collection ('%v') does not match fetched collection label ('%v')", collLabel, defaultCollection)
|
||||
}
|
||||
|
||||
if err = svc.Close(); err != nil {
|
||||
t.Errorf("could not close Service.Session: %v", err.Error())
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
TestCollection_Items tests the following internal functions/methods via nested calls:
|
||||
|
||||
@ -156,3 +110,91 @@ func TestCollection_Items(t *testing.T) {
|
||||
t.Errorf("could not close Service.Session: %v", err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
TestCollection_Label tests the following internal functions/methods via nested calls:
|
||||
|
||||
(all calls in TestNewCollection)
|
||||
Service.GetCollection
|
||||
Collection.Label
|
||||
Collection.PathName
|
||||
|
||||
*/
|
||||
func TestCollection_Label(t *testing.T) {
|
||||
|
||||
var svc *Service
|
||||
var collection *Collection
|
||||
var collLabel string
|
||||
var err error
|
||||
|
||||
if svc, err = NewService(); err != nil {
|
||||
t.Fatalf("NewService failed: %v", err.Error())
|
||||
}
|
||||
|
||||
if collection, err = svc.GetCollection(defaultCollectionLabel); err != nil {
|
||||
t.Errorf(
|
||||
"failed when fetching collection '%v': %v",
|
||||
defaultCollectionLabel, err.Error(),
|
||||
)
|
||||
err = nil
|
||||
if err = svc.Close(); err != nil {
|
||||
t.Errorf("could not close Service.Session: %v", err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
if collLabel, err = collection.Label(); err != nil {
|
||||
t.Errorf("cannot fetch label for '%v': %v", string(collection.Dbus.Path()), err.Error())
|
||||
if err = svc.Close(); err != nil {
|
||||
t.Fatalf("could not close Service.Session: %v", err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
if defaultCollectionLabel != collLabel {
|
||||
t.Errorf("fetched collection ('%v') does not match fetched collection label ('%v')", collLabel, defaultCollectionLabel)
|
||||
}
|
||||
|
||||
if err = svc.Close(); err != nil {
|
||||
t.Errorf("could not close Service.Session: %v", err.Error())
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
TestCollection_Locked tests the following internal functions/methods via nested calls:
|
||||
|
||||
(all calls in TestNewCollection)
|
||||
Collection.Locked
|
||||
|
||||
*/
|
||||
func TestCollection_Locked(t *testing.T) {
|
||||
|
||||
var svc *Service
|
||||
var collection *Collection
|
||||
var isLocked bool
|
||||
var err error
|
||||
|
||||
if svc, err = NewService(); err != nil {
|
||||
t.Fatalf("NewService failed: %v", err.Error())
|
||||
}
|
||||
|
||||
if collection, err = svc.GetCollection(defaultCollection); err != nil {
|
||||
t.Errorf(
|
||||
"failed when fetching collection '%v': %v",
|
||||
defaultCollectionLabel, err.Error(),
|
||||
)
|
||||
err = nil
|
||||
if err = svc.Close(); err != nil {
|
||||
t.Errorf("could not close Service.Session: %v", err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
if isLocked, err = collection.Locked(); err != nil {
|
||||
t.Errorf("failed to get lock status for collection '%v': %v", collection.PathName(), err.Error())
|
||||
} else {
|
||||
t.Logf("collection '%v' lock status: %v", collection.PathName(), isLocked)
|
||||
}
|
||||
|
||||
if err = svc.Close(); err != nil {
|
||||
t.Errorf("could not close Service.Session: %v", err.Error())
|
||||
}
|
||||
}
|
||||
|
@ -85,7 +85,7 @@ func TestService_Collections(t *testing.T) {
|
||||
}
|
||||
t.Logf(
|
||||
"collection #%v (name '%v', label '%v'): created %v, last modified %v",
|
||||
idx, c.name, collLabel, created, modified,
|
||||
idx, c.PathName(), collLabel, created, modified,
|
||||
)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user