func TestUser(t *testing.T) { u := User{} u.data.FirstName = "First" u.data.LastName = "Last" tests.CheckString(t, "First Last", u.String()) u.data.Email = "*****@*****.**" tests.CheckString(t, "First Last <*****@*****.**>", u.String()) d := u.Data() tests.CheckString(t, "*****@*****.**", d.Email) d = u.Data(data.User{Email: ""}) tests.CheckString(t, "", d.Email) tests.CheckString(t, "", d.FirstName) tests.CheckBool(t, false, u.Validate() == nil) u.data.Email = "example" tests.CheckBool(t, false, u.Validate() == nil) u.data.Email = "*****@*****.**" tests.CheckBool(t, false, u.Validate() == nil) u.data.Login = data.Login("login") tests.CheckBool(t, true, u.Validate() == nil) ejson, eerr := json.Marshal(u.data) tests.CheckBool(t, true, eerr == nil) ajson, aerr := json.Marshal(u) tests.CheckBool(t, true, aerr == nil) tests.CheckBytes(t, ejson, ajson) tests.CheckBytes(t, []byte{}, u.data.MD5API) tests.CheckString(t, "", u.data.HashType) tests.CheckBytes(t, []byte{}, u.data.Hash) u.Password("pass", []byte("secret")) h := md5.Sum([]byte(fmt.Sprintf("%s:%s", "login", "pass"))) tests.CheckBytes(t, h[:], u.data.MD5API) tests.CheckString(t, "sha1", u.data.HashType) tests.CheckBytes(t, u.generateHash("pass", []byte("secret")), u.data.Hash) }
func TestTag(t *testing.T) { tag := Tag{} tag.value = "Link" tests.CheckString(t, "Link", tag.String()) d := tag.Value() tests.CheckString(t, "Link", string(d)) d = tag.Value(data.TagValue("")) tests.CheckString(t, "", string(d)) tests.CheckBool(t, false, tag.Validate() == nil) tag.value = "tag" tests.CheckBool(t, false, tag.Validate() == nil) ejson, eerr := json.Marshal(tag.value) tests.CheckBool(t, true, eerr == nil) ajson, aerr := json.Marshal(tag) tests.CheckBool(t, true, aerr == nil) tests.CheckBytes(t, ejson, ajson) }
func TestSubscription(t *testing.T) { s := Subscription{} s.data.Link = "Link" tests.CheckString(t, "Subscription for Link", s.String()) d := s.Data() tests.CheckString(t, "Link", d.Link) d = s.Data(data.Subscription{Link: "New link"}) tests.CheckString(t, "New link", d.Link) tests.CheckBool(t, false, s.Validate() == nil) s.data.Link = "" tests.CheckBool(t, false, s.Validate() == nil) s.data.Link = "http://sugr.org" tests.CheckBool(t, false, s.Validate() == nil) s.data.FeedId = 1 tests.CheckBool(t, true, s.Validate() == nil) ejson, eerr := json.Marshal(s.data) tests.CheckBool(t, true, eerr == nil) ajson, aerr := json.Marshal(s) tests.CheckBool(t, true, aerr == nil) tests.CheckBytes(t, ejson, ajson) }
func TestArticle(t *testing.T) { a := Article{} a.data.Title = "Title" a.data.Id = data.ArticleId(1) tests.CheckString(t, "Title (1)", a.String()) d := a.Data() tests.CheckString(t, "Title", d.Title) d = a.Data(data.Article{Title: "New title", Description: "Desc"}) tests.CheckString(t, "New title", d.Title) tests.CheckString(t, "Desc", d.Description) tests.CheckBool(t, false, a.Validate() == nil) d.Link = "http://sugr.org/en/" d.FeedId = 42 a.Data(d) tests.CheckBool(t, true, a.Validate() == nil) ejson, eerr := json.Marshal(d) tests.CheckBool(t, true, eerr == nil) ajson, aerr := json.Marshal(a) tests.CheckBool(t, true, aerr == nil) tests.CheckBytes(t, ejson, ajson) }
func TestFeed(t *testing.T) { f := Feed{} f.data.Id = 1 f.data.Title = "Title" tests.CheckString(t, "Title (1)", f.String()) d := f.Data() tests.CheckString(t, "Title", d.Title) d = f.Data(data.Feed{Title: "New title", Description: "Desc"}) tests.CheckString(t, "New title", d.Title) tests.CheckString(t, "Desc", d.Description) tests.CheckBool(t, false, f.Validate() == nil) f.data.Link = "foobar" tests.CheckBool(t, false, f.Validate() == nil) f.data.Link = "http://sugr.org" tests.CheckBool(t, true, f.Validate() == nil) tests.CheckInt64(t, 0, int64(len(f.ParsedArticles()))) f.Refresh(parser.Feed{Title: "Title2", Articles: []parser.Article{parser.Article{Title: "Article title"}}}) tests.CheckString(t, "Title2", f.data.Title) tests.CheckInt64(t, 1, int64(len(f.ParsedArticles()))) tests.CheckString(t, "Article title", f.ParsedArticles()[0].Data().Title) ejson, eerr := json.Marshal(f.data) tests.CheckBool(t, true, eerr == nil) ajson, aerr := json.Marshal(f) tests.CheckBool(t, true, aerr == nil) tests.CheckBytes(t, ejson, ajson) }