Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions catalog/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,10 @@ func (c *Controller) get(id string) (ThingDescription, error) {
return nil, err
}

//tr := ThingRegistration(td)
//now := time.Now()
//tr.Retrieved = &now
//td[wot.KeyThingRegistration] = tr
tr := ThingRegistration(td)
now := time.Now().UTC()
tr.Retrieved = &now
td[wot.KeyThingRegistration] = tr

return td, nil
}
Expand Down
21 changes: 10 additions & 11 deletions catalog/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"encoding/json"
"fmt"
"os"
"reflect"
"strconv"
"strings"
"testing"
Expand Down Expand Up @@ -285,16 +284,14 @@ func TestControllerListPaginate(t *testing.T) {
},
}

id, err := controller.add(td)
tdCopy := make(map[string]any)
copyMap(&td, &tdCopy)
_, err := controller.add(tdCopy)
if err != nil {
t.Fatal("Error adding a TD:", err.Error())
}
sd, err := controller.get(id)
if err != nil {
t.Fatal("Error retrieving TD:", err.Error())
}

addedTDs = append(addedTDs, sd)
addedTDs = append(addedTDs, td)
}

var list []ThingDescription
Expand Down Expand Up @@ -324,10 +321,12 @@ func TestControllerListPaginate(t *testing.T) {
}

// compare added and collection
for i, sd := range list {
if !reflect.DeepEqual(addedTDs[i], sd) {
t.Fatalf("TDs listed in catalog is different with the one stored:\n Stored:\n%v\n Listed\n%v\n",
addedTDs[i], sd)
for i, li := range list {
// remove the whole registration object because it contains system-generated and dynamic values
delete(li, "registration")
if !serializedEqual(addedTDs[i], li) {
t.Fatalf("TD added in catalog is different with the one listed:\n Added:\n%v\n Listed:\n%v\n",
addedTDs[i], li)
}
}
}
Expand Down
8 changes: 7 additions & 1 deletion catalog/main_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

package catalog

import (
"bytes"
"encoding/json"
"os"
"reflect"
Expand Down Expand Up @@ -44,6 +44,12 @@ func serializedEqual(td1 ThingDescription, td2 ThingDescription) bool {
return reflect.DeepEqual(tdBytes, storedTDBytes)
}

func copyMap(in, out interface{}) {
buf := new(bytes.Buffer)
json.NewEncoder(buf).Encode(in)
json.NewDecoder(buf).Decode(out)
}

func TestMain(m *testing.M) {
// run tests for each storage backend
for b, supported := range TestSupportedBackends {
Expand Down