Skip to content

Commit

Permalink
feat: integration tests for go-use
Browse files Browse the repository at this point in the history
Signed-off-by: Sergio Schvezov <[email protected]>
  • Loading branch information
sergiusens committed Oct 17, 2024
1 parent 7927565 commit d709994
Showing 1 changed file with 99 additions and 0 deletions.
99 changes: 99 additions & 0 deletions tests/integration/plugins/test_go_use.py
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
)
""")

0 comments on commit d709994

Please sign in to comment.