Skip to content

Commit

Permalink
Merge pull request #209 from lemberg/issue/208-broken-provisioning
Browse files Browse the repository at this point in the history
Fix broken provisioning due to the missing '/vagrant' mount
  • Loading branch information
T2L committed Aug 12, 2020
2 parents b188649 + cc1b808 commit ed1e837
Show file tree
Hide file tree
Showing 8 changed files with 159 additions and 2 deletions.
6 changes: 6 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,12 @@ jobs:

env: MOLECULE_PLATFORM=ubuntu1604

before_install:
- curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
- sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
- sudo apt-get update
- sudo apt-get -y -o Dpkg::Options::="--force-confnew" install docker-ce

install:
- composer install --no-interaction --no-progress --no-suggest --prefer-dist --optimize-autoloader --no-dev
- pip install ansible==2.9.* ansible-lint docker flake8 molecule==3.*
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## Draft Environment (Unreleased)

Fixes:

- [GH-208](https://github.com/lemberg/draft-environment/issues/208) - Fix broken provisioning by adding `/vagrant` mount

## Draft Environment 3.1.0, 2020-08-06

Updates:
Expand Down
2 changes: 2 additions & 0 deletions Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,8 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
# Configure synched folders.
config.vm.synced_folder configuration.get("vagrant.source_directory"), configuration.get("vagrant.destination_directory"), configuration.get("vagrant.synced_folder_options")

config.vm.synced_folder ".", "/vagrant", id: "vagrant", type: "nfs", create: true

# Provisioning
#
# See https://docs.vagrantup.com/v2/provisioning/index.html
Expand Down
1 change: 1 addition & 0 deletions default.vm-settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ vagrant:
# for possible options and their values. Please note that each synced fodler
# type could have extra options, look at NFS or RSync for examples.
synced_folder_options:
id: default
type: nfs
create: true

Expand Down
28 changes: 28 additions & 0 deletions src/Config/Update/Step/AddIdToSyncedFoldersOptions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

declare(strict_types=1);

namespace Lemberg\Draft\Environment\Config\Update\Step;

use Lemberg\Draft\Environment\Config\Update\UpdateStepInterface;

/**
* Adds id to the synced folders configuration.
*/
final class AddIdToSyncedFoldersOptions extends AbstractUpdateStep implements UpdateStepInterface {

/**
* {@inheritdoc}
*/
public function getWeight(): int {
return 5;
}

/**
* {@inheritdoc}
*/
public function update(array &$config): void {
$config['vagrant']['synced_folder_options']['id'] = 'default';
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ final protected function assertComposerLockContainsPackageExtra(): void {
$key = array_search(App::PACKAGE_NAME, array_column($decoded_composer_lock['packages-dev'], 'name'), TRUE);

self::assertTrue($decoded_composer_lock['packages-dev'][$key]['extra']['draft-environment']['already-installed']);
self::assertSame(4, $decoded_composer_lock['packages-dev'][$key]['extra']['draft-environment']['last-update-weight']);
self::assertSame(5, $decoded_composer_lock['packages-dev'][$key]['extra']['draft-environment']['last-update-weight']);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/Config/Manager/UpdateManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ public function testGetAndSetLastAppliedUpdateWeight(): void {
* Tests the last available update weight getter.
*/
public function testGetLastAvailableUpdateWeight(): void {
self::assertSame(4, $this->configUpdateManager->getLastAvailableUpdateWeight());
self::assertSame(5, $this->configUpdateManager->getLastAvailableUpdateWeight());
}

}
114 changes: 114 additions & 0 deletions tests/Unit/Config/Update/Step/AddIdToSyncedFoldersOptionsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
<?php

declare(strict_types=1);

namespace Lemberg\Tests\Unit\Draft\Environment\Config\Update\Step;

use Composer\Composer;
use Composer\Config as ComposerConfig;
use Composer\IO\IOInterface;
use Lemberg\Draft\Environment\Config\Config;
use Lemberg\Draft\Environment\Config\Manager\UpdateManager;
use Lemberg\Draft\Environment\Config\Update\Step\AddIdToSyncedFoldersOptions;
use Lemberg\Draft\Environment\Utility\Filesystem;
use org\bovigo\vfs\vfsStream;
use PHPUnit\Framework\TestCase;

/**
* Tests adding id to the synced folders configuration.
*
* @covers \Lemberg\Draft\Environment\Config\Update\Step\AbstractUpdateStep
* @covers \Lemberg\Draft\Environment\Config\Update\Step\AddIdToSyncedFoldersOptions
*/
final class AddIdToSyncedFoldersOptionsTest extends TestCase {

/**
* @var \Composer\Composer
*/
private $composer;

/**
* @var \Composer\IO\IOInterface
*/
private $io;

/**
* @var string
*/
private $root;

/**
* @var \Lemberg\Draft\Environment\Config\Manager\UpdateManagerInterface
*/
private $configUpdateManager;

/**
* {@inheritdoc}
*/
protected function setUp(): void {
$this->composer = new Composer();
$this->composer->setConfig(new ComposerConfig());
$this->io = $this->createMock(IOInterface::class);

// Mock source and target configuration directories.
$this->root = vfsStream::setup()->url();
$fs = new Filesystem();
$fs->mkdir(["$this->root/source", "$this->root/target"]);

$configObject = new Config("$this->root/source", "$this->root/target");
$this->configUpdateManager = new UpdateManager($this->composer, $this->io, $configObject);
}

/**
* Tests step weight getter.
*/
final public function testGetWeight(): void {
$step = new AddIdToSyncedFoldersOptions($this->composer, $this->io, $this->configUpdateManager);
self::assertSame(5, $step->getWeight());
}

/**
* Tests update step execution.
*
* @param array<string,mixed> $config
* @param array<string,mixed> $expectedConfig
*
* @dataProvider updateDataProvider
*/
final public function testUpdate(array $config, array $expectedConfig): void {
$step = new AddIdToSyncedFoldersOptions($this->composer, $this->io, $this->configUpdateManager);

$step->update($config);
self::assertSame($config, $expectedConfig);
}

/**
* Data provider for the ::testUpdate().
*
* @return array<int,array<int,string|array<string,mixed>>>
*/
final public function updateDataProvider(): array {
return [
[
[
'vagrant' => [
'synced_folder_options' => [
'type' => 'nfs',
'create' => TRUE,
],
],
],
[
'vagrant' => [
'synced_folder_options' => [
'type' => 'nfs',
'create' => TRUE,
'id' => 'default',
],
],
],
],
];
}

}

0 comments on commit ed1e837

Please sign in to comment.