summaryrefslogtreecommitdiffstats
path: root/lib/common/tests/agents/crm_parse_agent_spec_test.c
blob: 1d44459eb3f27f1adb75a7640ba7fe8c6813fc02 (plain)
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/*
 * Copyright 2022-2023 the Pacemaker project contributors
 *
 * The version control history for this file may have further details.
 *
 * This source code is licensed under the GNU General Public License version 2
 * or later (GPLv2+) WITHOUT ANY WARRANTY.
 */

#include <crm_internal.h>

#include <crm/common/unittest_internal.h>
#include <crm/common/agents.h>

static void
all_params_null(void **state) {
    assert_int_equal(crm_parse_agent_spec(NULL, NULL, NULL, NULL), -EINVAL);
    assert_int_equal(crm_parse_agent_spec("", NULL, NULL, NULL), -EINVAL);
    assert_int_equal(crm_parse_agent_spec(":", NULL, NULL, NULL), -EINVAL);
    assert_int_equal(crm_parse_agent_spec("::", NULL, NULL, NULL), -EINVAL);
}

static void
no_prov_or_type(void **state) {
    char *std = NULL;
    char *prov = NULL;
    char *ty = NULL;

    assert_int_equal(crm_parse_agent_spec("ocf", &std, &prov, &ty), -EINVAL);
    assert_int_equal(crm_parse_agent_spec("ocf:", &std, &prov, &ty), -EINVAL);
    assert_int_equal(crm_parse_agent_spec("ocf::", &std, &prov, &ty), -EINVAL);
}

static void
no_type(void **state) {
    char *std = NULL;
    char *prov = NULL;
    char *ty = NULL;

    assert_int_equal(crm_parse_agent_spec("ocf:pacemaker:", &std, &prov, &ty), -EINVAL);
}

static void
get_std_and_ty(void **state) {
    char *std = NULL;
    char *prov = NULL;
    char *ty = NULL;

    assert_int_equal(crm_parse_agent_spec("stonith:fence_xvm", &std, &prov, &ty), pcmk_ok);
    assert_string_equal(std, "stonith");
    assert_null(prov);
    assert_string_equal(ty, "fence_xvm");

    free(std);
    free(ty);
}

static void
get_all_values(void **state) {
    char *std = NULL;
    char *prov = NULL;
    char *ty = NULL;

    assert_int_equal(crm_parse_agent_spec("ocf:pacemaker:ping", &std, &prov, &ty), pcmk_ok);
    assert_string_equal(std, "ocf");
    assert_string_equal(prov, "pacemaker");
    assert_string_equal(ty, "ping");

    free(std);
    free(prov);
    free(ty);
}

static void
get_systemd_values(void **state) {
    char *std = NULL;
    char *prov = NULL;
    char *ty = NULL;

    assert_int_equal(crm_parse_agent_spec("systemd:UNIT@A:B", &std, &prov, &ty), pcmk_ok);
    assert_string_equal(std, "systemd");
    assert_null(prov);
    assert_string_equal(ty, "UNIT@A:B");

    free(std);
    free(ty);
}

PCMK__UNIT_TEST(NULL, NULL,
                cmocka_unit_test(all_params_null),
                cmocka_unit_test(no_prov_or_type),
                cmocka_unit_test(no_type),
                cmocka_unit_test(get_std_and_ty),
                cmocka_unit_test(get_all_values),
                cmocka_unit_test(get_systemd_values))