Skip to content

Commit

Permalink
Fix bugs and add unit-tests.
Browse files Browse the repository at this point in the history
- Add nupkg to arguments
- Convert timeout TimeSpan to seconds
  • Loading branch information
atlemann committed Mar 20, 2019
1 parent 500272d commit 026954c
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 15 deletions.
14 changes: 7 additions & 7 deletions src/app/Fake.DotNet.Cli/DotNet.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand All @@ -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()
3 changes: 2 additions & 1 deletion src/app/Fake.DotNet.Cli/VisibleTo.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ namespace System
open System.Runtime.CompilerServices

[<assembly: InternalsVisibleTo("Fake.Core.IntegrationTests")>]
do ()
[<assembly: InternalsVisibleTo("Fake.Core.UnitTests")>]
do ()
44 changes: 37 additions & 7 deletions src/test/Fake.Core.UnitTests/Fake.DotNet.Cli.fs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,41 @@ open Expecto

[<Tests>]
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."
]

0 comments on commit 026954c

Please sign in to comment.