blob: 2b56b75e0fdd3ba910015acec4a893796e44d169 [file] [log] [blame]
// Copyright 2018 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "peridot/lib/scoped_tmpfs/scoped_tmpfs.h"
#include <fcntl.h>
#include <unistd.h>
#include "gtest/gtest.h"
#include "src/lib/files/unique_fd.h"
namespace scoped_tmpfs {
namespace {
TEST(ScopedTmpFsTest, ScopedTmpFs) {
ScopedTmpFS scoped_tmpfs;
EXPECT_GE(scoped_tmpfs.root_fd(), 0);
fbl::unique_fd fd(openat(scoped_tmpfs.root_fd(), "foo", O_WRONLY | O_CREAT | O_EXCL));
EXPECT_GT(write(fd.get(), "Hello", 6), 0);
fd.reset(openat(scoped_tmpfs.root_fd(), "foo", O_RDONLY));
char b;
EXPECT_EQ(1, read(fd.get(), &b, 1));
EXPECT_EQ('H', b);
} // namespace
} // namespace scoped_tmpfs