Sha256: 2133952f2e8d12f065b985e9a6788afdc8071bb102da086bdaea5b6bf3380c63

Contents?: true

Size: 1.69 KB

Versions: 34

Compression:

Stored size: 1.69 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.write(path, file_contents)
    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

34 entries across 34 versions & 1 rubygems

Version Path
appsignal-3.5.0-java spec/lib/appsignal/cli/diagnose/utils_spec.rb
appsignal-3.5.0 spec/lib/appsignal/cli/diagnose/utils_spec.rb
appsignal-3.4.16-java spec/lib/appsignal/cli/diagnose/utils_spec.rb
appsignal-3.4.16 spec/lib/appsignal/cli/diagnose/utils_spec.rb
appsignal-3.4.15-java spec/lib/appsignal/cli/diagnose/utils_spec.rb
appsignal-3.4.15 spec/lib/appsignal/cli/diagnose/utils_spec.rb
appsignal-3.4.14-java spec/lib/appsignal/cli/diagnose/utils_spec.rb
appsignal-3.4.14 spec/lib/appsignal/cli/diagnose/utils_spec.rb
appsignal-3.4.13-java spec/lib/appsignal/cli/diagnose/utils_spec.rb
appsignal-3.4.13 spec/lib/appsignal/cli/diagnose/utils_spec.rb
appsignal-3.4.12-java spec/lib/appsignal/cli/diagnose/utils_spec.rb
appsignal-3.4.12 spec/lib/appsignal/cli/diagnose/utils_spec.rb
appsignal-3.4.11-java spec/lib/appsignal/cli/diagnose/utils_spec.rb
appsignal-3.4.11 spec/lib/appsignal/cli/diagnose/utils_spec.rb
appsignal-3.4.10-java spec/lib/appsignal/cli/diagnose/utils_spec.rb
appsignal-3.4.10 spec/lib/appsignal/cli/diagnose/utils_spec.rb
appsignal-3.4.9-java spec/lib/appsignal/cli/diagnose/utils_spec.rb
appsignal-3.4.9 spec/lib/appsignal/cli/diagnose/utils_spec.rb
appsignal-3.4.8-java spec/lib/appsignal/cli/diagnose/utils_spec.rb
appsignal-3.4.8 spec/lib/appsignal/cli/diagnose/utils_spec.rb