Skip to content
This repository was archived by the owner on Feb 21, 2024. It is now read-only.

Add tests for identifier.go #88

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
51 changes: 51 additions & 0 deletions identifier_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package gomatrix

import (
"testing"
)

func TestUserIDType(t *testing.T) {
var userID UserIdentifier
if idType := userID.Type(); idType != "m.id.user" {
t.Fatalf("TestUserIDType: expected ID type '%s', got '%s'", "m.id.user", idType)
}
}

func TestNewUserID(t *testing.T) {
userID := NewUserIdentifier("user0001")
if userID.User != "user0001" || userID.IDType != "m.id.user" {
t.Fatalf(
"TestNewUserID: invalid UserIdentifier returned, IDType: '%s' User: '%s'",
userID.IDType,
userID.User,
)
}
}

func TestThirdPartyIDType(t *testing.T) {
var tpID ThirdpartyIdentifier
if idType := tpID.Type(); idType != "m.id.thirdparty" {
t.Fatalf("TestUserIDType: expected ID type '%s', got '%s'", "m.id.user", idType)
}
}

func TestNewThirdPartyID(t *testing.T) {
tpID := NewThirdpartyIdentifier("m01", "addr01")
if tpID.Medium != "m01" || tpID.Address != "addr01" || tpID.IDType != "m.id.thirdparty" {
t.Fatalf("NewThirdpartyIdentifier: invalid ThirdPartyIdentifier returned, Medium: '%s', Address: '%s', IDType: '%s'", tpID.Medium, tpID.Address, tpID.IDType)
}
}

func TestPhoneIDType(t *testing.T) {
var phoneID PhoneIdentifier
if idType := phoneID.Type(); idType != "m.id.phone" {
t.Fatalf("TestPhoneIDType: expected ID type '%s', got '%s'", "m.id.phone", idType)
}
}

func TestNewPhoneID(t *testing.T) {
phoneID := NewPhoneIdentifier("country01", "(11)111-111")
if phoneID.Country != "country01" || phoneID.Phone != "(11)111-111" || phoneID.IDType != "m.id.phone" {
t.Fatalf("TestNewPhoneID: invalid PhoneIdentifier returned, country: '%s', phone: '%s', IDType: '%s'", phoneID.Country, phoneID.Phone, phoneID.IDType)
}
}