-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Sergio Schvezov <[email protected]>
- Loading branch information
1 parent
7927565
commit d709994
Showing
1 changed file
with
99 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
# -*- Mode:Python; indent-tabs-mode:nil; tab-width:4 -*- | ||
# | ||
# Copyright 2021 Canonical Ltd. | ||
# | ||
# This program is free software; you can redistribute it and/or | ||
# modify it under the terms of the GNU Lesser General Public | ||
# License version 3 as published by the Free Software Foundation. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
# Lesser General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU Lesser General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
import re | ||
import subprocess | ||
import textwrap | ||
from pathlib import Path | ||
|
||
import pytest | ||
import yaml | ||
from craft_parts import LifecycleManager, Step | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def go_version(): | ||
output = subprocess.run( | ||
["go", "version"], check=True, capture_output=True | ||
).stdout.decode() | ||
return re.match(r"go version go([\d.]+)", output).group(1) | ||
|
||
|
||
def test_go_workspace_use(new_dir, partitions, go_version): | ||
parts_yaml = textwrap.dedent( | ||
""" | ||
parts: | ||
go-flags: | ||
source: https://github.com/jessevdk/go-flags.git | ||
plugin: go-use | ||
""" | ||
) | ||
parts = yaml.safe_load(parts_yaml) | ||
lf = LifecycleManager( | ||
parts, | ||
application_name="test_go", | ||
cache_dir=new_dir, | ||
work_dir=new_dir, | ||
partitions=partitions, | ||
) | ||
actions = lf.plan(Step.PRIME) | ||
|
||
with lf.action_executor() as ctx: | ||
ctx.execute(actions) | ||
|
||
go_work = (new_dir / "parts" / "go.work").read_text(encoding="utf-8") | ||
assert go_work == textwrap.dedent(f"""\ | ||
go {go_version} | ||
use {new_dir}/parts/go-flags/src | ||
""") | ||
|
||
|
||
def test_go_workspace_use_multiple(new_dir, partitions, go_version): | ||
parts_yaml = textwrap.dedent( | ||
""" | ||
parts: | ||
go-flags: | ||
source: https://github.com/jessevdk/go-flags.git | ||
plugin: go-use | ||
go-starlark: | ||
source: https://github.com/google/starlark-go.git | ||
plugin: go-use | ||
after: [go-flags] | ||
""" | ||
) | ||
parts = yaml.safe_load(parts_yaml) | ||
lf = LifecycleManager( | ||
parts, | ||
application_name="test_go", | ||
cache_dir=new_dir, | ||
work_dir=new_dir, | ||
partitions=partitions, | ||
) | ||
actions = lf.plan(Step.PRIME) | ||
|
||
with lf.action_executor() as ctx: | ||
ctx.execute(actions) | ||
|
||
go_work = (new_dir / "parts" / "go.work").read_text(encoding="utf-8") | ||
assert go_work == textwrap.dedent(f"""\ | ||
go {go_version} | ||
use ( | ||
\t{new_dir}/parts/go-flags/src | ||
\t{new_dir}/parts/go-starlark/src | ||
) | ||
""") |