/*
ekster - microsub server
Copyright (C) 2018 Peter Stuifzand
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see
Simple content
" itemmap["content"] = c itemmap["like-of"] = []string{ "https://p83.nl/", "https://p83.nl/test.html", } item := MapToItem(itemmap) if item.Type != "entry" { t.Errorf("Expected Type entry, was %q", item.Type) } if item.Name != "Title" { t.Errorf("Expected Name == %q, was actually %q", "Title", item.Name) } if item.Content.Text != "Simple content" { t.Errorf("Expected Content.Text == %q, was actually %q", "Simple content", item.Content.Text) } if item.Content.HTML != "Simple content
" { t.Errorf("Expected Content.HTML == %q, was actually %q", "Simple content
", item.Content.HTML) } // if val := item.LikeOf[0]; val != "https://p83.nl/" { // t.Errorf("Expected LikeOf[0] == %q, was actually %q", "https://p83.nl/", val) // } // if val := item.LikeOf[1]; val != "https://p83.nl/test.html" { // t.Errorf("Expected LikeOf[1] == %q, was actually %q", "https://p83.nl/test.html", val) // } } func TestConvertItem0(t *testing.T) { var item microsub.Item var mdItem microformats.Microformat f, err := os.Open("tests/test0.json") if err != nil { t.Fatalf("error while opening test0.json: %s", err) } json.NewDecoder(f).Decode(&mdItem) ConvertItem(&item, &mdItem) if item.Type != "entry" { t.Errorf("Expected Type entry, was %q", item.Type) } if item.Name != "name test" { t.Errorf("Expected Name == %q, was %q", "name test", item.Name) } } func TestConvertItem1(t *testing.T) { var item microsub.Item var mdItem microformats.Microformat f, err := os.Open("tests/test1.json") if err != nil { t.Fatalf("error while opening test1.json: %s", err) } json.NewDecoder(f).Decode(&mdItem) ConvertItem(&item, &mdItem) if item.Type != "entry" { t.Errorf("Expected Type entry, was %q", item.Type) } if item.Author.Type != "card" { t.Errorf("Expected Author.Type card, was %q", item.Author.Type) } if item.Author.Name != "Peter" { t.Errorf("Expected Author.Name == %q, was %q", "Peter", item.Author.Name) } } func TestConvertItem2(t *testing.T) { var item microsub.Item var mdItem microformats.Microformat f, err := os.Open("tests/test2.json") if err != nil { t.Fatalf("error while opening test2.json: %s", err) } json.NewDecoder(f).Decode(&mdItem) ConvertItem(&item, &mdItem) if item.Type != "entry" { t.Errorf("Expected Type entry, was %q", item.Type) } if item.Photo[0] != "https://peterstuifzand.nl/img/profile.jpg" { t.Errorf("Expected Photo[0], was %q", item.Type) } if item.Author.Type != "card" { t.Errorf("Expected Author.Type card, was %q", item.Author.Type) } if item.Author.Name != "Peter" { t.Errorf("Expected Author.Name == %q, was %q", "Peter", item.Author.Name) } }