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

Implemented new aliases "LoadDotEnv" and "LoadEnvData" #1

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
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
8 changes: 6 additions & 2 deletions .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,9 @@ branches:
# Build Cache #
#---------------------------------#
cache:
- Source\packages -> Source\**\packages.config
- tools -> setup.cake
- tools -> setup.cake

#---------------------------------#
# Build Image #
#---------------------------------#
image: Visual Studio 2017
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -250,3 +250,6 @@ paket-files/
# JetBrains Rider
.idea/
*.sln.iml

BuildArtifacts
tools
11 changes: 9 additions & 2 deletions nuspec/nuget/Cake.DotEnv.Module.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,24 @@
<package xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<metadata xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<id>Cake.DotEnv.Module</id>
<version>0.0.0</version>
<version>0.0.1</version>
<authors>Jamie Phillips</authors>
<owners>Jamie Phillips</owners>
<description>Cake Module for using the dotenv file for settings local environment variables.</description>
<summary>Cake Module for using the dotenv file for settings local environment variables.</summary>
<licenseUrl>https://github.com/cake-contrib/Cake.DotEnv.Module/blob/master/LICENSE</licenseUrl>
<projectUrl>https://github.com/cake-contrib/Cake.DotEnv.Module/Cake.Netlify</projectUrl>
<iconUrl>https://cdn.jsdelivr.net/gh/cake-contrib/graphics/png/cake-contrib-medium.png</iconUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<copyright>Copyright (c) Jamie Phillips 2017 - Present</copyright>
<tags>Cake, Script, Build, DotEnv, Module</tags>
</metadata>
<files>
</files>
<file src="net461\Cake.DotEnv.Module.dll" target="lib\net461" />
<file src="net461\Cake.DotEnv.Module.pdb" target="lib\net461" />
<file src="net461\Cake.DotEnv.Module.xml" target="lib\net461" />
<file src="netstandard2.0\Cake.DotEnv.Module.dll" target="lib\netstandard2.0" />
<file src="netstandard2.0\Cake.DotEnv.Module.pdb" target="lib\netstandard2.0" />
<file src="netstandard2.0\Cake.DotEnv.Module.xml" target="lib\netstandard2.0" />
</files>
</package>
6 changes: 4 additions & 2 deletions setup.cake
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ BuildParameters.SetParameters(context: Context,
title: "Cake.DotEnv.Module",
repositoryOwner: "cake-contrib",
repositoryName: "Cake.DotEnv.Module",
appVeyorAccountName: "cakecontrib");
appVeyorAccountName: "cakecontrib",
shouldRunDupFinder: false,
shouldRunInspectCode: false);

BuildParameters.PrintParameters(Context);

Expand All @@ -18,4 +20,4 @@ ToolSettings.SetToolSettings(context: Context,
testCoverageFilter: "+[*]* -[xunit.*]* -[Cake.Core]* -[Cake.Testing]* -[*.Tests]* ",
testCoverageExcludeByAttribute: "*.ExcludeFromCodeCoverage*",
testCoverageExcludeByFile: "*/*Designer.cs;*/*.g.cs;*/*.g.i.cs");
Build.Run();
Build.RunDotNetCore();
26 changes: 22 additions & 4 deletions src/Cake.DotEnv.Module.Tests/Cake.DotEnv.Module.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,13 +1,31 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard1.6</TargetFramework>
<TargetFramework>netcoreapp2.0</TargetFramework>
<IsPackable>false</IsPackable>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Cake.Testing" Version="0.19.4" />
<PackageReference Include="NSubstitute" Version="2.0.3" />
<PackageReference Include="xunit" Version="2.2.0" />
<PackageReference Include="Cake.Core" Version="0.33.0" />
<PackageReference Include="Cake.Testing" Version="0.33.0" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1" />
<PackageReference Include="NSubstitute" Version="4.2.0" />
</ItemGroup>

<ItemGroup>
<Compile Include="..\SolutionInfo.cs" Link="SolutionInfo.cs" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Cake.DotEnv.Module\Cake.DotEnv.Module.csproj" />
</ItemGroup>

