Skip to content

Commit

Permalink
More tests
Browse files Browse the repository at this point in the history
  • Loading branch information
moseshll committed Oct 23, 2023
1 parent a8f931f commit 2975b32
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 2 deletions.
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ services:
- mariadb

mariadb:
image: ghcr.io/hathitrust/db-image
image: mariadb:latest
#volumes:
# - ./sql/100_rights_log.sql:/docker-entrypoint-initdb.d/100_rights_log.sql
restart: always
Expand Down
2 changes: 1 addition & 1 deletion lib/hathifiles_database/db/migrations/001_create.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
String :author, text: true
end

FOREIGN_TABLES.values.each do |table|
HathifilesDatabase::Constants::FOREIGN_TABLES.values.each do |table|
create_table(table, collate: "utf8_general_ci", charset: "utf8") do
String :htid, null: false
String :value, null: false
Expand Down
21 changes: 21 additions & 0 deletions spec/connection_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
require_relative "../lib/hathifiles_database/db/connection"

RSpec.describe HathifilesDatabase::DB::Connection do
let(:conn) { described_class.new(ENV["HATHIFILES_MYSQL_CONNECTION"]) }

describe "#initialize" do
it "can create a connection" do
expect(conn).to be_a HathifilesDatabase::DB::Connection
end
end

describe "#recreate_tables!" do
it "does not raise an exception" do
conn.recreate_tables!
expect(conn.rawdb.table_exists?(HathifilesDatabase::Constants::MAINTABLE)).to be true
HathifilesDatabase::Constants::FOREIGN_TABLES.each do |_k, table|
expect(conn.rawdb.table_exists?(table)).to be true
end
end
end
end
32 changes: 32 additions & 0 deletions spec/datafile_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
require "tmpdir"
require_relative "../lib/hathifiles_database/datafile"

RSpec.describe HathifilesDatabase::Datafile do
let(:txt_datafile_path) { data_file_path "sample_10.txt" }
let(:gz_datafile_path) { data_file_path "sample_100.txt.gz" }
let(:txt_datafile) { described_class.new(txt_datafile_path) }
let(:gz_datafile) { described_class.new(txt_datafile_path) }
let(:all_tables) { [HathifilesDatabase::Constants::MAINTABLE] + HathifilesDatabase::Constants::FOREIGN_TABLES.values }

describe "#initialize" do
it "can create a .txt datafile" do
expect(txt_datafile).to be_a HathifilesDatabase::Datafile
end

it "can create a .txt.gz datafile" do
expect(gz_datafile).to be_a HathifilesDatabase::Datafile
end
end

describe "#dump_files_for_data_import" do
it "writes a file for each table" do
Dir.mktmpdir do |dir|
files_written = gz_datafile.dump_files_for_data_import dir
all_tables.each do |table|
expect(files_written.key?(table)).to be true
expect(File.exist?(files_written[table])).to be true
end
end
end
end
end

0 comments on commit 2975b32

Please sign in to comment.