-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3eedf4d
commit 2741890
Showing
2 changed files
with
163 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# Copyright (c) [2021] SUSE LLC | ||
# | ||
# All Rights Reserved. | ||
# | ||
# This program is free software; you can redistribute it and/or modify it | ||
# under the terms of version 2 of the GNU General Public License as published | ||
# by the Free Software Foundation. | ||
# | ||
# This program 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, contact SUSE LLC. | ||
# | ||
# To contact SUSE LLC about this file by physical or electronic mail, you may | ||
# find current contact information at www.suse.com. | ||
|
||
require "yast2/equatable" | ||
|
||
module Y2Users | ||
# Class for representing a user home | ||
class Home | ||
include Yast2::Equatable | ||
|
||
# Home path (e.g., "/home/username") | ||
# | ||
# @return [String, nil] nil if unknown | ||
attr_accessor :path | ||
|
||
# Home permissions | ||
# | ||
# It represents an octal number starting by 0 (e.g., "0755") | ||
# | ||
# @return [String, nil] nil if unknown | ||
attr_accessor :permissions | ||
|
||
# Sets whether home is a btrfs subvolume | ||
# | ||
# @return [Boolean] | ||
attr_accessor :btrfs_subvol | ||
|
||
eql_attr :path, :permissions, :btrfs_subvol | ||
|
||
# Constructor | ||
# | ||
# @param path [String, nil] home path | ||
def initialize(path = nil) | ||
@path = path | ||
end | ||
|
||
# Whether home is a btrfs subvolume | ||
# | ||
# @return [Boolean] | ||
def btrfs_subvol? | ||
!!@btrfs_subvol | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
#!/usr/bin/env rspec | ||
|
||
# Copyright (c) [2021] SUSE LLC | ||
# | ||
# All Rights Reserved. | ||
# | ||
# This program is free software; you can redistribute it and/or modify it | ||
# under the terms of version 2 of the GNU General Public License as published | ||
# by the Free Software Foundation. | ||
# | ||
# This program 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, contact SUSE LLC. | ||
# | ||
# To contact SUSE LLC about this file by physical or electronic mail, you may | ||
# find current contact information at www.suse.com. | ||
|
||
require_relative "test_helper" | ||
require "y2users/home" | ||
|
||
describe Y2Users::Home do | ||
subject { described_class.new } | ||
|
||
describe "#btrfs_subvol?" do | ||
before do | ||
subject.btrfs_subvol = value | ||
end | ||
|
||
context "when the value is set to nil" do | ||
let(:value) { nil } | ||
|
||
it "returns false" do | ||
expect(subject.btrfs_subvol?).to eq(false) | ||
end | ||
end | ||
|
||
context "when the value is set to false" do | ||
let(:value) { false } | ||
|
||
it "returns false" do | ||
expect(subject.btrfs_subvol?).to eq(false) | ||
end | ||
end | ||
|
||
context "when the value is set to true" do | ||
let(:value) { true } | ||
|
||
it "returns true" do | ||
expect(subject.btrfs_subvol?).to eq(true) | ||
end | ||
end | ||
end | ||
|
||
describe "#==" do | ||
before do | ||
subject.path = "/home/test" | ||
subject.permissions = "0777" | ||
subject.btrfs_subvol = true | ||
end | ||
|
||
context "when all the attributes are equal" do | ||
let(:other) { subject.dup } | ||
|
||
it "returns true" do | ||
expect(subject == other).to eq(true) | ||
end | ||
end | ||
|
||
context "when the #path does not match" do | ||
let(:other) do | ||
subject.dup.tap { |h| h.path = "/home/other" } | ||
end | ||
|
||
it "returns false" do | ||
expect(subject == other).to eq(false) | ||
end | ||
end | ||
|
||
context "when the #permissions does not match" do | ||
let(:other) do | ||
subject.dup.tap { |h| h.permissions = "0744" } | ||
end | ||
|
||
it "returns false" do | ||
expect(subject == other).to eq(false) | ||
end | ||
end | ||
|
||
context "when the #btrfs_subvol does not match" do | ||
let(:other) do | ||
subject.dup.tap { |h| h.btrfs_subvol = false } | ||
end | ||
|
||
it "returns false" do | ||
expect(subject == other).to eq(false) | ||
end | ||
end | ||
end | ||
end |