Skip to content

Commit

Permalink
[service] Adapt to changes in master
Browse files Browse the repository at this point in the history
  • Loading branch information
joseivanlopez committed Nov 3, 2023
1 parent d14ae23 commit ba7f482
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 61 deletions.
5 changes: 3 additions & 2 deletions service/lib/agama/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ def merge(config)
# Elements that match the current arch.
#
# @example
# config.pure_data = {
# config.products #=>
# {
# "ALP-Dolomite" => {
# "software" => {
# "installation_repositories" => [
Expand Down Expand Up @@ -171,7 +172,7 @@ def merge(config)
# @return [Array]
def arch_elements_from(*keys, property: nil)
keys.map!(&:to_s)
elements = pure_data.dig(*keys)
elements = products.dig(*keys)
return [] unless elements.is_a?(Array)

elements.map do |element|
Expand Down
2 changes: 1 addition & 1 deletion service/lib/agama/dbus/software/product.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class Product < BaseObject
PATH = "/org/opensuse/Agama/Software1/Product"
private_constant :PATH

# @param backend [Agama::Software]
# @param backend [Agama::Software::Manager]
# @param logger [Logger]
def initialize(backend, logger)
super(PATH, logger: logger)
Expand Down
4 changes: 3 additions & 1 deletion service/lib/agama/software/manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,9 @@ def initialize(config, logger)
# @raise {ArgumentError} If id is unknown.
#
# @param id [String]
# @return [Boolean] true on success.
def select_product(id)
return if id == product&.id
return false if id == product&.id

new_product = @products.find { |p| p.id == id }

Expand All @@ -111,6 +112,7 @@ def select_product(id)
@product = new_product
repositories.delete_all
update_issues
true
end

