Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport 7.61.x] [incident-32914] Disable worktree unit tests #31643

Merged
merged 1 commit into from
Dec 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
139 changes: 73 additions & 66 deletions tasks/unit_tests/libs/common/worktree_tests.py
Original file line number Diff line number Diff line change
@@ -1,97 +1,104 @@
import os
import unittest
# TODO(celian): Reintroduce these tests

from invoke import Context
"""
NOTE: These tests are disabled since they use git commands that are not mocked yet.
This breaks unit tests ran with macos runners.
"""

from tasks.libs.common.git import get_default_branch
from tasks.libs.common.gomodules import get_default_modules
from tasks.libs.common.worktree import agent_context, init_env, is_worktree
# import os
# import unittest

# from invoke import Context

def get_ctx():
return Context()
# from tasks.libs.common.git import get_default_branch
# from tasks.libs.common.gomodules import get_default_modules
# from tasks.libs.common.worktree import agent_context, init_env, is_worktree


class TestWorktree(unittest.TestCase):
def setUp(self):
# Pull only once
init_env(get_ctx(), '6.53.x')
os.environ['AGENT_WORKTREE_NO_PULL'] = '1'
# def get_ctx():
# return Context()

def test_context_is_worktree_true(self):
with agent_context(get_ctx(), '6.53.x'):
self.assertTrue(is_worktree())

def test_context_is_worktree_false(self):
self.assertFalse(is_worktree())
# class TestWorktree(unittest.TestCase):
# def setUp(self):
# # Pull only once
# init_env(get_ctx(), '6.53.x')
# os.environ['AGENT_WORKTREE_NO_PULL'] = '1'

def test_context_nested(self):
with agent_context(get_ctx(), '6.53.x'):
with agent_context(get_ctx(), '6.53.x'):
self.assertTrue(is_worktree())
self.assertTrue(is_worktree())
# def test_context_is_worktree_true(self):
# with agent_context(get_ctx(), '6.53.x'):
# self.assertTrue(is_worktree())

def test_context_pwd(self):
ctx = get_ctx()
# def test_context_is_worktree_false(self):
# self.assertFalse(is_worktree())

with agent_context(ctx, None, skip_checkout=True):
pwdnone = ctx.run('pwd').stdout
# def test_context_nested(self):
# with agent_context(get_ctx(), '6.53.x'):
# with agent_context(get_ctx(), '6.53.x'):
# self.assertTrue(is_worktree())
# self.assertTrue(is_worktree())

with agent_context(ctx, '6.53.x'):
pwd6 = ctx.run('pwd').stdout
# def test_context_pwd(self):
# ctx = get_ctx()

with agent_context(ctx, 'main'):
pwdmain = ctx.run('pwd').stdout
# with agent_context(ctx, None, skip_checkout=True):
# pwdnone = ctx.run('pwd').stdout

self.assertEqual(pwd6, pwdnone)
self.assertEqual(pwd6, pwdmain)
# with agent_context(ctx, '6.53.x'):
# pwd6 = ctx.run('pwd').stdout

def test_context_modules(self):
ctx = get_ctx()
# with agent_context(ctx, 'main'):
# pwdmain = ctx.run('pwd').stdout

with agent_context(ctx, 'main'):
modules7 = get_default_modules()
# self.assertEqual(pwd6, pwdnone)
# self.assertEqual(pwd6, pwdmain)

with agent_context(ctx, '6.53.x'):
modules6 = get_default_modules()
# def test_context_modules(self):
# ctx = get_ctx()

self.assertNotEqual(set(modules6.keys()), set(modules7.keys()))
# with agent_context(ctx, 'main'):
# modules7 = get_default_modules()

def test_context_branch(self):
ctx = get_ctx()
# with agent_context(ctx, '6.53.x'):
# modules6 = get_default_modules()

with agent_context(ctx, 'main'):
branch7 = get_default_branch()
# self.assertNotEqual(set(modules6.keys()), set(modules7.keys()))

with agent_context(ctx, '6.53.x'):
branch6 = get_default_branch()
# def test_context_branch(self):
# ctx = get_ctx()

self.assertNotEqual(branch6, branch7)
# with agent_context(ctx, 'main'):
# branch7 = get_default_branch()

def test_context_no_checkout(self):
ctx = get_ctx()
# with agent_context(ctx, '6.53.x'):
# branch6 = get_default_branch()

with agent_context(ctx, '6.53.x'):
branch6 = get_default_branch()
# self.assertNotEqual(branch6, branch7)

with agent_context(ctx, 'main'):
branch7 = get_default_branch()
# def test_context_no_checkout(self):
# ctx = get_ctx()

with agent_context(ctx, 'main', skip_checkout=True):
branch_no_checkout = get_default_branch()
# with agent_context(ctx, '6.53.x'):
# branch6 = get_default_branch()

self.assertNotEqual(branch6, branch7)
self.assertEqual(branch7, branch_no_checkout)
# with agent_context(ctx, 'main'):
# branch7 = get_default_branch()

def test_context_no_checkout_error(self):
ctx = get_ctx()
# with agent_context(ctx, 'main', skip_checkout=True):
# branch_no_checkout = get_default_branch()

with agent_context(ctx, '6.53.x'):
pass
# self.assertNotEqual(branch6, branch7)
# self.assertEqual(branch7, branch_no_checkout)

def switch_context():
# The current branch is not main
with agent_context(ctx, 'main', skip_checkout=True):
pass
# def test_context_no_checkout_error(self):
# ctx = get_ctx()

self.assertRaises(AssertionError, switch_context)
# with agent_context(ctx, '6.53.x'):
# pass

# def switch_context():
# # The current branch is not main
# with agent_context(ctx, 'main', skip_checkout=True):
# pass

# self.assertRaises(AssertionError, switch_context)
Loading