<ItemGroup>
<None Update="Testdata\testdata01.env">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
8 changes: 0 additions & 8 deletions src/Cake.DotEnv.Module.Tests/Class1.cs

This file was deleted.

70 changes: 70 additions & 0 deletions src/Cake.DotEnv.Module.Tests/DotEnvTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
using System;
using System.Linq;

using Xunit;

namespace Cake.DotEnv.Module.Tests
{
public class DotEnvTests : IDisposable
{
private readonly FakeCakeContext context;

public DotEnvTests()
{
context = new FakeCakeContext();
}

public void Dispose()
{
context.DumpLogs();
}

[Fact]
public void ParseEnvString()
{
var data = @"
DOTENV_TEST_ENV1=Value 1

DOTENV_TEST_ENV2=Value 2
DOTENV_TEST_ENV3 = Value 3
#DOTENV_TEST_ENV4=Value 4";

CakeAliases.LoadEnvString(context.CakeContext, data);

Assert.Equal("Value 1", Environment.GetEnvironmentVariable("DOTENV_TEST_ENV1"));
Assert.Equal("Value 2", Environment.GetEnvironmentVariable("DOTENV_TEST_ENV2"));
Assert.Equal("Value 3", Environment.GetEnvironmentVariable("DOTENV_TEST_ENV3"));
Assert.Null(Environment.GetEnvironmentVariable("DOTENV_TEST_ENV4"));

var vars = Environment.GetEnvironmentVariables().Keys.OfType<string>().Where(x => x.StartsWith("DOTENV_TEST_")).ToList();

Assert.Equal(3, vars.Count);

// Delete test vars
foreach (var variable in vars)
{
Environment.SetEnvironmentVariable(variable, null);
}
}

[Fact]
public void ParseEnvFile()
{
Assert.True(CakeAliases.LoadDotEnv(context.CakeContext, "Testdata\\testdata01.env"));

Assert.Equal(".COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC;.PY;.PYW", Environment.GetEnvironmentVariable("DOTENV_TEST_PATHEXT"));
Assert.Equal("$P$G", Environment.GetEnvironmentVariable("DOTENV_TEST_PROMPT"));
Assert.Equal("-Xms256m -Xmx512m", Environment.GetEnvironmentVariable("DOTENV_TEST_JAVA_OPTS"));

var vars = Environment.GetEnvironmentVariables().Keys.OfType<string>().Where(x => x.StartsWith("DOTENV_TEST_")).ToList();

Assert.Equal(17, vars.Count);

// Delete test vars
foreach (var variable in vars)
{
Environment.SetEnvironmentVariable(variable, null);
}
}
}
}
67 changes: 67 additions & 0 deletions src/Cake.DotEnv.Module.Tests/FakeCakeArguments.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
using System;
using System.Collections.Generic;

using Cake.Core;

namespace Cake.DotEnv.Module.Tests
{
internal sealed class FakeCakeArguments : ICakeArguments
{
private readonly Dictionary<string, string> _arguments;

/// <summary>
/// Gets the arguments.
/// </summary>
/// <value>The arguments.</value>
public IReadOnlyDictionary<string, string> Arguments => _arguments;

/// <summary>
/// Initializes a new instance of the <see cref="FakeCakeArguments"/> class.
/// </summary>
public FakeCakeArguments()
{
_arguments = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
}

/// <summary>
/// Initializes the argument list.
/// </summary>
/// <param name="arguments">The arguments.</param>
public void SetArguments(IDictionary<string, string> arguments)
{
if (arguments == null)
{
throw new ArgumentNullException(nameof(arguments));
}

_arguments.Clear();

foreach ((string key, string value) in arguments)
{
_arguments.Add(key, value);
}
}

/// <summary>
/// Determines whether or not the specified argument exist.
/// </summary>
/// <param name="name">The argument name.</param>
/// <returns>
/// <c>true</c> if the argument exist; otherwise <c>false</c>.
/// </returns>
public bool HasArgument(string name)
{
return _arguments.ContainsKey(name);
}

/// <summary>
/// Gets an argument.
/// </summary>
/// <param name="name">The argument name.</param>
/// <returns>The argument value.</returns>
public string GetArgument(string name)
{
return _arguments.ContainsKey(name) ? _arguments[name] : null;
}
}
}
55 changes: 55 additions & 0 deletions src/Cake.DotEnv.Module.Tests/FakeCakeContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using System;

