summary refs log tree commit diff stats
path: root/post_test.go
diff options
context:
space:
mode:
authorBen Morrison <ben@gbmor.dev>2019-05-27 18:25:30 -0400
committerBen Morrison <ben@gbmor.dev>2019-05-27 18:26:58 -0400
commit6f9383517d8dbee557d2b52113e20e08207b533e (patch)
tree1fd918f37cd963ab496e2f7b9ee1bef8fa7fa8ba /post_test.go
parent3c5dd59f5c3be00909df4a509eea940393fd060e (diff)
downloadgetwtxt-6f9383517d8dbee557d2b52113e20e08207b533e.tar.gz
modified POST test
Diffstat (limited to 'post_test.go')
-rw-r--r--post_test.go16
1 files changed, 9 insertions, 7 deletions
diff --git a/post_test.go b/post_test.go
index 9d04c9e..a0d43ac 100644
--- a/post_test.go
+++ b/post_test.go
@@ -1,11 +1,14 @@
 package main
 
 import (
+	"fmt"
 	"net/http"
 	"net/http/httptest"
 	"net/url"
 	"strings"
 	"testing"
+
+	"github.com/getwtxt/registry"
 )
 
 var apiPostUserCases = []struct {
@@ -16,8 +19,8 @@ var apiPostUserCases = []struct {
 }{
 	{
 		name:    "Known Good User",
-		nick:    "soltempore",
-		uri:     "https://enotty.dk/soltempore.txt",
+		nick:    "gbmor",
+		uri:     "https://gbmor.dev/twtxt.txt",
 		wantErr: false,
 	},
 	{
@@ -42,6 +45,8 @@ var apiPostUserCases = []struct {
 
 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) {
@@ -49,17 +54,14 @@ func Test_apiPostUser(t *testing.T) {
 			params.Set("url", tt.uri)
 			params.Set("nickname", tt.nick)
 
-			req, err := http.NewRequest("POST", "http://localhost"+testport+"/api/plain/users", strings.NewReader(params.Encode()))
+			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()
-			handler := http.HandlerFunc(apiEndpointPOSTHandler)
-
-			handler.ServeHTTP(rr, req)
+			apiEndpointPOSTHandler(rr, req)
 
 			if !tt.wantErr {
 				if rr.Code != http.StatusOK {
3388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
/* 
 * common.c
 *
 * Copyright (C) 2012 James Booth <boothj5@gmail.com>
 * 
 * This file is part of Profanity.
 *
 * Profanity 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.
 *
 * Profanity 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 Profanity.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

#include <sys/types.h>
#include <sys/stat.h>
#include <stdlib.h>
#include <errno.h>
#include <stdio.h>

#include <glib.h>

#include "common.h"

void
p_slist_free_full(GSList *items, GDestroyNotify free_func)
{
    g_slist_foreach (items, (GFunc) free_func, NULL);
    g_slist_free (items);
}

void
create_config_directory()
{
    GString *dir = g_string_new(getenv("HOME"));
    g_string_append(dir, "/.profanity");
    create_dir(dir->str);
    g_string_free(dir, TRUE);
}

void
create_dir(char *name)
{
    int e;
    struct stat sb;

    e = stat(name, &sb);
    if (e != 0)
        if (errno == ENOENT)
            e = mkdir(name, S_IRWXU);
}