summaryrefslogtreecommitdiff
path: root/test/sbuild/chroot/plain.cc
blob: c1e270c6c83f87c40b65449fb56133d4f0a0878e (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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/* Copyright © 2006-2013  Roger Leigh <rleigh@debian.org>
 *
 * schroot 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.
 *
 * schroot 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 this program.  If not, see
 * <http://www.gnu.org/licenses/>.
 *
 *********************************************************************/

#include <config.h>

#include <sbuild/config.h>
#include <sbuild/chroot/facet/plain.h>
#include <sbuild/keyfile-writer.h>

#include <test/sbuild/chroot/chroot.h>

#include <algorithm>
#include <set>

class ChrootPlain : public ChrootBase
{

public:
  ChrootPlain():
    ChrootBase("plain")
  {}

  void SetUp()
  {
    ChrootBase::SetUp();
    ASSERT_NE(chroot, nullptr);
    ASSERT_EQ(session, nullptr);
    ASSERT_EQ(source, nullptr);
    ASSERT_EQ(session_source, nullptr);
  }

  virtual void setup_chroot_props (sbuild::chroot::chroot::ptr& chroot)
  {
    ChrootBase::setup_chroot_props(chroot);

    chroot->set_mount_location("");

    sbuild::chroot::facet::plain::ptr plfac = chroot->get_facet<sbuild::chroot::facet::plain>();
    plfac->set_directory("/srv/chroot/example-chroot");
  }
};

TEST_F(ChrootPlain, Directory)
{
  sbuild::chroot::facet::plain::ptr plfac = chroot->get_facet<sbuild::chroot::facet::plain>();
  plfac->set_directory("/mnt/mount-location/example");
  ASSERT_EQ(plfac->get_directory(), "/mnt/mount-location/example");
  ASSERT_EQ(chroot->get_path(), "/mnt/mount-location/example");
  ASSERT_EQ(chroot->get_mount_location(), "");
}

TEST_F(ChrootPlain, Type)
{
  ASSERT_EQ(chroot->get_chroot_type(), "plain");
}

TEST_F(ChrootPlain, SetupEnv)
{
  sbuild::environment expected;
  setup_env_chroot(expected);
  expected.add("CHROOT_TYPE",           "plain");
  expected.add("CHROOT_DIRECTORY",      "/srv/chroot/example-chroot");
  expected.add("CHROOT_PATH",           "/srv/chroot/example-chroot");
  expected.add("CHROOT_SESSION_CLONE",  "false");
  expected.add("CHROOT_SESSION_CREATE", "false");
  expected.add("CHROOT_SESSION_PURGE",  "false");

  ChrootBase::test_setup_env(chroot, expected);
}

TEST_F(ChrootPlain, SetupKeyfile)
{
  sbuild::keyfile expected;
  std::string group = chroot->get_name();
  setup_keyfile_chroot(expected, group);
  expected.set_value(group, "type", "plain");
  expected.set_value(group, "directory", "/srv/chroot/example-chroot");

  ChrootBase::test_setup_keyfile
    (chroot, expected, group);
}

TEST_F(ChrootPlain, SessionFlags)
{
  ASSERT_EQ(chroot->get_session_flags(),
            sbuild::chroot::facet::facet::SESSION_NOFLAGS);
}

TEST_F(ChrootPlain, PrintDetails)
{
  std::ostringstream os;
  os << chroot;
  // TODO: Compare output.
  ASSERT_FALSE(os.str().empty());
}

TEST_F(ChrootPlain, PrintConfig)
{
  std::ostringstream os;
  sbuild::keyfile config;
  config << chroot;
  os << sbuild::keyfile_writer(config);
  // TODO: Compare output.
  ASSERT_FALSE(os.str().empty());
}

TEST_F(ChrootPlain, RunSetupScripts)
{
  ASSERT_FALSE(chroot->get_run_setup_scripts());
}