2 // Copyright (C) 2019-2019 Marcus Rohrmoser, https://code.mro.name/mro/Shaarli-API-test
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
26 "github.com/stretchr/testify/assert"
30 func TestURL(t
*testing
.T
) {
33 assert
.Equal(t
, "a/b", path
.Join("a", "b", "/"), "ach")
35 u
, _
:= url
.Parse("https://l.mro.name/pinboard.cgi/v1/info")
36 assert
.Equal(t
, "https://l.mro.name/pinboard.cgi/v1/info", u
.String(), "ach")
39 assert
.Equal(t
, "https://l.mro.name/pinboard.cgi/v1/info", base
.String(), "ach")
41 path_info
:= "/v1/info"
42 base
.Path
= base
.Path
[0:len(base
.Path
)-len(path_info
)] + "/../index.php"
43 assert
.Equal(t
, "https://l.mro.name/pinboard.cgi/../index.php", base
.String(), "ach")
47 base
.RawQuery
= v
.Encode()
48 assert
.Equal(t
, "https://l.mro.name/pinboard.cgi/../index.php?post=uhu", base
.String(), "ach")
51 func TestFormValuesFromHtml(t
*testing
.T
) {
52 file
, err
:= os
.Open("testdata/v0.10.2/login.html") // curl --location --output testdata/login.html 'https://demo.shaarli.org/?post=https://demo.mro.name/shaarligo'
53 assert
.Nil(t
, err
, "soso")
54 ips
, _
:= formValuesFromReader(file
, "loginform")
55 assert
.Equal(t
, 40, len(ips
["token"][0]), "form.token")
56 // assert.Equal(t, "", ips["returnurl"][0], "form.returnurl")
57 assert
.Equal(t
, "Login", ips
[""][0], "form.")
58 assert
.Equal(t
, "", ips
["login"][0], "form.login")
59 assert
.Equal(t
, "", ips
["password"][0], "form.password")
60 assert
.Equal(t
, "", ips
["longlastingsession"][0], "form.longlastingsession")
63 file
, err
= os
.Open("testdata/sebsauvage/login.html") // curl --location --output testdata/login.html 'https://demo.shaarli.org/?post=https://demo.mro.name/shaarligo'
64 assert
.Nil(t
, err
, "soso")
65 ips
, _
= formValuesFromReader(file
, "loginform")
66 assert
.Equal(t
, 40, len(ips
["token"][0]), "form.token")
67 // assert.Equal(t, "", ips["returnurl"][0], "form.returnurl")
68 assert
.Equal(t
, "Login", ips
[""][0], "form.")
69 assert
.Equal(t
, "", ips
["login"][0], "form.login")
70 assert
.Equal(t
, "", ips
["password"][0], "form.password")
71 assert
.Equal(t
, "", ips
["longlastingsession"][0], "form.longlastingsession")
74 file
, err
= os
.Open("testdata/bookmark/login.html") // curl --location --output testdata/login.html 'https://demo.shaarli.org/?post=https://demo.mro.name/shaarligo'
75 assert
.Nil(t
, err
, "soso")
76 ips
, _
= formValuesFromReader(file
, "loginform")
77 assert
.Equal(t
, 40, len(ips
["token"][0]), "form.token")
78 // assert.Equal(t, "", ips["returnurl"][0], "form.returnurl")
79 assert
.Equal(t
, "Login", ips
[""][0], "form.")
80 assert
.Equal(t
, "", ips
["login"][0], "form.login")
81 assert
.Equal(t
, "", ips
["password"][0], "form.password")
82 assert
.Equal(t
, "", ips
["longlastingsession"][0], "form.longlastingsession")
85 file
, err
= os
.Open("testdata/shaarligo/linkform.html") // curl --location --output testdata/login.html 'https://demo.shaarli.org/?post=https://demo.mro.name/shaarligo'
86 assert
.Nil(t
, err
, "soso")
87 ips
, _
= formValuesFromReader(file
, "linkform")
88 assert
.Equal(t
, 40, len(ips
["token"][0]), "form.token")
89 assert
.Equal(t
, "", ips
["returnurl"][0], "form.returnurl")
90 assert
.Equal(t
, "20190106_172531", ips
["lf_linkdate"][0], "form.lf_linkdate")
91 // tim, _ := time.ParseInLocation("20060102_150405", "20190106_172531", time.Now().Location())
92 // assert.Equal(t, int64(1546791931), tim.Unix(), "form.lf_linkdate")
93 // assert.Equal(t, time.Unix(1546791931, 0), tim, "form.lf_linkdate")
94 assert
.Equal(t
, "", ips
["lf_url"][0], "form.lf_url")
95 assert
.Equal(t
, "uhu", ips
["lf_title"][0], "form.lf_title")
96 assert
.Equal(t
, "content", ips
["lf_description"][0], "form.lf_description")
97 assert
.Equal(t
, "", ips
["lf_tags"][0], "form.lf_tags")
98 assert
.Equal(t
, "Save", ips
["save_edit"][0], "form.save_edit")
102 <?xml version="1.0" encoding="UTF-8"?>
103 <?xml-stylesheet type='text/xsl' href='./assets/default/de/do-post.xslt'?>
105 must be compatible with https://code.mro.name/mro/Shaarli-API-test/src/master/tests/test-post.sh
106 https://code.mro.name/mro/ShaarliOS/src/1d124e012933d1209d64071a90237dc5ec6372fc/ios/ShaarliOS/API/ShaarliCmd.m#L386
108 <html xmlns="http://www.w3.org/1999/xhtml" xml:base="https://l.mro.name/">
109 <head><title>{ 🔗 🐳 🚀 💫 }</title></head>
111 <ul id="taglist" style="display:none"></ul>
112 <form method="post" name="linkform">
113 <input name="lf_linkdate" type="hidden" value="20190106_172531"/>
114 <input name="lf_url" type="text" value=""/>
115 <input name="lf_title" type="text" value="uhu"/>
116 <textarea name="lf_description" rows="4" cols="25"></textarea>
117 <input name="lf_tags" type="text" data-multiple="data-multiple" value=""/>
118 <input name="lf_private" type="checkbox" value=""/>
119 <input name="save_edit" type="submit" value="Save"/>
120 <input name="cancel_edit" type="submit" value="Cancel"/>
121 <input name="token" type="hidden" value="d9aab65f6ca2462449079d72d5321ebae0ec8325"/>
122 <input name="returnurl" type="hidden" value=""/>
123 <input name="lf_image" type="hidden" value=""/>
130 func TestRailRoad(t
*testing
.T
) {
131 fa
:= func(success
bool) (ret
string, err error
) {
133 return "fail", fmt
.Errorf("failure")
137 fb
:= func(s
string, err0 error
) (int, error
) {
149 assert
.Equal(t
, 2, v
, "success")
150 assert
.Equal(t
, nil, e
, "success")
153 v
, e
:= fb(fa(false))
154 assert
.Equal(t
, 0, v
, "success")
155 assert
.Equal(t
, "failure", e
.Error(), "success")