Sha256: da68764b2b921f8772f7d0c3c181ff5d2fef48724071ed5ea50264cccc5c8e6a

Contents?: true

Size: 1.72 KB

Versions: 208

Compression:

Stored size: 1.72 KB

Contents

require "appsignal/cli/diagnose/utils"

describe Appsignal::CLI::Diagnose::Utils do
  describe ".username_for_uid" do
    subject { described_class.username_for_uid(uid) }

    context "when user with id exists" do
      let(:uid) { 0 }

      it "returns username" do
        is_expected.to be_kind_of(String)
      end
    end

    context "when user with id does not exist" do
      let(:uid) { -1 }

      it "returns nil" do
        is_expected.to be_nil
      end
    end
  end

  describe ".group_for_gid" do
    subject { described_class.group_for_gid(uid) }

    context "when group with id exists" do
      let(:uid) { 0 }

      it "returns group name" do
        is_expected.to be_kind_of(String)
      end
    end

    context "when group with id does not exist" do
      let(:uid) { -3 }

      it "returns nil" do
        is_expected.to be_nil
      end
    end
  end

  describe ".read_file_content" do
    let(:path) { File.join(spec_system_tmp_dir, "test_file.txt") }
    let(:bytes_to_read) { 100 }
    subject { described_class.read_file_content(path, bytes_to_read) }
    before do
      File.open path, "w+" do |f|
        f.write file_contents
      end
    end

    context "when file is bigger than read size" do
      let(:file_contents) do
        "".tap do |s|
          100.times do |i|
            s << "line #{i}\n"
          end
        end
      end

      it "returns the last X bytes" do
        is_expected
          .to eq(file_contents[(file_contents.length - bytes_to_read)..file_contents.length])
      end
    end

    context "when file is smaller than read size" do
      let(:file_contents) { "line 1\n" }

      it "returns the whole file content" do
        is_expected.to eq(file_contents)
      end
    end
  end
end

Version data entries

208 entries across 208 versions & 1 rubygems

Version Path
appsignal-3.3.11-java spec/lib/appsignal/cli/diagnose/utils_spec.rb
appsignal-3.3.11 spec/lib/appsignal/cli/diagnose/utils_spec.rb
appsignal-3.4.0-java spec/lib/appsignal/cli/diagnose/utils_spec.rb
appsignal-3.4.0 spec/lib/appsignal/cli/diagnose/utils_spec.rb
appsignal-3.3.10-java spec/lib/appsignal/cli/diagnose/utils_spec.rb
appsignal-3.3.10 spec/lib/appsignal/cli/diagnose/utils_spec.rb
appsignal-3.3.9-java spec/lib/appsignal/cli/diagnose/utils_spec.rb
appsignal-3.3.9 spec/lib/appsignal/cli/diagnose/utils_spec.rb
appsignal-3.3.8-java spec/lib/appsignal/cli/diagnose/utils_spec.rb
appsignal-3.3.8 spec/lib/appsignal/cli/diagnose/utils_spec.rb
appsignal-3.3.7-java spec/lib/appsignal/cli/diagnose/utils_spec.rb
appsignal-3.3.7 spec/lib/appsignal/cli/diagnose/utils_spec.rb
appsignal-3.3.6-java spec/lib/appsignal/cli/diagnose/utils_spec.rb
appsignal-3.3.6 spec/lib/appsignal/cli/diagnose/utils_spec.rb
appsignal-3.3.5-java spec/lib/appsignal/cli/diagnose/utils_spec.rb
appsignal-3.3.5 spec/lib/appsignal/cli/diagnose/utils_spec.rb
appsignal-3.3.4-java spec/lib/appsignal/cli/diagnose/utils_spec.rb
appsignal-3.3.4 spec/lib/appsignal/cli/diagnose/utils_spec.rb
appsignal-3.3.3-java spec/lib/appsignal/cli/diagnose/utils_spec.rb
appsignal-3.3.3 spec/lib/appsignal/cli/diagnose/utils_spec.rb