Branch | Commit message | Author | Age | |
---|---|---|---|---|
master | Merge branch 'victorbnl-viewnior-config' | toonn | 2 years | |
Tag | Download | Author | Age | |
v1.9.3 | ranger-1.9.3.tar.gz | toonn | 5 years | |
v1.9.2 | ranger-1.9.2.tar.gz | toonn | 6 years | |
v1.9.1 | ranger-1.9.1.tar.gz | Wojciech Siewierski | 7 years | |
v1.9.0 | ranger-1.9.0.tar.gz | hut | 7 years | |
v1.9.0b6 | ranger-1.9.0b6.tar.gz | Wojciech Siewierski | 7 years | |
v1.9.0b5 | ranger-1.9.0b5.tar.gz | nfnty | 8 years | |
v1.9.0b4 | ranger-1.9.0b4.tar.gz | nfnty | 8 years | |
v1.9.0b3 | ranger-1.9.0b3.tar.gz | nfnty | 8 years | |
v1.9.0b2 | ranger-1.9.0b2.tar.gz | nfnty | 8 years | |
v1.9.0b1 | ranger-1.9.0b1.tar.gz | nfnty | 8 years | |
v1.8.1 | ranger-1.8.1.tar.gz | nfnty | 8 years | |
v1.8.0 | ranger-1.8.0.tar.gz | hut | 8 years | |
v1.7.2 | ranger-1.7.2.tar.gz | hut | 9 years | |
v1.7.1 | ranger-1.7.1.tar.gz | hut | 10 years | |
v1.7.0-emacs | ranger-1.7.0-emacs.tar.gz | hut | 10 years | |
v1.7.0 | ranger-1.7.0.tar.gz | hut | 10 years | |
v1.6.1 | ranger-1.6.1.tar.gz | hut | 11 years | |
v1.6.0 | ranger-1.6.0.tar.gz | hut | 12 years | |
v1.5.5 | ranger-1.5.5.tar.gz | hut | 12 years | |
v1.5.4 | ranger-1.5.4.tar.gz | hut | 13 years | |
v1.5.3 | ranger-1.5.3.tar.gz | hut | 13 years | |
v1.5.2 | ranger-1.5.2.tar.gz | hut | 13 years | |
v1.5.1 | ranger-1.5.1.tar.gz | hut | 13 years | |
v1.5.0 | ranger-1.5.0.tar.gz | hut | 13 years | |
v1.4.4 | ranger-1.4.4.tar.gz | hut | 13 years | |
v1.4.3 | ranger-1.4.3.tar.gz | hut | 14 years | |
v1.4.2 | ranger-1.4.2.tar.gz | hut | 14 years | |
v1.4.1 | ranger-1.4.1.tar.gz | hut | 14 years | |
v1.4.0 | ranger-1.4.0.tar.gz | hut | 14 years | |
v1.2.3 | ranger-1.2.3.tar.gz | hut | 14 years | |
v1.2.2 | ranger-1.2.2.tar.gz | hut | 14 years | |
v1.2.1 | ranger-1.2.1.tar.gz | hut | 14 years | |
v1.2.0 | ranger-1.2.0.tar.gz | hut | 14 years | |
v1.1.2 | ranger-1.1.2.tar.gz | hut | 14 years | |
v1.1.1 | ranger-1.1.1.tar.gz | hut | 14 years | |
v1.1.0 | ranger-1.1.0.tar.gz | hut | 14 years | |
v1.0.4 | ranger-1.0.4.tar.gz | hut | 15 years | |
v1.0.3 | ranger-1.0.3.tar.gz | hut | 15 years | |
v1.0.2 | ranger-1.0.2.tar.gz | hut | 15 years | |
v0.2.6 | ranger-0.2.6.tar.gz | hut | 15 years | |
v1.0.1 | ranger-1.0.1.tar.gz | hut | 15 years | |
v0.2.5 | ranger-0.2.5.tar.gz | hut | 15 years | |
v0.2.4 | ranger-0.2.4.tar.gz | hut | 15 years | |
v0.2.3 | ranger-0.2.3.tar.gz | hut | 15 package svc // import "github.com/getwtxt/getwtxt/svc"
import (
"fmt"
"net/http"
"net/http/httptest"
"net/url"
"strings"
"testing"
"github.com/getwtxt/registry"
)
var apiPostUserCases = []struct {
name string
nick string
uri string
wantErr bool
}{
{
name: "Known Good User",
nick: "gbmor",
uri: "https://gbmor.dev/twtxt.txt",
wantErr: false,
},
{
name: "Missing URI",
nick: "missinguri",
uri: "",
wantErr: true,
},
{
name: "Missing Nickname",
nick: "",
uri: "https://example.com/twtxt.txt",
wantErr: true,
},
{
name: "Missing URI and Nickname",
nick: "",
uri: "",
wantErr: true,
},
}
func Test_apiPostUser(t *testing.T) {
initTestConf()
portnum := fmt.Sprintf(":%v", confObj.Port)
twtxtCache = registry.NewIndex()
for _, tt := range apiPostUserCases {
t.Run(tt.name, func(t *testing.T) {
params := url.Values{}
params.Set("url", tt.uri)
params.Set("nickname", tt.nick)
req, err := http.NewRequest("POST", "https://localhost"+portnum+"/api/plain/users", strings.NewReader(params.Encode()))
if err != nil {
t.Errorf("%v\n", err)
}
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
rr := httptest.NewRecorder()
apiEndpointPOSTHandler(rr, req)
if !tt.wantErr {
if rr.Code != http.StatusOK {
t.Errorf("Received unexpected non-200 response: %v\n", rr.Code)
}
} else {
if rr.Code != http.StatusBadRequest {
t.Errorf("Expected 400 Bad Request, but received: %v\n", rr.Code)
}
}
})
}
}
|