Skip to content

Commit

Permalink
added unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
aschnell committed Mar 4, 2019
1 parent dc5d615 commit 422de08
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 0 deletions.
57 changes: 57 additions & 0 deletions test/discovery_auth_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/usr/bin/env rspec
# encoding: utf-8

# Copyright (c) [2019] 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 "TargetData"

describe DiscoveryAuth do
describe "#analyze" do
before do
allow(Yast::Execute).to receive(:locally!).and_return(output)
end

let(:execute_object) { Yast::Execute.new }

context "when 'targetcli' output is correct" do
let(:output) { fixture("auth-typical") }

it "reads the correct values" do
subject.analyze

expect(subject.fetch_status).to eq true
expect(subject.fetch_userid).to eq "name1"
expect(subject.fetch_password).to eq "secret1"
expect(subject.fetch_mutual_userid).to eq "name2"
expect(subject.fetch_mutual_password).to eq "secret2"
end
end

context "when 'targetcli' output is broken" do
let(:output) { fixture("auth-broken") }

it "raises an exception" do
expect { subject.analyze }.to raise_error(Exception)
end
end
end
end
3 changes: 3 additions & 0 deletions test/fixtures/auth-broken
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
enable=True
userid=name1
password=secret1
5 changes: 5 additions & 0 deletions test/fixtures/auth-typical
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
enable=True
userid=name1
password=secret1
mutual_userid=name2
mutual_password=secret2

0 comments on commit 422de08

Please sign in to comment.