test/fake_home.rb in zold-0.15.0 vs test/fake_home.rb in zold-0.16.0
- old
+ new
@@ -19,44 +19,47 @@
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
require 'tmpdir'
+require_relative '../lib/zold/log'
require_relative '../lib/zold/id'
require_relative '../lib/zold/wallet'
require_relative '../lib/zold/wallets'
require_relative '../lib/zold/sync_wallets'
+require_relative '../lib/zold/cached_wallets'
require_relative '../lib/zold/key'
require_relative '../lib/zold/version'
require_relative '../lib/zold/remotes'
# Fake home dir.
# Author:: Yegor Bugayenko (yegor256@gmail.com)
# Copyright:: Copyright (c) 2018 Yegor Bugayenko
# License:: MIT
class FakeHome
attr_reader :dir
- def initialize(dir = __dir__)
+ def initialize(dir = __dir__, log: Zold::Log::Quiet.new)
@dir = dir
+ @log = log
end
def run
Dir.mktmpdir do |dir|
- FileUtils.copy(File.join(__dir__, '../fixtures/id_rsa'), File.join(dir, 'id_rsa'))
- yield FakeHome.new(dir)
+ FileUtils.copy(File.expand_path(File.join(__dir__, '../fixtures/id_rsa')), File.join(dir, 'id_rsa'))
+ yield FakeHome.new(dir, log: @log)
end
end
def wallets
- Zold::SyncWallets.new(Zold::Wallets.new(@dir), File.join(@dir, 'locks'))
+ Zold::SyncWallets.new(Zold::CachedWallets.new(Zold::Wallets.new(@dir)), log: @log)
end
def create_wallet(id = Zold::Id.new, dir = @dir)
- target = Zold::Wallet.new(File.join(dir, id.to_s))
+ target = Zold::Wallet.new(File.join(dir, id.to_s + Zold::Wallet::EXT))
wallets.find(id) do |w|
- w.init(id, Zold::Key.new(file: File.join(__dir__, '../fixtures/id_rsa.pub')))
- File.write(target.path, File.read(w.path))
+ w.init(id, Zold::Key.new(file: File.expand_path(File.join(__dir__, '../fixtures/id_rsa.pub'))))
+ IO.write(target.path, IO.read(w.path))
end
target
end
def create_wallet_json(id = Zold::Id.new)
@@ -71,10 +74,10 @@
score: score.to_h,
wallets: 1,
mtime: wallet.mtime.utc.iso8601,
digest: wallet.digest,
balance: wallet.balance.to_i,
- body: File.read(wallet.path)
+ body: IO.read(wallet.path)
}.to_json
end
end
def copies(wallet = create_wallet)