|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +require "spec_helper" |
| 4 | + |
| 5 | +RSpec.describe Weaviate::Backups do |
| 6 | + let(:client) { |
| 7 | + Weaviate::Client.new( |
| 8 | + scheme: "http", |
| 9 | + host: "localhost:8080" |
| 10 | + ) |
| 11 | + } |
| 12 | + |
| 13 | + let(:backups) { client.backups } |
| 14 | + let(:backup_fixture) { JSON.parse(File.read("spec/fixtures/backup.json")) } |
| 15 | + |
| 16 | + describe "#create" do |
| 17 | + let(:response) { OpenStruct.new(success?: true, body: backup_fixture) } |
| 18 | + |
| 19 | + before do |
| 20 | + allow_any_instance_of(Faraday::Connection).to receive(:post) |
| 21 | + .with("backups/filesystem") |
| 22 | + .and_return(response) |
| 23 | + end |
| 24 | + |
| 25 | + it "creates the backup" do |
| 26 | + response = backups.create( |
| 27 | + backend: "filesystem", |
| 28 | + id: "my-first-backup", |
| 29 | + include: ["Question"] |
| 30 | + ) |
| 31 | + expect(response["id"]).to eq("my-first-backup") |
| 32 | + expect(response["status"]).to eq("STARTED") |
| 33 | + end |
| 34 | + end |
| 35 | + |
| 36 | + describe "#get" do |
| 37 | + let(:response) { OpenStruct.new(success?: true, body: backup_fixture) } |
| 38 | + |
| 39 | + before do |
| 40 | + allow_any_instance_of(Faraday::Connection).to receive(:get) |
| 41 | + .with("backups/filesystem/my-first-backup") |
| 42 | + .and_return(response) |
| 43 | + end |
| 44 | + |
| 45 | + it "returns the backup" do |
| 46 | + response = backups.get( |
| 47 | + backend: "filesystem", |
| 48 | + id: "my-first-backup" |
| 49 | + ) |
| 50 | + expect(response["id"]).to eq("my-first-backup") |
| 51 | + end |
| 52 | + end |
| 53 | + |
| 54 | + describe "#restore" do |
| 55 | + let(:response) { OpenStruct.new(success?: true, body: backup_fixture) } |
| 56 | + |
| 57 | + before do |
| 58 | + allow_any_instance_of(Faraday::Connection).to receive(:post) |
| 59 | + .with("backups/filesystem/my-first-backup/restore") |
| 60 | + .and_return(response) |
| 61 | + end |
| 62 | + |
| 63 | + it "restores the backup" do |
| 64 | + response = backups.restore( |
| 65 | + backend: "filesystem", |
| 66 | + id: "my-first-backup", |
| 67 | + include: ["Question"] |
| 68 | + ) |
| 69 | + expect(response["id"]).to eq("my-first-backup") |
| 70 | + expect(response["status"]).to eq("STARTED") |
| 71 | + end |
| 72 | + end |
| 73 | + |
| 74 | + describe "#restore_status" do |
| 75 | + let(:response) { OpenStruct.new(success?: true, body: backup_fixture) } |
| 76 | + |
| 77 | + before do |
| 78 | + allow_any_instance_of(Faraday::Connection).to receive(:get) |
| 79 | + .with("backups/filesystem/my-first-backup/restore") |
| 80 | + .and_return(response) |
| 81 | + end |
| 82 | + |
| 83 | + it "returns the restore status" do |
| 84 | + response = backups.restore_status( |
| 85 | + backend: "filesystem", |
| 86 | + id: "my-first-backup" |
| 87 | + ) |
| 88 | + expect(response["id"]).to eq("my-first-backup") |
| 89 | + end |
| 90 | + end |
| 91 | +end |
0 commit comments