def probe
Expand Down
4 changes: 2 additions & 2 deletions service/lib/agama/software/product_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ def build
# @return [Hash]
def product_data_from_config(id)
{
name: config.pure_data.dig(id, "software", "base_product"),
version: config.pure_data.dig(id, "software", "version"),
name: config.products.dig(id, "software", "base_product"),
version: config.products.dig(id, "software", "version"),
repositories: config.arch_elements_from(
id, "software", "installation_repositories", property: :url
),
Expand Down
45 changes: 28 additions & 17 deletions service/test/agama/config_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
require_relative "../test_helper"
require "yast"
require "agama/config"
require "agama/product_reader"

Yast.import "Arch"

Expand Down Expand Up @@ -133,15 +134,22 @@
end

describe "#arch_elements_from" do
subject { described_class.new(data) }
subject { described_class.new }

before do
allow(Agama::ProductReader).to receive(:new).and_return(reader)
end

let(:reader) { instance_double(Agama::ProductReader, load_products: products) }

context "when the given set of keys does not match any data" do
let(:data) do
{
"Product1" => {
let(:products) do
[
{
"id" => "Product1",
"name" => "Test product 1"
}
}
]
end

it "returns an empty array" do
Expand All @@ -150,12 +158,13 @@
end

context "when the given set of keys does not contain a collection" do
let(:data) do
{
"Product1" => {
let(:products) do
[
{
"id" => "Product1",
"name" => "Test product 1"
}
}
]
end

it "returns an empty array" do
Expand All @@ -164,9 +173,10 @@
end

context "when the given set of keys contains a collection" do
let(:data) do
{
"Product1" => {
let(:products) do
[
{
"id" => "Product1",
"some" => {
"collection" => [
"element1",
Expand All @@ -188,7 +198,7 @@
]
}
}
}
]
end

before do
Expand All @@ -209,9 +219,10 @@
end

context "and there are no elements matching the current arch" do
let(:data) do
{
"Product1" => {
let(:products) do
[
{
"id" => "Product1",
"some" => {
"collection" => [
{
Expand All @@ -225,7 +236,7 @@
]
}
}
}
]
end

it "returns an empty list" do
Expand Down
14 changes: 7 additions & 7 deletions service/test/agama/dbus/software/product_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,17 @@

let(:backend) { Agama::Software::Manager.new(config, logger) }

let(:config) { Agama::Config.new(config_data) }

let(:config_data) do
path = File.join(FIXTURES_PATH, "root_dir/etc/agama.yaml")
YAML.safe_load(File.read(path))
end
let(:config) { Agama::Config.new }

before do
allow(config).to receive(:products).and_return(products)
allow(subject).to receive(:dbus_properties_changed)
end

let(:products) do
{ "Tumbleweed" => {}, "ALP-Dolomite" => {} }
end

it "defines Product D-Bus interface" do
expect(subject.intfs.keys).to include("org.opensuse.Agama.Software1.Product")
end
Expand Down Expand Up @@ -75,7 +75,7 @@

context "if the current product is registered" do
before do
subject.select_product("Leap")
subject.select_product("Leap16")
allow(backend.registration).to receive(:reg_code).and_return("123XX432")
end

Expand Down
7 changes: 3 additions & 4 deletions service/test/agama/software/manager_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@

shared_examples "software issues" do |tested_method|
before do
subject.select_product("Tumbleweed")
allow(subject.registration).to receive(:reg_code).and_return(reg_code)
end

Expand Down Expand Up @@ -192,7 +191,7 @@
stub_const("Agama::Software::Manager::REPOS_DIR", repos_dir)
stub_const("Agama::Software::Manager::REPOS_BACKUP", backup_repos_dir)
FileUtils.mkdir_p(repos_dir)
subject.select_product("Tumbleweed")
subject.select_product("ALP-Dolomite")
end

after do
Expand Down Expand Up @@ -233,9 +232,9 @@
expect(products.size).to eq(3)
expect(products).to all(be_a(Agama::Software::Product))
expect(products).to contain_exactly(
an_object_having_attributes(id: "ALP-Dolomite"),
an_object_having_attributes(id: "Tumbleweed"),
an_object_having_attributes(id: "Leap Micro"),
an_object_having_attributes(id: "Leap")
an_object_having_attributes(id: "Leap16")
)
end
end
Expand Down
56 changes: 29 additions & 27 deletions service/test/agama/software/product_builder_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,36 +22,26 @@
require_relative "../../test_helper"
require "yast"
require "agama/config"
require "agama/product_reader"
require "agama/software/product"
require "agama/software/product_builder"

Yast.import "Arch"

describe Agama::Software::ProductBuilder do
subject { described_class.new(config) }
before do
allow(Agama::ProductReader).to receive(:new).and_return(reader)
end

let(:config) { Agama::Config.new(data) }
let(:reader) { instance_double(Agama::ProductReader, load_products: products) }

let(:data) do
{
"products" => {
"Test1" => {
"name" => "Product Test 1",
"description" => "This is a test product named Test 1"
},
"Test2" => {
"name" => "Product Test 2",
"description" => "This is a test product named Test 2",
"archs" => "x86_64,aarch64"
},
"Test3" => {
"name" => "Product Test 3",
"description" => "This is a test product named Test 3",
"archs" => "ppc64,aarch64"
}
},
"Test1" => {
"software" => {
let(:products) do
[
{
"id" => "Test1",
"name" => "Product Test 1",
"description" => "This is a test product named Test 1",
"software" => {
"installation_repositories" => [
{
"url" => "https://repos/test1/x86_64/product/",
Expand Down Expand Up @@ -92,15 +82,23 @@
"version" => "1.0"
}
},
"Test2" => {
"software" => {
{
"id" => "Test2",
"name" => "Product Test 2",
"description" => "This is a test product named Test 2",
"archs" => "x86_64,aarch64",
"software" => {
"mandatory_patterns" => ["pattern2-1"],
"base_product" => "Test2",
"version" => "2.0"
}
},
"Test3" => {
"software" => {
{
"id" => "Test3",
"name" => "Product Test 3",
"description" => "This is a test product named Test 3",
"archs" => "ppc64,aarch64",
"software" => {
"installation_repositories" => ["https://repos/test3/product/"],
"optional_patterns" => [
{
Expand All @@ -111,9 +109,13 @@
"base_product" => "Test3"
}
}
}
]
end

subject { described_class.new(config) }

let(:config) { Agama::Config.new }

describe "#build" do
context "for x86_64" do
before do
Expand Down

0 comments on commit ba7f482

Please sign in to comment.