Skip to content

Commit

Permalink
Adapt file parser specs to recent changes
Browse files Browse the repository at this point in the history
Also, add the wanted version as a pinned requirement for now.
  • Loading branch information
deivid-rodriguez committed Dec 21, 2023
1 parent 62c0470 commit fb46440
Show file tree
Hide file tree
Showing 3 changed files with 190 additions and 134 deletions.
1 change: 1 addition & 0 deletions devcontainers/lib/dependabot/devcontainers/file_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
require "dependabot/dependency"
require "dependabot/file_parsers"
require "dependabot/file_parsers/base"
require "dependabot/devcontainers/version"
require "dependabot/devcontainers/file_parser/feature_dependency_parser"

module Dependabot
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def parse_cli_json(json)
package_manager: "devcontainers",
requirements: [
{
requirement: Requirement.new(["~> #{latest_major}"]), # TODO?
requirement: wanted,
file: config_dependency_file.name,
groups: ["feature"],
source: nil,
Expand Down
321 changes: 188 additions & 133 deletions devcontainers/spec/dependabot/devcontainers/file_parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,11 @@
end

let(:files) do
[
config_file
]
project_dependency_files(project_name, directory: directory)
end

let(:repo_contents_path) { build_tmp_repo(project_name, path: "projects") }

let(:config_file) do
Dependabot::DependencyFile.new(
name: config_file_name,
content: fixture("projects", project_name, directory, config_file_name)
)
end

let(:dependencies) { parser.parse }

shared_examples_for "parse" do
Expand All @@ -59,150 +50,214 @@

context "with a .devcontainer.json in repo root" do
let(:project_name) { "config_in_root" }
let(:config_file_name) { ".devcontainer.json" }
let(:directory) { "/" }

let(:expectations) do
EXPECTED_PARSE_FROM_ROOT_DEV_CONTAINER
[
{
name: "ghcr.io/codspace/versioning/foo:1",
version: "1.1.0",
requirements: [
{
requirement: "1.1.0",
file: ".devcontainer.json",
groups: ["feature"],
source: nil,
metadata: {
wanted: "1.1.0",
latest: "2.11.1",
latest_major: "2",
wanted_major: "1"
}
}
],
metadata: {}
},
{
name: "ghcr.io/codspace/versioning/bar:1",
version: "1.0.0",
requirements: [
{
requirement: "1.0.0",
file: ".devcontainer.json",
groups: ["feature"],
source: nil,
metadata: {
wanted: "1.0.0",
latest: "1.0.0",
latest_major: "1",
wanted_major: "1"
}
}
],
metadata: {}
}
].freeze
end

it_behaves_like "parse"
end

context "with a devcontainer.json in a .devcontainer folder" do
let(:project_name) { "config_in_dot_devcontainer_folder" }
let(:config_file_name) { "devcontainer.json" }
let(:directory) { "/.devcontainer" }
let(:directory) { "/" }

let(:expectations) do
EXPECTED_PARSE_FROM_NESTED_DEV_CONTAINER
[
{
name: "ghcr.io/codspace/versioning/foo:1",
version: "1.1.0",
requirements: [
{
requirement: "1.1.0",
file: ".devcontainer/devcontainer.json",
groups: ["feature"],
source: nil,
metadata: {
wanted: "1.1.0",
latest: "2.11.1",
latest_major: "2",
wanted_major: "1"
}
}
],
metadata: {}
},
{
name: "ghcr.io/codspace/versioning/bar:1",
version: "1.0.0",
requirements: [
{
requirement: "1.0.0",
file: ".devcontainer/devcontainer.json",
groups: ["feature"],
source: nil,
metadata: {
wanted: "1.0.0",
latest: "1.0.0",
latest_major: "1",
wanted_major: "1"
}
}
],
metadata: {}
},
{
name: "ghcr.io/codspace/versioning/baz:1.0",
version: "1.0.0",
requirements: [
{
requirement: "1.0.0",
file: ".devcontainer/devcontainer.json",
groups: ["feature"],
source: nil,
metadata: {
wanted: "1.0.0",
latest: "2.0.0",
latest_major: "2",
wanted_major: "1"
}
}
],
metadata: {}
}
].freeze
end

it_behaves_like "parse"
end

context "with multiple, valid devcontainer.json config files in repo" do
describe("with devcontainer.json in a .devcontainer folder") do
let(:project_name) { "multiple_configs" }
let(:config_file_name) { "devcontainer.json" }
let(:directory) { "/.devcontainer" }
let(:project_name) { "multiple_configs" }
let(:directory) { "/" }

let(:expectations) do
EXPECTED_PARSE_FROM_NESTED_DEV_CONTAINER
end
it_behaves_like "parse"
let(:expectations) do
[
{
name: "ghcr.io/codspace/versioning/foo:1",
version: "1.1.0",
requirements: [
{
requirement: "1.1.0",
file: ".devcontainer/devcontainer.json",
groups: ["feature"],
source: nil,
metadata: {
wanted: "1.1.0",
latest: "2.11.1",
latest_major: "2",
wanted_major: "1"
}
},
{
requirement: "1.1.0",
file: ".devcontainer.json",
groups: ["feature"],
source: nil,
metadata: {
wanted: "1.1.0",
latest: "2.11.1",
latest_major: "2",
wanted_major: "1"
}
}
],
metadata: {}
},
{
name: "ghcr.io/codspace/versioning/bar:1",
version: "1.0.0",
requirements: [
{
requirement: "1.0.0",
file: ".devcontainer/devcontainer.json",
groups: ["feature"],
source: nil,
metadata: {
wanted: "1.0.0",
latest: "1.0.0",
latest_major: "1",
wanted_major: "1"
}
},
{
requirement: "1.0.0",
file: ".devcontainer.json",
groups: ["feature"],
source: nil,
metadata: {
wanted: "1.0.0",
latest: "1.0.0",
latest_major: "1",
wanted_major: "1"
}
}
],
metadata: {}
},
{
name: "ghcr.io/codspace/versioning/baz:1.0",
version: "1.0.0",
requirements: [
{
requirement: "1.0.0",
file: ".devcontainer/devcontainer.json",
groups: ["feature"],
source: nil,
metadata: {
wanted: "1.0.0",
latest: "2.0.0",
latest_major: "2",
wanted_major: "1"
}
}
],
metadata: {}
}
].freeze
end

describe("with a .devcontainer.json in repo root") do
let(:project_name) { "multiple_configs" }
let(:config_file_name) { ".devcontainer.json" }
let(:directory) { "/" }

let(:expectations) do
EXPECTED_PARSE_FROM_ROOT_DEV_CONTAINER
end
it_behaves_like "parse"
end
it_behaves_like "parse"
end
end

EXPECTED_PARSE_FROM_ROOT_DEV_CONTAINER = [
{
name: "ghcr.io/codspace/versioning/foo:1",
version: "1.1.0",
requirements: [
{
requirement: Dependabot::Devcontainers::Requirement.new(["~> 2"]),
file: ".devcontainer.json",
groups: ["feature"],
source: nil,
metadata: {
wanted: "1.1.0",
latest: "2.11.1",
latest_major: "2",
wanted_major: "1"
}
}
],
metadata: {}
},
{
name: "ghcr.io/codspace/versioning/bar:1",
version: "1.0.0",
requirements: [
{
requirement: Dependabot::Devcontainers::Requirement.new(["~> 1"]),
file: ".devcontainer.json",
groups: ["feature"],
source: nil,
metadata: {
wanted: "1.0.0",
latest: "1.0.0",
latest_major: "1",
wanted_major: "1"
}
}
],
metadata: {}
}
].freeze

EXPECTED_PARSE_FROM_NESTED_DEV_CONTAINER = [
{
name: "ghcr.io/codspace/versioning/foo:1",
version: "1.1.0",
requirements: [
{
requirement: Dependabot::Devcontainers::Requirement.new(["~> 2"]),
file: "devcontainer.json",
groups: ["feature"],
source: nil,
metadata: {
wanted: "1.1.0",
latest: "2.11.1",
latest_major: "2",
wanted_major: "1"
}
}
],
metadata: {}
},
{
name: "ghcr.io/codspace/versioning/bar:1",
version: "1.0.0",
requirements: [
{
requirement: Dependabot::Devcontainers::Requirement.new(["~> 1"]),
file: "devcontainer.json",
groups: ["feature"],
source: nil,
metadata: {
wanted: "1.0.0",
latest: "1.0.0",
latest_major: "1",
wanted_major: "1"
}
}
],
metadata: {}
},
{
name: "ghcr.io/codspace/versioning/baz:1.0",
version: "1.0.0",
requirements: [
{
requirement: Dependabot::Devcontainers::Requirement.new(["~> 2"]),
file: "devcontainer.json",
groups: ["feature"],
source: nil,
metadata: {
wanted: "1.0.0",
latest: "2.0.0",
latest_major: "2",
wanted_major: "1"
}
}
],
metadata: {}
}
].freeze

0 comments on commit fb46440

Please sign in to comment.