aboutsummaryrefslogtreecommitdiffstats
path: root/searchcore/src/tests/index/index_disk_layout/index_disk_layout_test.cpp
blob: e35225b2745f60e92bdb82daeca8530e4983ca20 (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
59
60
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#include <vespa/searchcorespi/index/indexdisklayout.h>
#include <vespa/searchcorespi/index/index_disk_dir.h>
#include <vespa/vespalib/gtest/gtest.h>

namespace searchcorespi::index {

namespace {

void expect_index_disk_dir(IndexDiskDir exp, const vespalib::string& dir)
{
    auto act = IndexDiskLayout::get_index_disk_dir(dir);
    ASSERT_TRUE(act.valid());
    ASSERT_EQ(exp, act);
}

void expect_bad_index_disk_dir(const vespalib::string& dir)
{
    auto act = IndexDiskLayout::get_index_disk_dir(dir);
    ASSERT_FALSE(act.valid());
}

}

TEST(IndexDiskLayoutTest, get_index_disk_dir_works)
{
    {
        SCOPED_TRACE("index.fusion.1");
        expect_index_disk_dir(IndexDiskDir(1, true), "index.fusion.1");
    }
    {
        SCOPED_TRACE("index.flush.2");
        expect_index_disk_dir(IndexDiskDir(2, false), "index.flush.2");
    }
    {
        SCOPED_TRACE("index.flush.3");
        expect_index_disk_dir(IndexDiskDir(3, false), "index.flush.3");
    }
    {
        SCOPED_TRACE("foo/bar/index.flush.4");
        expect_index_disk_dir(IndexDiskDir(4, false), "foo/bar/index.flush.4");
    }
    {
        SCOPED_TRACE("index.flush.");
        expect_bad_index_disk_dir("index.flush.");
    }
    {
        SCOPED_TRACE("index.flush.0");
        expect_bad_index_disk_dir("index.flush.0");
    }
    {
        SCOPED_TRACE("asdf");
        expect_bad_index_disk_dir("asdf");
    }
}

}

GTEST_MAIN_RUN_ALL_TESTS()