@@ -70,8 +70,11 @@ def parse(string)
7070 end
7171
7272 before do
73- # Speed up tests by avoding real check of TPM presence.
73+ # Speed up tests by avoiding real check of TPM presence.
7474 allow ( Y2Storage ::EncryptionMethod ::TPM_FDE ) . to receive ( :possible? ) . and_return ( true )
75+ # Speed up tests by avoiding looking up by name in the system
76+ allow ( Y2Storage ::BlkDevice ) . to receive ( :find_by_any_name )
77+
7578 allow ( Yast ::Arch ) . to receive ( :s390 ) . and_return false
7679 allow ( backend ) . to receive ( :on_configure )
7780 allow ( backend ) . to receive ( :on_issues_change )
@@ -786,6 +789,110 @@ def parse(string)
786789 end
787790 end
788791
792+ describe "#probe" do
793+ before do
794+ allow ( subject ) . to receive ( :SystemChanged )
795+ allow ( subject ) . to receive ( :ProgressChanged )
796+ allow ( subject ) . to receive ( :ProgressFinished )
797+
798+ allow ( backend ) . to receive ( :activated? ) . and_return activated
799+ allow ( backend ) . to receive ( :probe )
800+ end
801+
802+ let ( :activated ) { true }
803+
804+ it "triggers a new probing" do
805+ expect ( backend ) . to receive ( :probe )
806+ subject . probe
807+ end
808+
809+ context "when storage devices are already activated" do
810+ it "does not activate devices" do
811+ expect ( backend ) . to_not receive ( :activate )
812+ subject . probe
813+ end
814+ end
815+
816+ context "when storage devices are not yet activated" do
817+ let ( :activated ) { false }
818+
819+ it "activates the devices" do
820+ expect ( backend ) . to receive ( :activate )
821+ subject . probe
822+ end
823+ end
824+
825+ context "when no storage configuration has been set" do
826+ it "does not calculate a new proposal" do
827+ expect ( backend ) . to_not receive ( :configure )
828+ subject . probe
829+ end
830+
831+ it "does not emit a ProposalChanged signal" do
832+ expect ( subject ) . to_not receive ( :ProposalChanged )
833+ subject . probe
834+ end
835+
836+ it "emits signals for SystemChanged, ProgressChanged and ProgressFinished" do
837+ expect ( subject ) . to receive ( :SystemChanged ) do |system_str |
838+ system = parse ( system_str )
839+ device = system [ :devices ] . first
840+ expect ( device [ :name ] ) . to eq "/dev/sda"
841+ expect ( system [ :availableDrives ] ) . to eq [ device [ :sid ] ]
842+ end
843+ expect ( subject ) . to receive ( :ProgressChanged ) . with ( /storage configuration/i )
844+ expect ( subject ) . to receive ( :ProgressFinished )
845+
846+ subject . probe
847+ end
848+ end
849+
850+ context "when a storage configuration was previously set" do
851+ before do
852+ allow ( proposal ) . to receive ( :storage_json ) . and_return config_json . to_json
853+ allow ( subject ) . to receive ( :ProposalChanged )
854+ end
855+
856+ let ( :config_json ) do
857+ {
858+ storage : {
859+ drives : [
860+ {
861+ partitions : [
862+ { search : "*" , delete : true } ,
863+ { filesystem : { path : "/" } , size : { min : "5 GiB" } }
864+ ]
865+ }
866+ ]
867+ }
868+ }
869+ end
870+
871+ it "re-calculates the proposal" do
872+ expect ( backend ) . to receive ( :configure ) . with ( config_json )
873+ subject . probe
874+ end
875+
876+ it "emits signals for ProposalChanged, SystemChanged, ProgressChanged and ProgressFinished" do
877+ expect ( subject ) . to receive ( :SystemChanged ) do |system_str |
878+ system = parse ( system_str )
879+ device = system [ :devices ] . first
880+ expect ( device [ :name ] ) . to eq "/dev/sda"
881+ expect ( system [ :availableDrives ] ) . to eq [ device [ :sid ] ]
882+ end
883+ expect ( subject ) . to receive ( :ProposalChanged ) do |proposal_str |
884+ proposal = parse ( proposal_str )
885+ expect ( proposal [ :devices ] ) . to be_a Array
886+ expect ( proposal [ :actions ] ) . to be_a Array
887+ end
888+ expect ( subject ) . to receive ( :ProgressChanged ) . with ( /storage configuration/i )
889+ expect ( subject ) . to receive ( :ProgressFinished )
890+
891+ subject . probe
892+ end
893+ end
894+ end
895+
789896 describe "#recover_issues" do
790897 context "if no proposal has been calculated" do
791898 it "returns an empty array" do
0 commit comments