github.com/qri-io/qri@v0.10.1-0.20220104210721-c771715036cb/profile/profile_test.go (about) 1 package profile 2 3 import ( 4 "testing" 5 6 "github.com/qri-io/qri/config" 7 ) 8 9 func TestProfileDecode(t *testing.T) { 10 var ( 11 p = &Profile{} 12 cp = &config.ProfilePod{} 13 err error 14 ) 15 16 if err = p.Decode(cp); err == nil { 17 t.Errorf("expected missing ID to error") 18 } 19 20 cp = &config.ProfilePod{} 21 cp.ID = "QmTwtwLMKHHKCrugNxyAaZ31nhBqRUQVysT2xK911n4m6F" 22 cp.Type = "dinosaur" 23 24 if err = p.Decode(cp); err == nil { 25 t.Errorf("expected invalid type to error") 26 } 27 28 cp = &config.ProfilePod{} 29 cp.ID = "QmTwtwLMKHHKCrugNxyAaZ31nhBqRUQVysT2xK911n4m6F" 30 cp.Poster = "foo" 31 cp.Photo = "bar" 32 cp.Thumb = "baz" 33 34 if err := p.Decode(cp); err != nil { 35 t.Errorf("unexpected error: %s", err.Error()) 36 } 37 38 if p.Poster != "foo" { 39 t.Error("poster mismatch") 40 } 41 if p.Photo != "bar" { 42 t.Error("photo mismatch") 43 } 44 if p.Thumb != "baz" { 45 t.Error("thumb mismatch") 46 } 47 } 48 49 func TestProfileEncode(t *testing.T) { 50 cp := &config.ProfilePod{ 51 ID: "QmTwtwLMKHHKCrugNxyAaZ31nhBqRUQVysT2xK911n4m6F", 52 Peername: "test_profile", 53 } 54 55 pro := &Profile{} 56 if err := pro.Decode(cp); err != nil { 57 t.Error(err.Error()) 58 return 59 } 60 }