コード例 #1
0
    def test_generated_hook_wrappers_include_environment(self, mock_snap_env):
        mock_snap_env.return_value = ["PATH={}/foo".format(self.prime_dir)]

        # Set up the prime directory to contain a hook in snap/hooks as well as
        # one in meta/hooks
        snap_hook = os.path.join(self.prime_dir, "snap", "hooks", "snap-hook")
        meta_hook = os.path.join(self.prime_dir, "meta", "hooks", "meta-hook")

        for path in (snap_hook, meta_hook):
            _create_file(path, executable=True, content=path)

        # Now generate hook wrappers
        self.generate_meta_yaml()

        # Verify that the hook already in meta was unchanged (no environment)
        final_meta_hook = os.path.join(self.hooks_dir, "meta-hook")
        self.assertThat(final_meta_hook, FileExists())
        self.assertThat(final_meta_hook, unit.IsExecutable())
        self.assertThat(final_meta_hook, FileContains(meta_hook))

        # Verify that the snap hook was unchanged
        self.assertThat(snap_hook, FileExists())
        self.assertThat(snap_hook, unit.IsExecutable())
        self.assertThat(snap_hook, FileContains(snap_hook))

        # Verify that the snap hook got a wrapper generated for it with a full
        # environment
        final_snap_hook = os.path.join(self.hooks_dir, "snap-hook")
        self.assertThat(final_snap_hook, FileExists())
        self.assertThat(final_snap_hook, unit.IsExecutable())
        expected = textwrap.dedent(
            """\
            #!/bin/sh
            export PATH=$SNAP/foo
            export LD_LIBRARY_PATH="$SNAP_LIBRARY_PATH:$LD_LIBRARY_PATH"
            exec "$SNAP/snap/hooks/snap-hook" "$@"
        """
        )

        self.assertThat(final_snap_hook, FileContains(expected))
コード例 #2
0
    def test_generate_hook_wrappers(self):
        # Set up the prime directory to contain a few hooks in snap/hooks
        snap_hooks_dir = os.path.join(self.prime_dir, 'snap', 'hooks')
        hook1_path = os.path.join(snap_hooks_dir, 'test-hook1')
        hook2_path = os.path.join(snap_hooks_dir, 'test-hook2')

        for path in (hook1_path, hook2_path):
            _create_file(path, executable=True)

        # Now generate hook wrappers, and verify that they're correct
        self.generate_meta_yaml()
        for hook in ('test-hook1', 'test-hook2'):
            hook_path = os.path.join(self.hooks_dir, hook)
            self.assertThat(hook_path, FileExists())
            self.assertThat(hook_path, unit.IsExecutable())

            # The hook in meta/hooks should exec the one in snap/hooks, as it's
            # a wrapper generated by snapcraft.
            self.assertThat(
                hook_path,
                FileContains(matcher=Contains(
                    'exec "$SNAP/snap/hooks/{}"'.format(hook))))
コード例 #3
0
 def test_download_makes_executable(self, mock_download):
     self.source.file = os.path.join('destination', 'file')
     self.source.download()
     self.assertThat(self.source.file, FileExists())
     self.assertThat(self.source.file, unit.IsExecutable())