Skip to content

Commit

Permalink
Add uuidish field in snapshot tests
Browse files Browse the repository at this point in the history
Follow #341
  • Loading branch information
kachick committed Mar 20, 2024
1 parent d7fdafb commit 07619a2
Show file tree
Hide file tree
Showing 5 changed files with 3,026 additions and 7 deletions.
21 changes: 21 additions & 0 deletions scripts/add_uuidish_in_snapshots.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# coding: us-ascii
# frozen_string_literal: true

require('bundler/setup')
require_relative('../lib/ulid')
require_relative('../test/many_data/fixtures/example')
require('perfect_toml')

# Needless to rollback. This is rough script.
ENV['TZ'] = 'UTC'

path = ARGV.first
parsed_hash = PerfectTOML.load_file(path, symbolize_names: true)
updated_hash = parsed_hash.transform_values { |table|
ulid = ULID.from_integer(table.fetch(:integer))
# Specifying some redundant attributes to adjust the key order
table.delete(:uuidv4)
table.delete(:octets)
table.merge(uuidish: ulid.to_uuidish, uuidv4: ulid.to_uuidv4(force: true), octets: ulid.octets)
}
PerfectTOML.save_file(path, updated_hash)
1 change: 1 addition & 0 deletions scripts/generate_snapshots.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
randomness: ulid.randomness,
octets: ulid.octets,
inspect: ulid.inspect,
uuidish: ulid.to_uuidish,
uuidv4: ulid.to_uuidv4(force: true)
)
end
Expand Down
2 changes: 1 addition & 1 deletion test/many_data/fixtures/example.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@

# The to_time should be less than 10000: https://github.com/toml-lang/toml/blob/2431aa308a7bc97eeb50673748606e23a6e0f201/toml.abnf#L180
# period is derepcated since it cannot be serialize in TOML
Example = Data.define(:string, :integer, :timestamp, :randomness, :period, :to_time, :inspect, :uuidv4, :octets)
Example = Data.define(:string, :integer, :timestamp, :randomness, :period, :to_time, :inspect, :uuidish, :uuidv4, :octets)
Loading

0 comments on commit 07619a2

Please sign in to comment.