| 
									
										
										
										
											2019-04-19 15:38:03 +09:00
										 |  |  | # frozen_string_literal: true | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-22 14:15:36 -04:00
										 |  |  | require "linkage_cache_store" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-18 15:11:11 -08:00
										 |  |  | RSpec.describe LinkageCacheStore do | 
					
						
							| 
									
										
										
										
											2021-01-31 13:14:23 -05:00
										 |  |  |   subject(:linkage_cache) { described_class.new(keg_name, database) } | 
					
						
							| 
									
										
										
										
											2018-09-20 09:07:56 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-22 14:15:36 -04:00
										 |  |  |   let(:keg_name) { "keg_name" } | 
					
						
							| 
									
										
										
										
											2023-01-22 17:08:01 -08:00
										 |  |  |   let(:database) { instance_double(CacheStoreDatabase, "database") } | 
					
						
							| 
									
										
										
										
											2018-05-22 14:15:36 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |   describe "#keg_exists?" do | 
					
						
							| 
									
										
										
										
											2021-02-19 23:15:33 +00:00
										 |  |  |     context "when `keg_name` exists in cache" do | 
					
						
							| 
									
										
										
										
											2018-05-22 14:15:36 -04:00
										 |  |  |       it "returns `true`" do | 
					
						
							| 
									
										
										
										
											2019-03-28 19:16:56 +00:00
										 |  |  |         expect(database).to receive(:get).with(keg_name).and_return("") | 
					
						
							| 
									
										
										
										
											2021-01-31 13:14:23 -05:00
										 |  |  |         expect(linkage_cache.keg_exists?).to be(true) | 
					
						
							| 
									
										
										
										
											2018-05-22 14:15:36 -04:00
										 |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-19 23:15:33 +00:00
										 |  |  |     context "when `keg_name` does not exist in cache" do | 
					
						
							| 
									
										
										
										
											2018-05-22 14:15:36 -04:00
										 |  |  |       it "returns `false`" do | 
					
						
							| 
									
										
										
										
											2019-03-28 19:16:56 +00:00
										 |  |  |         expect(database).to receive(:get).with(keg_name).and_return(nil) | 
					
						
							| 
									
										
										
										
											2021-01-31 13:14:23 -05:00
										 |  |  |         expect(linkage_cache.keg_exists?).to be(false) | 
					
						
							| 
									
										
										
										
											2018-05-22 14:15:36 -04:00
										 |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   describe "#update!" do | 
					
						
							| 
									
										
										
										
											2021-02-19 23:15:33 +00:00
										 |  |  |     context "when a `value` is a `Hash`" do | 
					
						
							| 
									
										
										
										
											2018-05-22 14:15:36 -04:00
										 |  |  |       it "sets the cache for the `keg_name`" do | 
					
						
							|  |  |  |         expect(database).to receive(:set).with(keg_name, anything) | 
					
						
							| 
									
										
										
										
											2021-01-31 13:14:23 -05:00
										 |  |  |         linkage_cache.update!(keg_files_dylibs: { key: ["value"] }) | 
					
						
							| 
									
										
										
										
											2018-05-22 14:15:36 -04:00
										 |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-19 23:15:33 +00:00
										 |  |  |     context "when a `value` is not a `Hash`" do | 
					
						
							| 
									
										
										
										
											2018-06-01 13:26:45 +01:00
										 |  |  |       it "raises a `TypeError` if a `value` is not a `Hash`" do | 
					
						
							| 
									
										
										
										
											2021-01-31 13:14:23 -05:00
										 |  |  |         expect { linkage_cache.update!(a_value: ["value"]) }.to raise_error(TypeError) | 
					
						
							| 
									
										
										
										
											2018-05-22 14:15:36 -04:00
										 |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-13 08:22:51 -07:00
										 |  |  |   describe "#delete!" do | 
					
						
							| 
									
										
										
										
											2018-05-22 14:15:36 -04:00
										 |  |  |     it "calls `delete` on the `database` with `keg_name` as parameter" do | 
					
						
							|  |  |  |       expect(database).to receive(:delete).with(keg_name) | 
					
						
							| 
									
										
										
										
											2021-01-31 13:14:23 -05:00
										 |  |  |       linkage_cache.delete! | 
					
						
							| 
									
										
										
										
											2018-05-22 14:15:36 -04:00
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-13 08:22:51 -07:00
										 |  |  |   describe "#fetch" do | 
					
						
							| 
									
										
										
										
											2021-02-19 23:15:33 +00:00
										 |  |  |     context "when `HASH_LINKAGE_TYPES.include?(type)`" do | 
					
						
							| 
									
										
										
										
											2018-05-22 14:15:36 -04:00
										 |  |  |       it "returns a `Hash` of values" do | 
					
						
							| 
									
										
										
										
											2019-03-28 19:16:56 +00:00
										 |  |  |         expect(database).to receive(:get).with(keg_name).and_return(nil) | 
					
						
							| 
									
										
										
										
											2021-01-31 13:14:23 -05:00
										 |  |  |         expect(linkage_cache.fetch(:keg_files_dylibs)).to be_an_instance_of(Hash) | 
					
						
							| 
									
										
										
										
											2018-05-22 14:15:36 -04:00
										 |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-19 23:15:33 +00:00
										 |  |  |     context "when `type` is not in `HASH_LINKAGE_TYPES`" do | 
					
						
							| 
									
										
										
										
											2018-05-22 14:15:36 -04:00
										 |  |  |       it "raises a `TypeError` if the `type` is not supported" do | 
					
						
							| 
									
										
										
										
											2021-01-31 13:14:23 -05:00
										 |  |  |         expect { linkage_cache.fetch(:bad_type) }.to raise_error(TypeError) | 
					
						
							| 
									
										
										
										
											2018-05-22 14:15:36 -04:00
										 |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | end |