using Cake.Core;
using Cake.Core.IO;
using Cake.Core.Tooling;
using Cake.Testing;

using Path = System.IO.Path;
using NSubstitute;

namespace Cake.DotEnv.Module.Tests
{

public class FakeCakeContext
{
private readonly ICakeContext context;
private readonly FakeLog log;
private readonly DirectoryPath testsDir;

public FakeCakeContext()
{
testsDir = new DirectoryPath(Path.GetFullPath(AppContext.BaseDirectory));

var environment = FakeEnvironment.CreateUnixEnvironment(false);

var fileSystem = new FakeFileSystem(environment);
var globber = new Globber(fileSystem, environment);
log = new FakeLog();
var args = new FakeCakeArguments();
var registry = new WindowsRegistry();

var config = new FakeConfiguration();
var tools = new ToolLocator(environment, new ToolRepository(environment), new ToolResolutionStrategy(fileSystem, environment, globber, config));
var processRunner = new ProcessRunner(fileSystem, environment, log, tools, config);
var data = Substitute.For<ICakeDataService>();
context = new CakeContext(fileSystem, environment, globber, log, args, processRunner, registry, tools, data, config);
context.Environment.WorkingDirectory = testsDir;
}

public DirectoryPath WorkingDirectory => testsDir;

public ICakeContext CakeContext => context;

public string GetLogs()
{
return string.Join(Environment.NewLine, log.Entries);
}

public void DumpLogs()
{
foreach (var m in log.Entries)
Console.WriteLine(m);
}
}
}
17 changes: 17 additions & 0 deletions src/Cake.DotEnv.Module.Tests/Testdata/testdata01.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
DOTENV_TEST_ALLUSERSPROFILE=C:\ProgramData
DOTENV_TEST_ANDROID_SDK_HOME=C:\Android
DOTENV_TEST_CommonProgramFiles=C:\Program Files\Common Files
DOTENV_TEST_CommonProgramFiles(x86)=C:\Program Files (x86)\Common Files
DOTENV_TEST_CommonProgramW6432=C:\Program Files\Common Files
DOTENV_TEST_JAVA_OPTS=-Xms256m -Xmx512m
DOTENV_TEST_OS=Windows_NT
DOTENV_TEST_PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC;.PY;.PYW
DOTENV_TEST_PROCESSOR_ARCHITECTURE=AMD64
DOTENV_TEST_ProgramData=C:\ProgramData
DOTENV_TEST_ProgramFiles=C:\Program Files
DOTENV_TEST_ProgramFiles(x86)=C:\Program Files (x86)
DOTENV_TEST_ProgramW6432=C:\Program Files
DOTENV_TEST_PROMPT=$P$G
DOTENV_TEST_SystemDrive=C:
DOTENV_TEST_SystemRoot=C:\WINDOWS
DOTENV_TEST_windir=C:\WINDOWS
18 changes: 16 additions & 2 deletions src/Cake.DotEnv.Module/Cake.DotEnv.Module.csproj
Original file line number Diff line number Diff line change
@@ -1,11 +1,25 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard1.6</TargetFramework>
<TargetFrameworks>net461;netstandard2.0</TargetFrameworks>
<AssemblyName>Cake.DotEnv.Module</AssemblyName>
<RootNamespace>Cake.DotEnv.Module</RootNamespace>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<PlatformTarget>anycpu</PlatformTarget>
<DebugType>portable</DebugType>
</PropertyGroup>

<PropertyGroup>
<DocumentationFile>bin\$(Configuration)\$(TargetFramework)\Cake.DotEnv.Module.xml</DocumentationFile>
</PropertyGroup>

<ItemGroup>
<Compile Include="..\SolutionInfo.cs" Link="SolutionInfo.cs" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Cake.Core" Version="0.19.4" />
<PackageReference Include="Cake.Core" Version="0.33.0" PrivateAssets="All" />
</ItemGroup>

</Project>
Loading