Fix cask source checksum handling
This commit is contained in:
		
							parent
							
								
									6c5da0dfe1
								
							
						
					
					
						commit
						326bc3f889
					
				@ -275,6 +275,7 @@ module Cask
 | 
			
		||||
      @ruby_source_path = sourcefile_path.relative_path_from(tap.path)
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    sig { returns(T::Hash[Symbol, String]) }
 | 
			
		||||
    def ruby_source_checksum
 | 
			
		||||
      @ruby_source_checksum ||= {
 | 
			
		||||
        sha256: Digest::SHA256.file(sourcefile_path).hexdigest,
 | 
			
		||||
@ -300,7 +301,7 @@ module Cask
 | 
			
		||||
      # TODO: Clean this up when we deprecate the current JSON API and move to the internal JSON v3.
 | 
			
		||||
      ruby_source_sha256 = json_cask.dig(:ruby_source_checksum, :sha256)
 | 
			
		||||
      ruby_source_sha256 ||= json_cask[:ruby_source_sha256]
 | 
			
		||||
      @ruby_source_checksum = { "sha256" => ruby_source_sha256 }
 | 
			
		||||
      @ruby_source_checksum = { sha256: ruby_source_sha256 }
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    def to_s
 | 
			
		||||
 | 
			
		||||
@ -45,4 +45,30 @@ RSpec.describe Homebrew::API::Cask do
 | 
			
		||||
      expect(casks_output).to eq casks_hash
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  describe "::source_download", :needs_macos do
 | 
			
		||||
    let(:cask) do
 | 
			
		||||
      cask = Cask::CaskLoader::FromAPILoader.new(
 | 
			
		||||
        "everything",
 | 
			
		||||
        from_json: JSON.parse((TEST_FIXTURE_DIR/"cask/everything.json").read.strip),
 | 
			
		||||
      ).load(config: nil)
 | 
			
		||||
      cask
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    before do
 | 
			
		||||
      allow_any_instance_of(Homebrew::API::Download).to receive(:fetch)
 | 
			
		||||
      allow_any_instance_of(Homebrew::API::Download).to receive(:symlink_location).and_return(
 | 
			
		||||
        TEST_FIXTURE_DIR/"cask/Casks/everything.rb",
 | 
			
		||||
      )
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    it "specifies the correct URL and sha256" do
 | 
			
		||||
      expect(Homebrew::API::Download).to receive(:new).with(
 | 
			
		||||
        "https://raw.githubusercontent.com/Homebrew/homebrew-cask/abcdef1234567890abcdef1234567890abcdef12/Casks/everything.rb",
 | 
			
		||||
        Checksum.new("d8d0d6b2e5ff65388eccb82236fd3aa157b4a29bb043a1f72b97f0e9b70e8320"),
 | 
			
		||||
        any_args,
 | 
			
		||||
      ).and_call_original
 | 
			
		||||
      described_class.source_download(cask)
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
@ -219,7 +219,11 @@ RSpec.describe Cask::Cask, :cask do
 | 
			
		||||
      it "returns expected hash" do
 | 
			
		||||
        allow(MacOS).to receive(:version).and_return(MacOSVersion.new("13"))
 | 
			
		||||
 | 
			
		||||
        hash = Cask::CaskLoader.load("everything").to_h
 | 
			
		||||
        cask = Cask::CaskLoader.load("everything")
 | 
			
		||||
 | 
			
		||||
        expect(cask.tap).to receive(:git_head).and_return("abcdef1234567890abcdef1234567890abcdef12")
 | 
			
		||||
 | 
			
		||||
        hash = cask.to_h
 | 
			
		||||
 | 
			
		||||
        expect(hash).to be_a(Hash)
 | 
			
		||||
        expect(JSON.pretty_generate(hash)).to eq(expected_json)
 | 
			
		||||
 | 
			
		||||
@ -96,7 +96,7 @@
 | 
			
		||||
  "disabled": false,
 | 
			
		||||
  "disable_date": null,
 | 
			
		||||
  "disable_reason": null,
 | 
			
		||||
  "tap_git_head": null,
 | 
			
		||||
  "tap_git_head": "abcdef1234567890abcdef1234567890abcdef12",
 | 
			
		||||
  "languages": [
 | 
			
		||||
    "en",
 | 
			
		||||
    "eo"
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user