Fix tuntap_test to cleanup after CreateInterfaceNoCap

PiperOrigin-RevId: 350646249
This commit is contained in:
Mithun Iyer 2021-01-07 15:06:18 -08:00 committed by gVisor bot
parent b1de1da318
commit 04b37c8220
1 changed files with 8 additions and 1 deletions

View File

@ -162,12 +162,19 @@ TEST(TuntapStaticTest, NetTunExists) {
class TuntapTest : public ::testing::Test {
protected:
void SetUp() override {
have_net_admin_cap_ =
ASSERT_NO_ERRNO_AND_VALUE(HaveCapability(CAP_NET_ADMIN));
}
void TearDown() override {
if (ASSERT_NO_ERRNO_AND_VALUE(HaveCapability(CAP_NET_ADMIN))) {
if (have_net_admin_cap_) {
// Bring back capability if we had dropped it in test case.
ASSERT_NO_ERRNO(SetCapability(CAP_NET_ADMIN, true));
}
}
bool have_net_admin_cap_;
};
TEST_F(TuntapTest, CreateInterfaceNoCap) {