From 026954c590e6428db87de0ad3265db6500dfe700 Mon Sep 17 00:00:00 2001 From: Atle Rudshaug Date: Wed, 20 Mar 2019 22:01:00 +0100 Subject: [PATCH] Fix bugs and add unit-tests. - Add nupkg to arguments - Convert timeout TimeSpan to seconds --- src/app/Fake.DotNet.Cli/DotNet.fs | 14 +++--- src/app/Fake.DotNet.Cli/VisibleTo.fs | 3 +- .../Fake.Core.UnitTests/Fake.DotNet.Cli.fs | 44 ++++++++++++++++--- 3 files changed, 46 insertions(+), 15 deletions(-) diff --git a/src/app/Fake.DotNet.Cli/DotNet.fs b/src/app/Fake.DotNet.Cli/DotNet.fs index 7ddbd3bd0fa..5b43ac48e09 100644 --- a/src/app/Fake.DotNet.Cli/DotNet.fs +++ b/src/app/Fake.DotNet.Cli/DotNet.fs @@ -1436,7 +1436,7 @@ module DotNet = execWithBinLog project param.Common "test" args param.MSBuildParams __.MarkSuccess() - let private buildNugetPushArgs (param : NuGet.NuGetPushParams) = + let internal buildNugetPushArgs (param : NuGet.NuGetPushParams) = [ param.DisableBuffering |> argOption "disable-buffering" param.ApiKey |> Option.toList |> argList2 "api-key" @@ -1445,21 +1445,21 @@ module DotNet = param.Source |> Option.toList |> argList2 "source" param.SymbolApiKey |> Option.toList |> argList2 "symbol-api-key" param.SymbolSource |> Option.toList |> argList2 "symbol-source" - param.Timeout |> Option.map string |> Option.toList |> argList2 "timeout" + param.Timeout |> Option.map (fun t -> t.TotalSeconds |> int |> string) |> Option.toList |> argList2 "timeout" ] |> List.concat |> List.filter (not << String.IsNullOrEmpty) type NuGetPushOptions = { Common: Options - Options: NuGet.NuGetPushParams } + PushParams: NuGet.NuGetPushParams } static member Create() = { Common = Options.Create() - Options = NuGet.NuGetPushParams.Create() } + PushParams = NuGet.NuGetPushParams.Create() } member this.WithCommon (common : Options) = { this with Common = common } - member this.WithOptions (options : NuGet.NuGetPushParams) = - { this with Options = options } + member this.WithPushParams (options : NuGet.NuGetPushParams) = + { this with PushParams = options } /// Execute dotnet nuget push command @@ -1470,7 +1470,7 @@ module DotNet = let nugetPush setParams nupkg = use __ = Trace.traceTask "DotNet:nuget:push" nupkg let param = NuGetPushOptions.Create() |> setParams - let args = param.Options |> buildNugetPushArgs |> Args.toWindowsCommandLine + let args = Args.toWindowsCommandLine (nupkg :: buildNugetPushArgs param.PushParams) let result = exec (fun _ -> param.Common) "nuget push" args if not result.OK then failwithf "dotnet nuget push failed with code %i" result.ExitCode __.MarkSuccess() diff --git a/src/app/Fake.DotNet.Cli/VisibleTo.fs b/src/app/Fake.DotNet.Cli/VisibleTo.fs index 21d9c08a2b0..3c7a01575c6 100644 --- a/src/app/Fake.DotNet.Cli/VisibleTo.fs +++ b/src/app/Fake.DotNet.Cli/VisibleTo.fs @@ -3,4 +3,5 @@ namespace System open System.Runtime.CompilerServices [] -do () \ No newline at end of file +[] +do () diff --git a/src/test/Fake.Core.UnitTests/Fake.DotNet.Cli.fs b/src/test/Fake.Core.UnitTests/Fake.DotNet.Cli.fs index 79c6674cc01..1f36328b8f4 100644 --- a/src/test/Fake.Core.UnitTests/Fake.DotNet.Cli.fs +++ b/src/test/Fake.Core.UnitTests/Fake.DotNet.Cli.fs @@ -6,11 +6,41 @@ open Expecto [] let tests = - testList "Fake.DotNet.Cli.Tests" [ - testCase "Test that we can use Process-Helpers on Cli Paramters" <| fun _ -> - let cli = - DotNet.Options.Create() - |> Process.setEnvironmentVariable "Somevar" "someval" + testList "Fake.DotNet.Cli.Tests" [ + testCase "Test that we can use Process-Helpers on Cli Paramters" <| fun _ -> + let cli = + DotNet.Options.Create() + |> Process.setEnvironmentVariable "Somevar" "someval" - Expect.equal cli.Environment.["Somevar"] "someval" "Retrieving the correct environment variable failed." - ] + Expect.equal cli.Environment.["Somevar"] "someval" "Retrieving the correct environment variable failed." + + testCase "Test that the default dotnet nuget push arguments returns empty string" <| fun _ -> + let cli = + DotNet.NuGetPushOptions.Create().PushParams + |> DotNet.buildNugetPushArgs + |> Args.toWindowsCommandLine + + + Expect.equal cli "" "Empty push args." + + testCase "Test that the dotnet nuget push arguments with all params setreturns correct string" <| fun _ -> + let param = + { DotNet.NuGetPushOptions.Create().PushParams with + DisableBuffering = true + ApiKey = Some "abc123" + NoSymbols = true + NoServiceEndpoint = true + Source = Some "MyNuGetSource" + SymbolApiKey = Some "MySymbolApiKey" + SymbolSource = Some "MySymbolSource" + Timeout = Some <| System.TimeSpan.FromMinutes 5.0 } + + let cli = + param + |> DotNet.buildNugetPushArgs + |> Args.toWindowsCommandLine + + let expected = "--disable-buffering --api-key abc123 --no-symbols --no-service-endpoint --source MyNuGetSource --symbol-api-key MySymbolApiKey --symbol-source MySymbolSource --timeout 300" + + Expect.equal cli expected "Push args generated correctly." + ]