mirror of
https://github.com/nbd-wtf/go-nostr.git
synced 2025-09-17 19:13:56 +02:00
using testify instead of testing.T methods. (#143)
This commit is contained in:
@@ -3,48 +3,54 @@ package nip05
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestParse(t *testing.T) {
|
||||
name, domain, _ := ParseIdentifier("saknd@yyq.com")
|
||||
if name != "saknd" || domain != "yyq.com" {
|
||||
t.Fatalf("wrong parsing")
|
||||
tests := []struct {
|
||||
input string
|
||||
expectedName string
|
||||
expectedDomain string
|
||||
expectError bool
|
||||
}{
|
||||
{"saknd@yyq.com", "saknd", "yyq.com", false},
|
||||
{"287354gkj+asbdfo8gw3rlicbsopifbcp3iougb5piseubfdikswub5ks@yyq.com", "287354gkj+asbdfo8gw3rlicbsopifbcp3iougb5piseubfdikswub5ks", "yyq.com", false},
|
||||
{"asdn.com", "_", "asdn.com", false},
|
||||
{"_@uxux.com.br", "_", "uxux.com.br", false},
|
||||
{"821yh498ig21", "", "", true},
|
||||
{"////", "", "", true},
|
||||
}
|
||||
|
||||
name, domain, _ = ParseIdentifier("287354gkj+asbdfo8gw3rlicbsopifbcp3iougb5piseubfdikswub5ks@yyq.com")
|
||||
if name != "287354gkj+asbdfo8gw3rlicbsopifbcp3iougb5piseubfdikswub5ks" || domain != "yyq.com" {
|
||||
t.Fatalf("wrong parsing")
|
||||
}
|
||||
|
||||
name, domain, _ = ParseIdentifier("asdn.com")
|
||||
if name != "_" || domain != "asdn.com" {
|
||||
t.Fatalf("wrong parsing")
|
||||
}
|
||||
|
||||
name, domain, _ = ParseIdentifier("_@uxux.com.br")
|
||||
if name != "_" || domain != "uxux.com.br" {
|
||||
t.Fatalf("wrong parsing")
|
||||
}
|
||||
|
||||
_, _, err := ParseIdentifier("821yh498ig21")
|
||||
if err == nil {
|
||||
t.Fatalf("should have errored")
|
||||
}
|
||||
|
||||
_, _, err = ParseIdentifier("////")
|
||||
if err == nil {
|
||||
t.Fatalf("should have errored")
|
||||
for _, test := range tests {
|
||||
name, domain, err := ParseIdentifier(test.input)
|
||||
if test.expectError {
|
||||
assert.Error(t, err, "expected error for input: %s", test.input)
|
||||
} else {
|
||||
assert.NoError(t, err, "not expect error for input: %s", test.input)
|
||||
assert.Equal(t, test.expectedName, name)
|
||||
assert.Equal(t, test.expectedDomain, domain)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestQuery(t *testing.T) {
|
||||
pp, err := QueryIdentifier(context.Background(), "fiatjaf.com")
|
||||
if err != nil || pp.PublicKey != "3bf0c63fcb93463407af97a5e5ee64fa883d107ef9e558472c4eb9aaaefa459d" {
|
||||
t.Fatalf("invalid query for fiatjaf.com")
|
||||
tests := []struct {
|
||||
input string
|
||||
expectedKey string
|
||||
expectError bool
|
||||
}{
|
||||
{"fiatjaf.com", "3bf0c63fcb93463407af97a5e5ee64fa883d107ef9e558472c4eb9aaaefa459d", false},
|
||||
{"htlc@fiatjaf.com", "f9dd6a762506260b38a2d3e5b464213c2e47fa3877429fe9ee60e071a31a07d7", false},
|
||||
}
|
||||
|
||||
pp, err = QueryIdentifier(context.Background(), "htlc@fiatjaf.com")
|
||||
if err != nil || pp.PublicKey != "f9dd6a762506260b38a2d3e5b464213c2e47fa3877429fe9ee60e071a31a07d7" {
|
||||
t.Fatalf("invalid query for htlc@fiatjaf.com")
|
||||
for _, test := range tests {
|
||||
pp, err := QueryIdentifier(context.Background(), test.input)
|
||||
if test.expectError {
|
||||
assert.Error(t, err, "Expected error for input: %s", test.input)
|
||||
} else {
|
||||
assert.NoError(t, err, "Did not expect error for input: %s", test.input)
|
||||
assert.Equal(t, test.expectedKey, pp.PublicKey, "For input: %s", test.input)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user