about summary refs log tree commit diff
path: root/test/uname_test.c
blob: 3a8390c1ca87ce171e30d2dad21870473b395b1a (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
51
52
53
54
55
56
57
58
/*
 * Copyright 2018 Google LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <string.h>
#include <sys/utsname.h>

#include "harness.h"
#include "mock_scrape.h"
#include "../collector.h"

extern const struct collector uname_collector;
void uname_test_override_data(void *ctx, struct utsname *name);

TEST(uname_metrics) {
  scrape_req *req = mock_scrape_start(env);
  struct utsname mock_uname;
  strcpy(mock_uname.machine, "x86_64");
  strcpy(mock_uname.nodename, "eris");
  strcpy(mock_uname.release, "4.18.0-1-amd64");
  strcpy(mock_uname.sysname, "Linux");
  strcpy(mock_uname.version, "#1 SMP Debian 4.18.6-1 (2018-09-06)");

  void *ctx = uname_collector.init(0, 0);
  uname_test_override_data(ctx, &mock_uname);
  uname_collector.collect(req, ctx);

  mock_scrape_expect(
      req,
      "node_uname_info",
      LABEL_LIST(
          {"machine", "x86_64"},
          {"nodename", "eris"},
          {"release", "4.18.0-1-amd64"},
          {"sysname", "Linux"},
          {"version", "#1 SMP Debian 4.18.6-1 (2018-09-06)"}),
      1);
  mock_scrape_expect_no_more(req);
  mock_scrape_free(req);
}

TEST_SUITE {
  TEST_SUITE_START;
  RUN_TEST(uname_metrics);
  TEST_SUITE_END;
}