summary refs log tree commit diff stats
path: root/Makefile
blob: eea8cdd031f376263582f2696b165b1cc72bab87 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
PREFIX?=/usr/local
_INSTDIR=$(PREFIX)
BINDIR?=$(_INSTDIR)/getwtxt
VERSION?=$(shell git tag | grep ^v | sort -V | tail -n 1)
GOFLAGS?=-tags netgo \
				 -ldflags '-X github.com/getwtxt/getwtxt/svc.Vers=${VERSION} -extldflags "-static"' \
				 -buildmode pie

getwtxt: getwtxt.go go.mod go.sum
	go build $(GOFLAGS) \
		-o $@

RM?=rm -f

clean:
	$(RM) getwtxt

update:
	git pull --rebase

install:
	adduser -home $(BINDIR) --system --group getwtxt
	mkdir -p $(BINDIR)/assets/tmpl $(BINDIR)/docs
	install -m755 getwtxt $(BINDIR)
	install -m644 getwtxt.yml $(BINDIR)
	install -m644 assets/style.css $(BINDIR)/assets
	install -m644 assets/tmpl/index.html $(BINDIR)/assets/tmpl
	install -m644 README.md $(BINDIR)/docs
	install -m644 LICENSE $(BINDIR)/docs
	install -m644 etc/getwtxt-proxied.service /etc/systemd/system
	chown -R getwtxt:getwtxt $(BINDIR)

install-unproxied:
	adduser -home $(BINDIR) --system --group getwtxt
	mkdir -p $(BINDIR)/assets/tmpl $(BINDIR)/docs
	install -m755 getwtxt $(BINDIR)
	install -m644 getwtxt.yml $(BINDIR)
	install -m644 assets/style.css $(BINDIR)/assets
	install -m644 assets/tmpl/index.html $(BINDIR)/assets/tmpl
	install -m644 README.md $(BINDIR)/docs
	install -m644 LICENSE $(BINDIR)/docs
	install -m644 etc/getwtxt.service /etc/systemd/system
	chown -R getwtxt:getwtxt $(BINDIR)

uninstall:
	systemctl stop getwtxt >/dev/null 2>&1
	systemctl disable getwtxt >/dev/null 2>&1
	rm -rf $(BINDIR)
	rm -f /etc/systemd/system/getwtxt.service
	userdel getwtxt
 
                                                               






                                             





















































                                                                 
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
#include <cmocka.h>
#include <stdlib.h>
#include <string.h>
#include <glib.h>

#include "xmpp/xmpp.h"
#include "xmpp/mock_xmpp.h"

#include "ui/ui.h"
#include "ui/mock_ui.h"

#include "config/preferences.h"

#include "command/command.h"
#include "command/commands.h"

void cmd_alias_add_shows_usage_when_no_args(void **state)
{
    mock_cons_show();
    CommandHelp *help = malloc(sizeof(CommandHelp));
    help->usage = "some usage";
    gchar *args[] = { "add", NULL };

    expect_cons_show("Usage: some usage");

    gboolean result = cmd_alias(args, *help);
    assert_true(result);

    free(help);
}

void cmd_alias_add_shows_usage_when_no_value(void **state)
{
    mock_cons_show();
    CommandHelp *help = malloc(sizeof(CommandHelp));
    help->usage = "some usage";
    gchar *args[] = { "add", "alias", NULL };

    expect_cons_show("Usage: some usage");

    gboolean result = cmd_alias(args, *help);
    assert_true(result);

    free(help);
}

void cmd_alias_remove_shows_usage_when_no_args(void **state)
{
    mock_cons_show();
    CommandHelp *help = malloc(sizeof(CommandHelp));
    help->usage = "some usage";
    gchar *args[] = { "remove", NULL };

    expect_cons_show("Usage: some usage");

    gboolean result = cmd_alias(args, *help);
    assert_true(result);

    free(help);
}

void cmd_alias_show_usage_when_invalid_subcmd(void **state)
{
    mock_cons_show();
    CommandHelp *help = malloc(sizeof(CommandHelp));
    help->usage = "some usage";
    gchar *args[] = { "blah", NULL };

    expect_cons_show("Usage: some usage");

    gboolean result = cmd_alias(args, *help);
    assert_true(result);

    free(help);
}

void cmd_alias_add_adds_alias(void **state)
{
    mock_cons_show();
    CommandHelp *help = malloc(sizeof(CommandHelp));
    gchar *args[] = { "add", "hc", "/help commands", NULL };

    expect_cons_show("Command alias added /hc -> /help commands");

    gboolean result = cmd_alias(args, *help);

    char *returned_val = prefs_get_alias("hc");

    assert_true(result);
    assert_string_equal("/help commands", returned_val);

    free(help);
}

void cmd_alias_add_shows_message_when_exists(void **state)
{
    mock_cons_show();
    CommandHelp *help = malloc(sizeof(CommandHelp));
    gchar *args[] = { "add", "hc", "/help commands", NULL };

    cmd_init();
    prefs_add_alias("hc", "/help commands");
    cmd_autocomplete_add("/hc");

    expect_cons_show("Command or alias '/hc' already exists.");

    gboolean result = cmd_alias(args, *help);
    assert_true(result);

    free(help);
}

void cmd_alias_remove_removes_alias(void **state)
{
    mock_cons_show();
    CommandHelp *help = malloc(sizeof(CommandHelp));
    gchar *args[] = { "remove", "hn", NULL };

    prefs_add_alias("hn", "/help navigation");

    expect_cons_show("Command alias removed -> /hn");

    gboolean result = cmd_alias(args, *help);

    char *returned_val = prefs_get_alias("hn");

    assert_true(result);
    assert_null(returned_val);

    free(help);
}

void cmd_alias_remove_shows_message_when_no_alias(void **state)
{
    mock_cons_show();
    CommandHelp *help = malloc(sizeof(CommandHelp));
    gchar *args[] = { "remove", "hn", NULL };

    expect_cons_show("No such command alias /hn");

    gboolean result = cmd_alias(args, *help);
    assert_true(result);

    free(help);
}

void cmd_alias_list_shows_all_aliases(void **state)
{
    mock_cons_show_aliases();
    CommandHelp *help = malloc(sizeof(CommandHelp));
    gchar *args[] = { "list", NULL };

    prefs_add_alias("vy", "/vercheck on");
    prefs_add_alias("q", "/quit");
    prefs_add_alias("hn", "/help navigation");
    prefs_add_alias("hc", "/help commands");
    prefs_add_alias("vn", "/vercheck off");

    // write a custom checker to check the correct list is passed
    expect_cons_show_aliases();

    gboolean result = cmd_alias(args, *help);
    assert_true(result);

    free(help);
}