Skip to content

Commit

Permalink
Added an example fixture, with a real sample; tests pass.
Browse files Browse the repository at this point in the history
  • Loading branch information
mvidner committed Jan 9, 2018
1 parent 1111876 commit 985628c
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 16 deletions.
2 changes: 1 addition & 1 deletion test/backstores_test.rb
Expand Up @@ -23,7 +23,7 @@
expect(Yast::Execute).to receive(:locally).and_return(output)

bs = Backstores.new
expect(bs.get_backstores_list).to eq([42])
expect(bs.get_backstores_list).to eq([])
end

it "parses an error output" do
Expand Down
21 changes: 21 additions & 0 deletions test/fixtures/ls-typical
@@ -0,0 +1,21 @@
o- / ......................................................................................................................... [...]
o- backstores .............................................................................................................. [...]
| o- block .................................................................................................. [Storage Objects: 0]
| o- fileio ................................................................................................. [Storage Objects: 2]
| | o- home_foouser_tmp_urandom ................................... [/home/foouser/tmp/urandom (1000.0MiB) write-thru deactivated]
| | o- local_home-foouser_dl_openSUSE-Tumbleweed-NET-i586-Snapshot20160416-Media.iso [/local/home-foouser/dl/openSUSE-Tumbleweed-NET-i586-Snapshot20160416-Media.iso (92.0MiB) write-thru activated]
| o- pscsi .................................................................................................. [Storage Objects: 0]
| o- ramdisk ................................................................................................ [Storage Objects: 0]
o- iscsi ............................................................................................................ [Targets: 1]
| o- iqn.2018-01.cz.suse:2e149e55-4d2e-43b7-bc6b-a999c837d6fe .......................................................... [TPGs: 1]
| o- tpg1 ............................................................................................... [no-gen-acls, no-auth]
| o- acls .......................................................................................................... [ACLs: 1]
| | o- iqn.2018-01.cz.suse:2e149e55-4d2e-43b7-bc6b-a999c837d6fe ............................................. [Mapped LUNs: 1]
| | o- mapped_lun0 ........ [lun0 fileio/local_home-foouser_dl_openSUSE-Tumbleweed-NET-i586-Snapshot20160416-Media.iso (rw)]
| o- luns .......................................................................................................... [LUNs: 1]
| | o- lun0 [fileio/local_home-foouser_dl_openSUSE-Tumbleweed-NET-i586-Snapshot20160416-Media.iso (/local/home-foouser/dl/openSUSE-Tumbleweed-NET-i586-Snapshot20160416-Media.iso)]
| o- portals .................................................................................................... [Portals: 1]
| o- 10.217.88.99:3260 ................................................................................................ [OK]
o- loopback ......................................................................................................... [Targets: 0]
o- vhost ............................................................................................................ [Targets: 0]
o- xen_pvscsi ....................................................................................................... [Targets: 0]
34 changes: 19 additions & 15 deletions test/target_data_test.rb
Expand Up @@ -20,30 +20,34 @@
end

it "parses a typical output" do
output = <<EOS
I don't know how the typical output looks like
Let's assume this is fine ;-)
iqn.9999-99.aaa ... [TPGs: 99]
tpg99 whatever
acls .............. [ACLs: 99]
iqn.9999-99.aaa ... [bbb ccc Mapped LUNs: 99]
EOS
output = fixture("ls-typical")
# Anyway, the problem is that the method calls it multiple times
# with various arguments. Refactoring is needed to make this work.
expect_any_instance_of(described_class)
.to receive(:`)
.with("targetcli ls")
.and_return(output)

acl_output = "please don't steal our secrets"
expect_any_instance_of(described_class)
.to receive(:`)
.with("targetcli iscsi/iqn.9999-99.foo/tpg44/acls/iqn.9999-99.bla/ get auth userid")
.and_return(acl_output)
acl = "iscsi/iqn.2018-01.cz.suse:2e149e55-4d2e-43b7-bc6b-a999c837d6fe/tpg1/acls/iqn.2018-01.cz.suse:2e149e55-4d2e-43b7-bc6b-a999c837d6fe/"

expect_any_instance_of(described_class).to receive(:`)
.with("targetcli #{acl} get auth userid")
.and_return("userid=teddybear")

expect_any_instance_of(described_class).to receive(:`)
.with("targetcli #{acl} get auth password")
.and_return("password=plush")

expect_any_instance_of(described_class).to receive(:`)
.with("targetcli #{acl} get auth mutual_userid")
.and_return("mutual_userid=foo")

expect_any_instance_of(described_class).to receive(:`)
.with("targetcli #{acl} get auth mutual_password")
.and_return("mutual_password=bar")

td = TargetData.new
expect(td.get_target_names_array).to eq(["iqn.9999-99.aaa"])
expect(td.get_target_names_array).to eq(["iqn.2018-01.cz.suse:2e149e55-4d2e-43b7-bc6b-a999c837d6fe"])
end

it "parses an error output" do
Expand Down
5 changes: 5 additions & 0 deletions test/test_helper.rb
@@ -1 +1,6 @@
$LOAD_PATH << File.expand_path("../../src/include/iscsi-lio-server", __FILE__)

def fixture(name)
fn = File.expand_path("../fixtures/#{name}", __FILE__)
File.read(fn)
end

0 comments on commit 985628c

Please sign in to comment.