Exemple #1
0
// testCloudStoreEndnodeToken checks endnode token.
func testCloudStoreEndnodeToken(t *testing.T, s cloud.Store) {
	err := s.PutEndnodeToken(common.CloudAddress{
		ServerLocation: "us", AppID: "01234567", ThingID: "ABCDEF-001"},
		common.Token{Type: "baz", Value: "555"})
	if err != nil {
		t.Fatal("PutEndnodeToken failed:", err)
	}
	v, err := s.GetEndnodeToken(common.CloudAddress{
		ServerLocation: "us", AppID: "01234567", ThingID: "ABCDEF-001"})
	if err != nil {
		t.Fatal("GetEndnodeToken failed:", err)
	} else if v.Type != "baz" || v.Value != "555" {
		t.Errorf("GetEndnodeToken returns unexpected: %#v", v)
	}
	err = s.PutEndnodeToken(common.CloudAddress{
		ServerLocation: "jp", AppID: "76543210", ThingID: "FEDCBA-002"},
		common.Token{Type: "baz", Value: "666"})
	if err != nil {
		t.Fatal("PutEndnodeToken failed:", err)
	}
	v, err = s.GetEndnodeToken(common.CloudAddress{
		ServerLocation: "jp", AppID: "76543210", ThingID: "FEDCBA-002"})
	if err != nil {
		t.Fatal("GetEndnodeToken failed:", err)
	} else if v.Type != "baz" || v.Value != "666" {
		t.Errorf("GetEndnodeToken returns unexpected: %#v", v)
	}
	v, err = s.GetEndnodeToken(common.CloudAddress{
		ServerLocation: "us", AppID: "76543210", ThingID: "FEDCBA-001"})
	if err == nil {
		t.Errorf("GetEndnodeToken returns for unknown endnode: %#v", v)
	} else if err != common.ErrTokenNotFound {
		t.Errorf("GetEndnodeToken should returns ErrTokenNotFound: %s", err)
	}
}
Exemple #2
0
func testCloudStore(t *testing.T, s cloud.Store) {
	// check master token.
	err := s.PutMasterToken(common.Token{Type: "foo", Value: "111"})
	if err != nil {
		t.Fatal("PutMasterToken failed:", err)
	}
	v, err := s.GetMasterToken()
	if err != nil {
		t.Fatal("GetMasterToken failed:", err)
	} else if v.Type != "foo" || v.Value != "111" {
		t.Errorf("GetMasterToken returns unexpected: %#v", v)
	}
	err = s.PutMasterToken(common.Token{Type: "bar", Value: "222"})
	if err != nil {
		t.Fatal("PutMasterToken (update) failed:", err)
	}
	v, err = s.GetMasterToken()
	if err != nil {
		t.Fatal("GetMasterToken (updated) failed:", err)
	} else if v.Type != "bar" || v.Value != "222" {
		t.Errorf("GetMasterToken (updated) returns unexpected: %#v", v)
	}

	// TODO: test OnboardedApp functions.

	testCloudStoreEndnodeToken(t, s)

	// TODO: test to retrieve existing OnboardedApp.
}