mock_proc_files

in spec/elastic_apm/metrics/cpu_mem_set_spec.rb [94:122]


      def mock_proc_files(
        user: 6_410_558,
        idle: 329_434_672,
        utime: 7,
        stime: 0,
        proc_stat_format: :debian,
        proc_meminfo_format: nil
      )
        allow_any_instance_of(ElasticAPM::Metrics::CpuMemSet::Linux::Meminfo).
          to receive(:`).with('getconf PAGESIZE').and_return('8192')
        {
          '/proc/stat' =>
            ["proc_stat_#{proc_stat_format}", { user: user, idle: idle }],
          '/proc/self/stat' =>
            ['proc_self_stat', { utime: utime, stime: stime }],
          '/proc/meminfo' =>
            [
              "proc_meminfo#{proc_meminfo_format && "_
              {}
            ]
        }.each do |file, (fixture, updates)|
          allow(IO).to receive(:readlines).with(file) do
            text = File.read("spec/fixtures/#{fixture}")
            updates.each { |key, val| text.gsub!("{#{key}}", val.to_s) }
            text.split("\n")
          end
        end
      end