This commit is contained in:
Chris Cheetham 2020-02-15 12:30:19 -05:00
Родитель 3020db0337
Коммит 9f2789bf64
111 изменённых файлов: 1541 добавлений и 6237 удалений

Просмотреть файл

@ -1,9 +1,17 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Boolean x:Key="/Default/UserDictionary/Words/=autodetected/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=autodetection/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=cfgname/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=cfgs/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Datastore/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=depname/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=dummyos/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=hystrix/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Initializr/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Postgre/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=postgresql/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=rabbitmq/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=sqlserver/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Steeltoe/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=steeltoeoss/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Undeploy/@EntryIndexedValue">True</s:Boolean>

Просмотреть файл

@ -1,45 +0,0 @@
// Copyright 2018 the original author or authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
using System.ComponentModel.DataAnnotations;
using McMaster.Extensions.CommandLineUtils;
using Steeltoe.Tooling.Executors;
namespace Steeltoe.Cli
{
[Command(Description = "Add an app")]
public class AddAppCommand : Command
{
public const string Name = "add-app";
[Required(ErrorMessage = "App name not specified")]
[Argument(1, Name = "name", Description = "App name")]
private string AppName { get; } = null;
[Option("-f|--framework", Description = "Target framework")]
private string Framework { get; } = null;
[Option("-r|--runtime", Description = "Target runtime")]
private string Runtime { get; } = null;
public AddAppCommand(IConsole console) : base(console)
{
}
protected override Executor GetExecutor()
{
return new AddAppExecutor(AppName, Framework, Runtime);
}
}
}

Просмотреть файл

@ -0,0 +1,58 @@
// Copyright 2020 the original author or authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
using System;
using System.ComponentModel.DataAnnotations;
using McMaster.Extensions.CommandLineUtils;
using Steeltoe.Tooling.Executors;
namespace Steeltoe.Cli
{
[Command(Description = "Adds a dependency",
ExtendedHelpText = @"
Overview:
Explicitly add a dependency to the project. Useful when autodetection fails.
Examples:
Add a dependency on a Redis service:
$ st add-dep redis
Add a dependency on a Redis service and name it MyRedis:
$ st add-dep redis --name MyRedis
See Also:
rem-dep
list-deps"
)]
public class AddDependencyCommand : Command
{
public const string CommandName = "add-dep";
[Required(ErrorMessage = "Dependency not specified")]
[Argument(0, Name = "dep", Description = "The dependency to be added")]
private string Dependency { get; set; }
[Option("-n|--name", Description = "Sets the dependency name; default is <dep>")]
private string DependencyName { get; set; }
public AddDependencyCommand(IConsole console) : base(console)
{
}
protected override Executor GetExecutor()
{
throw new NotImplementedException();
}
}
}

Просмотреть файл

@ -1,74 +0,0 @@
// Copyright 2018 the original author or authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using McMaster.Extensions.CommandLineUtils;
using Steeltoe.Tooling.Executors;
// ReSharper disable UnassignedGetOnlyAutoProperty
namespace Steeltoe.Cli
{
[Command(
Description = "Set or get the arguments for an app or service",
ExtendedHelpText =
"If run with no arguments, show the current arguments for the app or service.",
AllowArgumentSeparator = true
)]
public class ArgsCommand : Command
{
public const string Name = "args";
[Required(ErrorMessage = "App or service name not specified")]
[Argument(0, Name = "name", Description = "App or service name")]
private string AppOrServiceName { get; }
[Argument(2, Name = "args", Description = "App or service arguments")]
private List<string> Arguments { get; }
[Option("-t|--target", Description = "Apply the args to the deployment on the specified target")]
private string Target { get; }
[Option("-F|--force", Description = "Overwrite existing arguments")]
private bool Force { get; }
private List<string> RemainingArguments { get; }
public ArgsCommand(IConsole console) : base(console)
{
}
protected override Executor GetExecutor()
{
var args = new List<string>();
if (Arguments != null)
{
args.AddRange(Arguments);
}
if (RemainingArguments != null)
{
args.AddRange(RemainingArguments);
}
if (args.Count == 0)
{
return new GetArgsExecutor(AppOrServiceName, Target);
}
return new SetArgsExecutor(AppOrServiceName, Target, string.Join(" ", args), Force);
}
}
}

Просмотреть файл

@ -0,0 +1,72 @@
// Copyright 2020 the original author or authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
using System;
using System.ComponentModel.DataAnnotations;
using McMaster.Extensions.CommandLineUtils;
using Steeltoe.Tooling.Executors;
namespace Steeltoe.Cli
{
[Command(Description = "Adds a custom dependency definition",
ExtendedHelpText = @"
Overview:
*** under construction ***
Examples:
Add a dependency definition for a service that listens on a couple of network ports:
$ st def-dep MyService myrepo/myimage --port 9876 --port 9877
Add a dependency definition for a service that can used in all projects:
$ st def-dep MyService myrepo/myimage --scope global
Add a dependency definition for a service that can be autodetected:
$ st def-dep MyService myrepo/myimage --nuget-package My.Service.NuGet
See Also:
undef-dep
list-deps"
)]
public class DefineDependencyCommand : Command
{
public const string CommandName = "def-dep";
[Required(ErrorMessage = "Dependency not specified")]
[Argument(0, Name = "dep", Description = "Dependency")]
private string Dependency { get; set; }
[Required(ErrorMessage = "Docker image not specified")]
[Argument(1, Name = "image", Description = "Docker image")]
private string DockerImage { get; set; }
[Option("-p|--port <port>",
Description = "Sets a network port; may be specified multiple times")]
private int Port { get; set; }
[Option("--nuget-package <name>",
Description = "Sets a NuGet package name for autodetection; may be specified multiple times")]
private string NugetPackage { get; set; }
[Option("--scope <scope>",
Description = "Sets the dependency definition scope (one of: project, global); default is project")]
private string Scope { get; set; }
public DefineDependencyCommand(IConsole console) : base(console)
{
}
protected override Executor GetExecutor()
{
throw new NotImplementedException();
}
}
}

Просмотреть файл

@ -13,15 +13,14 @@
// limitations under the License.
using McMaster.Extensions.CommandLineUtils;
using Steeltoe.Tooling;
using Steeltoe.Tooling.Executors;
namespace Steeltoe.Cli
{
[Command(Description = "Check for potential problems")]
[Command(Description = "Checks for potential problems")]
public class DoctorCommand : Command
{
public const string Name = "doctor";
public const string CommandName = "doctor";
public DoctorCommand(IConsole console) : base(console)
{
@ -44,29 +43,6 @@ namespace Steeltoe.Cli
var dotnetVersion = new Tooling.Cli("dotnet", Context.Shell).Run("--version", "getting dotnet version")
.Trim();
Context.Console.WriteLine($"dotnet version {dotnetVersion}");
// is intialized?
Context.Console.Write("initialized ... ");
var cfgFile = new ConfigurationFile(Context.ProjectDirectory);
if (!cfgFile.Exists())
{
Context.Console.WriteLine($"!!! no (run '{Program.Name} {InitCommand.Name}' to initialize)");
return;
}
Context.Console.WriteLine("yes");
// target deployment environment
Context.Console.Write("target ... ");
string target = cfgFile.Configuration.Target;
if (target == null)
{
Context.Console.WriteLine($"!!! not set (run '{Program.Name} {TargetCommand.Name} <env>' to set)");
return;
}
Context.Console.WriteLine(target);
Registry.GetTarget(target).IsHealthy(Context);
}
}
}

Просмотреть файл

@ -1,4 +1,4 @@
// Copyright 2018 the original author or authors.
// Copyright 2020 the original author or authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@ -12,23 +12,27 @@
// See the License for the specific language governing permissions and
// limitations under the License.
using System;
using McMaster.Extensions.CommandLineUtils;
using Steeltoe.Tooling.Executors;
namespace Steeltoe.Cli
{
[Command(Description = "Deploy apps and services to the target")]
public class DeployCommand : Command
[Command(Description = "Displays a list of available configurations",
ExtendedHelpText = @"
Overview:
*** under construction ***")]
public class ListConfigurationsCommand : Command
{
public const string Name = "deploy";
public const string CommandName = "list-cfgs";
public DeployCommand(IConsole console) : base(console)
public ListConfigurationsCommand(IConsole console) : base(console)
{
}
protected override Executor GetExecutor()
{
return new DeployExecutor();
throw new NotImplementedException();
}
}
}

Просмотреть файл

@ -1,4 +1,4 @@
// Copyright 2018 the original author or authors.
// Copyright 2020 the original author or authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@ -12,23 +12,27 @@
// See the License for the specific language governing permissions and
// limitations under the License.
using System;
using McMaster.Extensions.CommandLineUtils;
using Steeltoe.Tooling.Executors;
namespace Steeltoe.Cli
{
[Command(Description = "Show app and service statuses")]
public class StatusCommand : Command
[Command(Description = "Displays a list of available dependencies",
ExtendedHelpText = @"
Overview:
*** under construction ***")]
public class ListDependenciesCommand : Command
{
public const string Name = "status";
public const string CommandName = "list-deps";
public StatusCommand(IConsole console) : base(console)
public ListDependenciesCommand(IConsole console) : base(console)
{
}
protected override Executor GetExecutor()
{
return new StatusExecutor();
throw new NotImplementedException();
}
}
}

Просмотреть файл

@ -1,4 +1,4 @@
// Copyright 2018 the original author or authors.
// Copyright 2020 the original author or authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@ -12,23 +12,27 @@
// See the License for the specific language governing permissions and
// limitations under the License.
using System;
using McMaster.Extensions.CommandLineUtils;
using Steeltoe.Tooling.Executors;
namespace Steeltoe.Cli
{
[Command(Description = "Undeploy apps and services from the target")]
public class UndeployCommand : Command
[Command(Description = "Displays a list of available templates",
ExtendedHelpText = @"
Overview:
*** under construction ***")]
public class ListTemplatesCommand : Command
{
public const string Name = "undeploy";
public const string CommandName = "list-templates";
public UndeployCommand(IConsole console) : base(console)
public ListTemplatesCommand(IConsole console) : base(console)
{
}
protected override Executor GetExecutor()
{
return new UndeployExecutor();
throw new NotImplementedException();
}
}
}

Просмотреть файл

@ -0,0 +1,88 @@
// Copyright 2020 the original author or authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
using System;
using McMaster.Extensions.CommandLineUtils;
using Steeltoe.Tooling.Executors;
namespace Steeltoe.Cli
{
[Command(Description = "Creates a new project using Steeltoe Initializr",
ExtendedHelpText = @"
Overview:
Create a new project using Steeltoe Initializr. If the output directory exists and is not empty, --force must be specified.
Examples:
Create a new project in the current directory:
$ st new
Re-create a project in the current directory:
$ st new --force
Create a new project in a new directory:
$ st new --project-dir src/MyProj
Create a new project with dependencies on SQL Server and Redis:
$ st new --dependency sqlserver --dep redis
Create a new project with dependencies on a SQL Server service named MyDB:
$ st new --dependency sqlserver:MyDB
Create a new project with a custom name and using the Steeltoe-React template:
$ st new --name MyCompany.MySample --template Steeltoe-React
Create a new project for netcoreapp2.2:
$ st new --framework netcoreapp2.2
See Also:
show
list-templates
list-deps"
)]
public class NewCommand : Command
{
public const string CommandName = "new";
[Option("-n|--name <name>",
Description = "Sets the project name; default is the name of the current directory")]
private string Name { get; set; }
[Option("--project-dir <path>",
Description = "Sets the location to place the generated project files; default is the current directory")]
private string ProjectDirectory { get; set; }
[Option("-f|--framework <framework>", Description = "Sets the project framework")]
private string Framework { get; set; }
[Option("-t|--template <template>", Description = "Sets the Initializr template")]
private string Template { get; set; }
[Option("-d|--dependency <dep>|<dep>:<depname>",
Description = "Adds the named Initializr dependency; may be specified multiple times")]
private string Dependency { get; set; }
[Option("-F|--force",
Description = "Forces project files to be generated even if it would change existing files")]
private bool Force { get; set; }
public NewCommand(IConsole console) : base(console)
{
}
protected override Executor GetExecutor()
{
throw new NotImplementedException();
}
}
}

Просмотреть файл

@ -0,0 +1,94 @@
// Copyright 2020 the original author or authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
using System;
using McMaster.Extensions.CommandLineUtils;
using Steeltoe.Tooling.Executors;
namespace Steeltoe.Cli
{
[Command(Description = "Creates configuration files for a target",
ExtendedHelpText = @"
Overview:
Creates configuration files for a target. By default, files are generated for the Docker target.
Docker configurations can subsequently be used by the run command.
Examples:
Create the default configuration:
$ st new-cfg
Re-create the default configuration for a project in a specific directory:
$ st new-cfg --force --project-dir src/MyProj
Create a configuration for Kubernetes using the netcoreapp2.1 framework:
$ st new-cfg --target k8s --framework netcoreapp2.1
Create a named configuration with application arguments:
$ st new-cfg --name MyCustomDockerConfig --application-arg arg1 --application-arg arg2
Create a configuration that sets an environment variable for a dependency:
$ st new-cfg --dependency-env MyDB:ACCEPT_EULA=Y
See Also:
show-cfg
run"
)]
public class NewConfigurationCommand : Command
{
public const string CommandName = "new-cfg";
[Option("-T|--target <target>", Description = "Sets the configuration target (one of: Docker, Kubernetes, Cloud-Foundry); default is 'Docker'")]
private string Target { get; set; } = "Docker";
[Option("-n|--name <cfgname>", Description = "Sets the configuration name; default is the project name")]
private string Name { get; set; }
[Option("-o|--output <path>",
Description = "Sets the location to place the generated configuration; default is the current directory")]
private string OutputPath { get; set; }
[Option("-f|--framework <framework>", Description = "Sets the framework; default is the project framework")]
private string Framework { get; set; }
[Option("-a|--arg <arg>", Description = "Sets a command line argument for the application")]
private string Argument { get; set; }
[Option("-e|--env <name>=<value>",
Description = "Sets an environment variable for the application; may be specified multiple times")]
private string ApplicationEnvironmentVariable { get; set; }
[Option("--dep-arg <depname>:<arg>",
Description = "Sets a command line argument for the named dependency")]
private string DependencyArgument { get; set; }
[Option("--dep-env <depname>:<name>=<value>",
Description =
"Sets an environment variable for the named dependency; may be specified multiple times")]
private string DependencyEnvironmentVariable { get; set; }
[Option("-F|--force",
Description = "Forces configuration to be generated even if it would change existing files")]
private bool Force { get; set; }
public NewConfigurationCommand(IConsole console) : base(console)
{
}
protected override Executor GetExecutor()
{
throw new NotImplementedException();
}
}
}

Просмотреть файл

@ -20,17 +20,21 @@ namespace Steeltoe.Cli
{
[Command(Name = Name, Description = "Steeltoe Developer Tools")]
[VersionOptionFromMember("-V|--version", MemberName = nameof(GetVersion))]
[Subcommand(InitCommand.Name, typeof(InitCommand))]
[Subcommand(TargetCommand.Name, typeof(TargetCommand))]
[Subcommand(AddAppCommand.Name, typeof(AddAppCommand))]
[Subcommand(AddServiceCommand.Name, typeof(AddServiceCommand))]
[Subcommand(RemoveCommand.Name, typeof(RemoveCommand))]
[Subcommand(DeployCommand.Name, typeof(DeployCommand))]
[Subcommand(UndeployCommand.Name, typeof(UndeployCommand))]
[Subcommand(StatusCommand.Name, typeof(StatusCommand))]
[Subcommand(ArgsCommand.Name, typeof(ArgsCommand))]
[Subcommand(ListCommand.Name, typeof(ListCommand))]
[Subcommand(DoctorCommand.Name, typeof(DoctorCommand))]
[Subcommand(AddDependencyCommand.CommandName, typeof(AddDependencyCommand))]
[Subcommand(DefineDependencyCommand.CommandName, typeof(DefineDependencyCommand))]
[Subcommand(DoctorCommand.CommandName, typeof(DoctorCommand))]
[Subcommand(ListConfigurationsCommand.CommandName, typeof(ListConfigurationsCommand))]
[Subcommand(ListDependenciesCommand.CommandName, typeof(ListDependenciesCommand))]
[Subcommand(ListTemplatesCommand.CommandName, typeof(ListTemplatesCommand))]
[Subcommand(NewConfigurationCommand.CommandName, typeof(NewConfigurationCommand))]
[Subcommand(NewCommand.CommandName, typeof(NewCommand))]
[Subcommand(RemoveDependencyCommand.CommandName, typeof(RemoveDependencyCommand))]
[Subcommand(RunCommand.CommandName, typeof(RunCommand))]
[Subcommand(ShowCommand.CommandName, typeof(ShowCommand))]
[Subcommand(ShowConfigurationCommand.CommandName, typeof(ShowConfigurationCommand))]
[Subcommand(ShowTopicCommand.CommandName, typeof(ShowTopicCommand))]
[Subcommand(StopCommand.CommandName, typeof(StopCommand))]
[Subcommand(UndefineDependencyCommand.CommandName, typeof(UndefineDependencyCommand))]
public class Program
{
public const string Name = "st";

Просмотреть файл

@ -1,4 +1,4 @@
// Copyright 2018 the original author or authors.
// Copyright 2020 the original author or authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@ -12,32 +12,41 @@
// See the License for the specific language governing permissions and
// limitations under the License.
using System;
using System.ComponentModel.DataAnnotations;
using McMaster.Extensions.CommandLineUtils;
using Steeltoe.Tooling.Executors;
namespace Steeltoe.Cli
{
[Command(Description = "Add a service")]
public class AddServiceCommand : Command
[Command(Description = "Removes a dependency that was added using the add-dep command",
ExtendedHelpText = @"
Overview:
Remove the named dependency from the project.
Examples:
Remove the dependency named MyRedis:
$ st rem-dep MyRedis
See Also:
add-dep
list-deps"
)]
public class RemoveDependencyCommand : Command
{
public const string Name = "add-service";
public const string CommandName = "rem-dep";
[Required(ErrorMessage = "Service type not specified")]
[Argument(0, Name = "type", Description = "Service type")]
private string ServiceType { get; } = null;
[Required(ErrorMessage = "Dependency name not specified")]
[Argument(0, Name = "depname", Description = "The name of the dependency to be removed")]
private string DependencyName { get; set; }
[Required(ErrorMessage = "Service name not specified")]
[Argument(1, Name = "name", Description = "Service name")]
private string ServiceName { get; } = null;
public AddServiceCommand(IConsole console) : base(console)
public RemoveDependencyCommand(IConsole console) : base(console)
{
}
protected override Executor GetExecutor()
{
return new AddServiceExecutor(ServiceName, ServiceType);
throw new NotImplementedException();
}
}
}

Просмотреть файл

@ -0,0 +1,53 @@
// Copyright 2020 the original author or authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
using System;
using McMaster.Extensions.CommandLineUtils;
using Steeltoe.Tooling.Executors;
namespace Steeltoe.Cli
{
[Command(Description = "Runs the project in the local Docker environment",
ExtendedHelpText = @"
Overview:
Starts the project application and its dependencies in the local Docker environment.
Examples:
Run the default configuration:
$ st run
Run a specific configuration:
$ st run -n MyDockerConfig
See Also:
stop
list-cfgs")]
public class RunCommand : Command
{
public const string CommandName = "run";
[Option("-n|--name <name>",
Description = "Sets the name of the configuration to be run (must be a Docker configuration)")]
private string Name { get; set; }
public RunCommand(IConsole console) : base(console)
{
}
protected override Executor GetExecutor()
{
throw new NotImplementedException();
}
}
}

Просмотреть файл

@ -0,0 +1,49 @@
// Copyright 2020 the original author or authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
using System;
using McMaster.Extensions.CommandLineUtils;
using Steeltoe.Tooling.Executors;
namespace Steeltoe.Cli
{
[Command(Description = "Displays the project details",
ExtendedHelpText = @"
Overview:
*** under construction ***
Examples:
Show the details of the project in the current directory:
$ st show
Show the details of the project in a specific directory:
$ st show --project src/MyProj")]
public class ShowCommand : Command
{
public const string CommandName = "show";
[Option("--project-dir <path>",
Description = "Sets the location of the project; default is the current directory")]
private string ProjectDirectory { get; set; }
public ShowCommand(IConsole console) : base(console)
{
}
protected override Executor GetExecutor()
{
throw new NotImplementedException();
}
}
}

Просмотреть файл

@ -1,4 +1,4 @@
// Copyright 2018 the original author or authors.
// Copyright 2020 the original author or authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@ -12,31 +12,38 @@
// See the License for the specific language governing permissions and
// limitations under the License.
using System;
using McMaster.Extensions.CommandLineUtils;
using Steeltoe.Tooling.Executors;
// ReSharper disable UnassignedGetOnlyAutoProperty
namespace Steeltoe.Cli
{
[Command(Description = "Initialize Steeltoe Developer Tools")]
public class InitCommand : Command
[Command(Description = "Displays configuration details",
ExtendedHelpText = @"
Overview:
*** under construction ***
Examples:
Display the details of the default configuration:
$ st show-cfg
Display the details of a specific configuration:
$ st show-cfg --name MyCustomDockerConfig")]
public class ShowConfigurationCommand : Command
{
public const string Name = "init";
public const string CommandName = "show-cfg";
[Option("-a|--autodetect", Description = "Autodetect application")]
private bool Autodetect { get; }
[Option("-n|--name <name>",
Description = "Sets the name of the configuration to be displayed")]
private string Name { get; set; }
[Option("-F|--force", Description = "Initialize the project even if already initialized")]
private bool Force { get; }
public InitCommand(IConsole console) : base(console)
public ShowConfigurationCommand(IConsole console) : base(console)
{
}
protected override Executor GetExecutor()
{
return new InitializationExecutor(Program.ProjectConfigurationPath, autodetect: Autodetect, force: Force);
throw new NotImplementedException();
}
}
}

Просмотреть файл

@ -1,4 +1,4 @@
// Copyright 2018 the original author or authors.
// Copyright 2020 the original author or authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@ -12,30 +12,36 @@
// See the License for the specific language governing permissions and
// limitations under the License.
using System;
using System.ComponentModel.DataAnnotations;
using McMaster.Extensions.CommandLineUtils;
using Steeltoe.Tooling.Executors;
// ReSharper disable UnassignedGetOnlyAutoProperty
namespace Steeltoe.Cli
{
[Command(Description = "Remove an app or service")]
public class RemoveCommand : Command
[Command(Description = "Displays documentation on a topic",
ExtendedHelpText = @"
Overview:
*** under construction ***
Examples:
Display documentation on autodetection:
$ st show-topic autodetection"
)]
public class ShowTopicCommand : Command
{
public const string Name = "remove";
public const string CommandName = "show-topic";
[Required(ErrorMessage = "App or service name not specified")]
[Argument(0, Name = "name", Description = "App or service name")]
private string AppOrServiceName { get; }
[Argument(0, Name = "topic", Description = "Topic")]
private string Topic { get; set; }
public RemoveCommand(IConsole console) : base(console)
public ShowTopicCommand(IConsole console) : base(console)
{
}
protected override Executor GetExecutor()
{
return new RemoveExecutor(AppOrServiceName);
throw new NotImplementedException();
}
}
}

Просмотреть файл

@ -1,4 +1,4 @@
// Copyright 2018 the original author or authors.
// Copyright 2020 the original author or authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@ -12,28 +12,34 @@
// See the License for the specific language governing permissions and
// limitations under the License.
using System;
using McMaster.Extensions.CommandLineUtils;
using Steeltoe.Tooling.Executors;
// ReSharper disable UnassignedGetOnlyAutoProperty
namespace Steeltoe.Cli
{
[Command(Description = "List apps and services")]
public class ListCommand : Command
[Command(Description = "Stops the project running in the local Docker environment",
ExtendedHelpText = @"
Overview:
Stops the project application and its dependencies in the local Docker environment.
Examples:
Stop the running project:
$ st stop
See Also:
run")]
public class StopCommand : Command
{
public const string Name = "list";
public const string CommandName = "stop";
[Option("-v|--verbose", Description = "Verbose")]
private bool Verbose { get; }
public ListCommand(IConsole console) : base(console)
public StopCommand(IConsole console) : base(console)
{
}
protected override Executor GetExecutor()
{
return new ListExecutor(Verbose);
throw new NotImplementedException();
}
}
}

Просмотреть файл

@ -1,49 +0,0 @@
// Copyright 2018 the original author or authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
using McMaster.Extensions.CommandLineUtils;
using Steeltoe.Tooling.Executors;
// ReSharper disable UnassignedGetOnlyAutoProperty
namespace Steeltoe.Cli
{
[Command(Description =
"Set or get the deployment target",
ExtendedHelpText = "If run with no args, show the current deployment target.")]
public class TargetCommand : Command
{
public const string Name = "target";
[Argument(0, Name = "target", Description = "Deployment target name")]
private string Target { get; }
[Option("-F|--force", Description = "Set the deployment target even if checks fail")]
private bool Force { get; }
public TargetCommand(IConsole console) : base(console)
{
}
protected override Executor GetExecutor()
{
if (Target == null)
{
return new GetTargetExecutor();
}
return new SetTargetExecutor(Target, Force);
}
}
}

Просмотреть файл

@ -0,0 +1,56 @@
// Copyright 2020 the original author or authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
using System;
using System.ComponentModel.DataAnnotations;
using McMaster.Extensions.CommandLineUtils;
using Steeltoe.Tooling.Executors;
namespace Steeltoe.Cli
{
[Command(Description = "Removes a custom dependency definition",
ExtendedHelpText = @"
Overview:
*** under construction ***
Examples:
Remove a dependency definition:
$ st undef-dep MyService
See Also:
def-dep
list-deps"
)]
public class UndefineDependencyCommand : Command
{
public const string CommandName = "undef-dep";
[Required(ErrorMessage = "Dependency not specified")]
[Argument(0, Name = "dep", Description = "Dependency")]
private string Dependency { get; set; }
[Option("--scope <scope>",
Description = "Sets the dependency definition scope (one of: project, global); default is project")]
private string Scope { get; set; }
public UndefineDependencyCommand(IConsole console) : base(console)
{
}
protected override Executor GetExecutor()
{
throw new NotImplementedException();
}
}
}

Просмотреть файл

@ -26,22 +26,6 @@ namespace Steeltoe.Tooling
{
private static readonly ILogger Logger = Logging.LoggerFactory.CreateLogger<Configuration>();
private string _target;
/// <summary>
/// Project deployment target.
/// </summary>
[YamlMember(Alias = "target")]
public string Target
{
get => _target;
set
{
_target = value;
NotifyChanged();
}
}
/// <summary>
/// Project applications.
/// </summary>
@ -87,7 +71,7 @@ namespace Steeltoe.Tooling
Logger.LogDebug($"removing app {app}");
if (!Apps.Remove(app))
{
throw new ItemDoesNotExistException(app, "app");
throw new ItemDoesNotExistException(app);
}
NotifyChanged();
@ -116,7 +100,7 @@ namespace Steeltoe.Tooling
}
else
{
throw new ItemDoesNotExistException(app, "app");
throw new ItemDoesNotExistException(app);
}
}
@ -131,7 +115,7 @@ namespace Steeltoe.Tooling
Logger.LogDebug($"setting app '{app}' args to '{args}'");
if (!Apps.ContainsKey(app))
{
throw new ItemDoesNotExistException(app, "app");
throw new ItemDoesNotExistException(app);
}
Apps[app].Args = args;
@ -150,12 +134,12 @@ namespace Steeltoe.Tooling
Logger.LogDebug($"setting app '{app}' args for target '{target}' to '{args}'");
if (!Registry.Targets.Contains(target))
{
throw new ItemDoesNotExistException(target, "target");
throw new ItemDoesNotExistException(target);
}
if (!Apps.ContainsKey(app))
{
throw new ItemDoesNotExistException(app, "app");
throw new ItemDoesNotExistException(app);
}
Apps[app].DeployArgs[target] = args;
@ -175,7 +159,7 @@ namespace Steeltoe.Tooling
}
catch (KeyNotFoundException)
{
throw new ItemDoesNotExistException(app, "app");
throw new ItemDoesNotExistException(app);
}
}
@ -189,7 +173,7 @@ namespace Steeltoe.Tooling
{
if (!Registry.Targets.Contains(target))
{
throw new ItemDoesNotExistException(target, "target");
throw new ItemDoesNotExistException(target);
}
try
@ -199,7 +183,7 @@ namespace Steeltoe.Tooling
}
catch (KeyNotFoundException)
{
throw new ItemDoesNotExistException(app, "app");
throw new ItemDoesNotExistException(app);
}
}
@ -214,7 +198,7 @@ namespace Steeltoe.Tooling
Logger.LogDebug($"adding service {serviceType} '{service}'");
if (!Registry.GetServiceTypes().Contains(serviceType))
{
throw new ItemDoesNotExistException(serviceType, "service type");
throw new ItemDoesNotExistException(serviceType);
}
if (Services.ContainsKey(service))
@ -236,7 +220,7 @@ namespace Steeltoe.Tooling
Logger.LogDebug($"removing service {service}");
if (!Services.Remove(service))
{
throw new ItemDoesNotExistException(service, "service");
throw new ItemDoesNotExistException(service);
}
NotifyChanged();
@ -265,7 +249,7 @@ namespace Steeltoe.Tooling
}
catch (KeyNotFoundException)
{
throw new ItemDoesNotExistException(service, "service");
throw new ItemDoesNotExistException(service);
}
}
@ -280,7 +264,7 @@ namespace Steeltoe.Tooling
Logger.LogDebug($"setting service '{service}' args to '{args}'");
if (!Services.ContainsKey(service))
{
throw new ItemDoesNotExistException(service, "service");
throw new ItemDoesNotExistException(service);
}
Services[service].Args = args;
@ -299,12 +283,12 @@ namespace Steeltoe.Tooling
Logger.LogDebug($"setting service '{service}' args for target '{target} to '{args}'");
if (!Registry.Targets.Contains(target))
{
throw new ItemDoesNotExistException(target, "target");
throw new ItemDoesNotExistException(target);
}
if (!Services.ContainsKey(service))
{
throw new ItemDoesNotExistException(service, "service");
throw new ItemDoesNotExistException(service);
}
Services[service].DeployArgs[target] = args;
@ -324,7 +308,7 @@ namespace Steeltoe.Tooling
}
catch (KeyNotFoundException)
{
throw new ItemDoesNotExistException(service, "service");
throw new ItemDoesNotExistException(service);
}
}
@ -338,7 +322,7 @@ namespace Steeltoe.Tooling
{
if (!Registry.Targets.Contains(target))
{
throw new ItemDoesNotExistException(target, "target");
throw new ItemDoesNotExistException(target);
}
try
@ -348,7 +332,7 @@ namespace Steeltoe.Tooling
}
catch (KeyNotFoundException)
{
throw new ItemDoesNotExistException(service, "service");
throw new ItemDoesNotExistException(service);
}
}

Просмотреть файл

@ -41,28 +41,6 @@ namespace Steeltoe.Tooling
/// </summary>
public Shell Shell { get; }
/// <summary>
/// Steeltoe Tooling deployment target.
/// </summary>
/// <exception cref="ToolingException">Throw if the target has not been set.</exception>
public Target Target
{
get
{
if (Configuration?.Target == null)
{
throw new ToolingException("Target not set");
}
return Registry.GetTarget(Configuration.Target);
}
}
/// <summary>
/// Steeltoe Tooling driver. The driver is used to deploy applications and their services.
/// </summary>
public IDriver Driver => Target.GetDriver(this);
/// <summary>
/// Creates a new Steeltoe Tooling Content.
/// </summary>

Просмотреть файл

@ -1,172 +0,0 @@
// Copyright 2018 the original author or authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
using System.Collections.Generic;
using System.ComponentModel.Design;
using System.IO;
using System.Text.RegularExpressions;
namespace Steeltoe.Tooling.Drivers.CloudFoundry
{
internal class CloudFoundryDriver : IDriver
{
private readonly Context _context;
private readonly Cli _cfCli;
private readonly Cli _dotnetCli;
internal CloudFoundryDriver(Context context)
{
_context = context;
_cfCli = new CloudFoundryCli(context.Shell);
_dotnetCli = new Cli("dotnet", _context.Shell);
}
public void DeploySetup()
{
}
public void DeployTeardown()
{
}
public void DeployApp(string app)
{
var manifestPath = Path.Combine(_context.ProjectDirectory, CloudFoundryManifestFile.DefaultFileName);
if (File.Exists(manifestPath))
{
File.Delete(manifestPath);
}
var manifestFile = new CloudFoundryManifestFile(manifestPath);
var cloudFoundryApp = new CloudFoundryManifest.Application();
cloudFoundryApp.Name = app;
cloudFoundryApp.Memory = "512M";
cloudFoundryApp.Environment = new Dictionary<string, string> {{"ASPNETCORE_ENVIRONMENT", "development"}};
cloudFoundryApp.ServiceNames = _context.Configuration.GetServices();
if (_context.Configuration.Apps[app].TargetRuntime.StartsWith("ubuntu"))
{
cloudFoundryApp.BuildPacks = new List<string> {"dotnet_core_buildpack"};
cloudFoundryApp.Command = $"cd ${{HOME}} && ./{Path.GetFileName(_context.ProjectDirectory)}";
}
else
{
cloudFoundryApp.Stack = "windows";
cloudFoundryApp.BuildPacks = new List<string> {"hwc_buildpack"};
cloudFoundryApp.Command = $"cmd /c .\\{Path.GetFileName(_context.ProjectDirectory)}";
}
manifestFile.CloudFoundryManifest.Applications.Add(cloudFoundryApp);
manifestFile.Store();
var framework = _context.Configuration.Apps[app].TargetFramework;
var runtime = _context.Configuration.Apps[app].TargetRuntime;
_dotnetCli.Run($"publish -f {framework} -r {runtime}", "publishing app");
_cfCli.Run(
$"push -f {CloudFoundryManifestFile.DefaultFileName} -p bin/Debug/{framework}/{runtime}/publish",
"pushing app to Cloud Foundry");
}
public void UndeployApp(string app)
{
_cfCli.Run($"delete {app} -f", $"deleting Cloud Foundry app");
}
public Lifecycle.Status GetAppStatus(string app)
{
try
{
var appInfo = _cfCli.Run($"app {app}", "getting details for Cloud Foundry app");
var state = new Regex(@"^#0\s+(\S+)", RegexOptions.Multiline).Match(appInfo).Groups[1].ToString()
.Trim();
switch (state)
{
case "down":
return Lifecycle.Status.Starting;
case "running":
return Lifecycle.Status.Online;
}
}
catch (CliException e)
{
if (e.Error.Contains($"App {app} not found"))
{
return Lifecycle.Status.Offline;
}
if (e.Error.Contains($"App '{app}' not found"))
{
return Lifecycle.Status.Offline;
}
}
return Lifecycle.Status.Unknown;
}
public void DeployService(string service)
{
var svcInfo = _context.Configuration.GetServiceInfo(service);
_context.Target.Configuration.ServiceTypeProperties.TryGetValue(svcInfo.ServiceType, out var cfServiceDef);
if (cfServiceDef == null)
{
throw new ToolingException(
$"No Cloud Foundry service available for '{svcInfo.Service}' [{svcInfo.ServiceType}]");
}
var cfCmd = $"create-service {cfServiceDef["service"]} {cfServiceDef["plan"]} {service}";
var svcArgs = _context.Configuration.GetServiceArgs(service, "cloud-foundry") ?? "";
if (svcArgs.Length > 0)
{
svcArgs = svcArgs.Replace("\"", "\"\"\"");
cfCmd += $" {svcArgs}";
}
_cfCli.Run(cfCmd, "creating Cloud Foundry service");
}
public void UndeployService(string service)
{
_cfCli.Run($"delete-service {service} -f", "deleting Cloud Foundry service");
}
public Lifecycle.Status GetServiceStatus(string service)
{
try
{
var serviceInfo = _cfCli.Run($"service {service}", "getting details for Cloud Foundry service");
var state = new Regex(@"^status:\s+(.*)$", RegexOptions.Multiline).Match(serviceInfo).Groups[1]
.ToString().Trim();
switch (state)
{
case "create in progress":
return Lifecycle.Status.Starting;
case "create succeeded":
return Lifecycle.Status.Online;
case "delete in progress":
return Lifecycle.Status.Stopping;
}
}
catch (CliException e)
{
if (e.Error.Contains($"Service instance {service} not found"))
{
return Lifecycle.Status.Offline;
}
}
return Lifecycle.Status.Unknown;
}
}
}

Просмотреть файл

@ -1,57 +0,0 @@
// Copyright 2018 the original author or authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
namespace Steeltoe.Tooling.Drivers.CloudFoundry
{
internal class CloudFoundryTarget : Target
{
internal CloudFoundryTarget(TargetConfiguration configuration) : base(configuration)
{
}
public override IDriver GetDriver(Context context)
{
return new CloudFoundryDriver(context);
}
public override bool IsHealthy(Context context)
{
var cli = new CloudFoundryCli(context.Shell);
try
{
context.Console.Write($"Cloud Foundry ... ");
context.Console.WriteLine(cli.Run("--version", "getting Cloud Foundry CLI version").Trim());
}
catch (ShellException)
{
context.Console.WriteLine($"!!! {cli.Command} command not found");
return false;
}
try
{
context.Console.Write("logged into Cloud Foundry ... ");
cli.Run("target", "checking if logged into Cloud Foundry");
context.Console.WriteLine("yes");
}
catch (ToolingException)
{
context.Console.WriteLine("!!! no");
return false;
}
return true;
}
}
}

Просмотреть файл

@ -1,172 +0,0 @@
// Copyright 2018 the original author or authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
using System;
using System.IO;
using System.Linq;
using System.Net.Sockets;
using System.Text.RegularExpressions;
namespace Steeltoe.Tooling.Drivers.Docker
{
internal class DockerDriver : IDriver
{
private const string Localhost = "127.0.0.1";
private const string HardCodedFramework = "netcoreapp2.1";
private const int HardCodedLocalPort = 8080;
private const int HardCodedRemotePort = 80;
private readonly Context _context;
private readonly DockerCli _dockerCli;
private readonly Cli _dotnetCli;
internal DockerDriver(Context context)
{
_context = context;
_dockerCli = new DockerCli(_context.Shell);
_dotnetCli = new Cli("dotnet", _context.Shell);
}
public void DeploySetup()
{
_dockerCli.Run(
$"network create {GetNetworkName()}",
"creating network");
}
public void DeployTeardown()
{
_dockerCli.Run(
$"network rm {GetNetworkName()}",
"destroying network");
}
private string GetNetworkName()
{
if (_context.Configuration.Apps.Count > 0)
{
return $"{_context.Configuration.Apps.First().Key}-network";
}
return $"{_context.Configuration.Services.First().Key}-network";
}
public void DeployApp(string app)
{
_dotnetCli.Run($"publish -f {HardCodedFramework}", "publishing dotnet app");
var dotnetImage = _context.Target.GetProperty("dotnetRuntimeImage");
var projectDll =
$"bin/Debug/{HardCodedFramework}/publish/{Path.GetFileName(_context.ProjectDirectory)}.dll";
const string appDir = "/app";
var mount = $"{Path.GetFullPath(_context.ProjectDirectory)}:{appDir}";
var portMap = $"{HardCodedLocalPort}:{HardCodedRemotePort}";
_dockerCli.Run(
$"run --name {app} --volume {mount} --workdir {appDir} --env ASPNETCORE_ENVIRONMENT=Docker --publish {portMap} --rm --detach {dotnetImage} dotnet {projectDll}",
"running app in Docker container");
_dockerCli.Run(
$"network connect {GetNetworkName()} {app}",
$"attaching {app} to network");
}
public void UndeployApp(string app)
{
_dockerCli.Run(
$"network disconnect {GetNetworkName()} {app}",
$"detaching {app} from network");
_dockerCli.Run($"stop {app}", "stopping Docker container for app");
}
public Lifecycle.Status GetAppStatus(string app)
{
return GetContainerStatus(app, HardCodedLocalPort);
}
public void DeployService(string service)
{
var dockerInfo = new DockerCli(_context.Shell).Run("info", "getting Docker container OS");
var dockerOs = new Regex(@"OSType:\s*(\S+)", RegexOptions.Multiline).Match(dockerInfo).Groups[1].ToString();
DeployService(service, dockerOs);
_dockerCli.Run(
$"network connect {GetNetworkName()} {service}",
$"attaching {service} to network");
}
public void DeployService(string service, string os)
{
var svcInfo = _context.Configuration.GetServiceInfo(service);
var port = Registry.GetServiceTypeInfo(svcInfo.ServiceType).Port;
var image = LookupImage(svcInfo.ServiceType, os);
var dockerCmd = $"run --name {service} --publish {port}:{port} --detach --rm";
var svcArgs = _context.Configuration.GetServiceArgs(service, "docker") ?? "";
if (svcArgs.Length > 0)
{
svcArgs = svcArgs.Replace("\"", "\"\"\"");
dockerCmd += $" {svcArgs}";
}
dockerCmd += $" {image}";
_dockerCli.Run(dockerCmd, "running Docker container for service");
}
public void UndeployService(string service)
{
_dockerCli.Run(
$"network disconnect {GetNetworkName()} {service}",
$"detaching {service} from network");
_dockerCli.Run($"stop {service}", "stopping Docker container for service");
}
public Lifecycle.Status GetServiceStatus(string service)
{
var svcInfo = _context.Configuration.GetServiceInfo(service);
var port = Registry.GetServiceTypeInfo(svcInfo.ServiceType).Port;
return GetContainerStatus(service, port);
}
private Lifecycle.Status GetContainerStatus(string name, int port)
{
var containerInfo = _dockerCli.Run($"ps --no-trunc --filter name=^/{name}$", "getting Docker container status").Split('\n');
if (containerInfo.Length <= 2)
{
return Lifecycle.Status.Offline;
}
var statusStart = containerInfo[0].IndexOf("STATUS", StringComparison.Ordinal);
if (!containerInfo[1].Substring(statusStart).StartsWith("Up "))
{
return Lifecycle.Status.Unknown;
}
try
{
new TcpClient(Localhost, port).Dispose();
return Lifecycle.Status.Online;
}
catch (SocketException)
{
return Lifecycle.Status.Starting;
}
}
private string LookupImage(string type, string os)
{
var images = _context.Target.Configuration.ServiceTypeProperties[type];
return images.TryGetValue($"image-{os}", out var image) ? image : images["image"];
}
}
}

Просмотреть файл

@ -1,64 +0,0 @@
// Copyright 2018 the original author or authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
using System.Text.RegularExpressions;
namespace Steeltoe.Tooling.Drivers.Docker
{
internal class DockerTarget : Target
{
internal DockerTarget(TargetConfiguration configuration) : base(configuration)
{
}
public override IDriver GetDriver(Context context)
{
return new DockerDriver(context);
}
public override bool IsHealthy(Context context)
{
var console = context.Console;
console.Write("Docker ... ");
var cli = new DockerCli(context.Shell);
try
{
var dockerVersion = cli.Run("--version", "getting Docker CLI version").Trim();
console.WriteLine(dockerVersion);
var dockerInfo = cli.Run("info", "getting Docker info");
console.Write("Docker host OS ... ");
context.Console.WriteLine(new Regex(@"Operating System:\s*(.+)", RegexOptions.Multiline)
.Match(dockerInfo).Groups[1].ToString());
console.Write("Docker container OS ... ");
context.Console.WriteLine(new Regex(@"OSType:\s*(.+)", RegexOptions.Multiline)
.Match(dockerInfo).Groups[1].ToString());
return true;
}
catch (CliException e)
{
context.Console.WriteLine($"!!! {e.Message}");
return false;
}
catch (ShellException)
{
context.Console.WriteLine($"!!! {cli.Command} command not found");
return false;
}
}
}
}

Просмотреть файл

@ -1,94 +0,0 @@
// Copyright 2018 the original author or authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
namespace Steeltoe.Tooling.Drivers.Dummy
{
internal class DummyDriver : IDriver
{
private readonly string _path;
private DummyServiceDatabase _database;
internal DummyDriver(string path)
{
_path = path;
_database = DummyServiceDatabase.Load(_path);
}
public void DeploySetup()
{
}
public void DeployTeardown()
{
}
public void DeployApp(string app)
{
_database.Apps.Add(app);
Store();
}
public void UndeployApp(string app)
{
_database.Apps.Remove(app);
Store();
}
public Lifecycle.Status GetAppStatus(string app)
{
return _database.Apps.Contains(app) ? Lifecycle.Status.Online : Lifecycle.Status.Offline;
}
public void DeployService(string service)
{
_database.Services[service] = Lifecycle.Status.Starting;
Store();
}
public void UndeployService(string service)
{
_database.Services[service] = Lifecycle.Status.Stopping;
Store();
}
public Lifecycle.Status GetServiceStatus(string service)
{
if (!_database.Services.ContainsKey(service))
{
return Lifecycle.Status.Offline;
}
var state = _database.Services[service];
switch (state)
{
case Lifecycle.Status.Starting:
_database.Services[service] = Lifecycle.Status.Online;
Store();
break;
case Lifecycle.Status.Stopping:
_database.Services.Remove(service);
Store();
break;
}
return state;
}
private void Store()
{
DummyServiceDatabase.Store(_path, _database);
}
}
}

Просмотреть файл

@ -1,36 +0,0 @@
// Copyright 2018 the original author or authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
using System.IO;
namespace Steeltoe.Tooling.Drivers.Dummy
{
internal class DummyTarget : Target
{
internal DummyTarget(TargetConfiguration configuration) : base(configuration)
{
}
public override IDriver GetDriver(Context context)
{
return new DummyDriver(Path.Combine(context.ProjectDirectory, "dummy-service-driver.db"));
}
public override bool IsHealthy(Context context)
{
context.Console.WriteLine("dummy tool version ... 0.0.0");
return true;
}
}
}

Просмотреть файл

@ -1,286 +0,0 @@
// Copyright 2018 the original author or authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
using System;
using System.Collections.Generic;
using System.IO;
using System.Runtime.InteropServices;
using System.Text.RegularExpressions;
namespace Steeltoe.Tooling.Drivers.Kubernetes
{
internal class KubernetesDriver : IDriver
{
private readonly Context _context;
private readonly Cli _kubectlCli;
private readonly Cli _dockerCli;
private const string ServiceKind = "Service";
private const string HardCodedServiceApiVersion = "v1";
private const string DeploymentKind = "Deployment";
private const string NodePort = "NodePort";
private const string ImagePullNever = "Never";
private const string HardCodedDeploymentApiVersion = "apps/v1";
internal KubernetesDriver(Context context)
{
_context = context;
_kubectlCli = new KubernetesCli(context.Shell);
_dockerCli = new DockerCli(context.Shell);
}
public void DeploySetup()
{
}
public void DeployTeardown()
{
}
public void DeployApp(string app)
{
KubernetesDotnetAppDockerfileFile dockerfileFile =
new KubernetesDotnetAppDockerfileFile(Path.Join(_context.ProjectDirectory, "Dockerfile"));
var dockerfile = dockerfileFile.KubernetesDotnetAppDockerfile;
dockerfile.App = app;
dockerfile.AppPath = "/app";
dockerfile.BaseImage = "steeltoeoss/dotnet-runtime:2.1";
dockerfile.BuildPath = "bin/Debug/netcoreapp2.1/publish";
dockerfile.Environment["ASPNETCORE_ENVIRONMENT"] = "Docker";
dockerfileFile.Store();
_dockerCli.Run($"build --tag {app.ToLower()} .", "building Docker image for app");
void PreSaveAction(KubernetesDeploymentConfig deployCfg, KubernetesServiceConfig svcCfg)
{
deployCfg.Spec.Template.Spec.Containers[0].ImagePullPolicy = ImagePullNever;
deployCfg.Spec.Template.Spec.Containers[0].Env =
new List<KubernetesDeploymentConfig.DeploymentSpec.ServiceTemplate.TemplateSpec.Container.
NameValuePair>
{
new KubernetesDeploymentConfig.DeploymentSpec.ServiceTemplate.TemplateSpec.Container.
NameValuePair() {Name = "GET_HOSTS_FROM", Value = "dns"}
};
svcCfg.Spec.Type = NodePort;
}
// TODO: get 'port' from somewhere else
// TODO: get 'image' from somewhere else
DeployKubernetesService(app, app.ToLower(), 80, PreSaveAction);
// var appPodInfo = _kubectlCli.Run($"get pods --selector app={app.ToLower()}", "getting app pod");
// var pod = new Regex($"^({app.ToLower()}-\\S+)", RegexOptions.Multiline).Match(appPodInfo).Groups[1].ToString();
// _kubectlCli.Run($"port-forward {pod} 8080:80", "forwarding port 8080->80");
}
public void UndeployApp(string app)
{
UndeployKubernetesService(app);
}
public Lifecycle.Status GetAppStatus(string app)
{
return GetKubernetesServiceStatus(app);
}
public void DeployService(string service)
{
// TODO: get 'os' from from docker command
DeployService(service, "linux");
}
public void UndeployService(string service)
{
UndeployKubernetesService(service);
}
public Lifecycle.Status GetServiceStatus(string service)
{
return GetKubernetesServiceStatus(service);
}
internal void DeployService(string service, string os)
{
var svcInfo = _context.Configuration.GetServiceInfo(service);
var port = Registry.GetServiceTypeInfo(svcInfo.ServiceType).Port;
var image = LookupImage(svcInfo.ServiceType, os);
DeployKubernetesService(service, image, port);
}
private void DeployKubernetesService(String name, String image, int port,
Action<KubernetesDeploymentConfig, KubernetesServiceConfig> preSaveAction = null)
{
var deployCfgFile =
new KubernetesDeploymentConfigFile(Path.Join(_context.ProjectDirectory, $"{name}-deployment.yaml"));
var deployCfg = deployCfgFile.KubernetesDeploymentConfig;
deployCfg.ApiVersion = HardCodedDeploymentApiVersion;
deployCfg.Kind = DeploymentKind;
deployCfg.MetaData = new KubernetesConfig.ConfigMetaData()
{
Name = name.ToLower(),
Labels = new Dictionary<string, string>()
{
{"app", name.ToLower()}
}
};
deployCfg.Spec = new KubernetesDeploymentConfig.DeploymentSpec()
{
Selector = new KubernetesDeploymentConfig.DeploymentSpec.ServiceSelector()
{
MatchLabels = new Dictionary<string, string>()
{
{"app", name.ToLower()}
}
},
Template = new KubernetesDeploymentConfig.DeploymentSpec.ServiceTemplate()
{
MetaData = new KubernetesDeploymentConfig.DeploymentSpec.ServiceTemplate.ServiceMetaData()
{
Labels = new Dictionary<string, string>()
{
{"app", name.ToLower()}
}
},
Spec = new KubernetesDeploymentConfig.DeploymentSpec.ServiceTemplate.TemplateSpec()
{
Containers =
new List<KubernetesDeploymentConfig.DeploymentSpec.ServiceTemplate.TemplateSpec.Container>()
{
new KubernetesDeploymentConfig.DeploymentSpec.ServiceTemplate.TemplateSpec.Container()
{
Name = name.ToLower(),
Image = image,
Ports = new List<KubernetesConfig.ServicePorts>()
{
new KubernetesConfig.ServicePorts()
{
ContainerPort = port
}
}
}
}
}
}
};
var svcCfgFile =
new KubernetesServiceConfigFile(Path.Combine(_context.ProjectDirectory, $"{name}-service.yaml"));
var svcCfg = svcCfgFile.KubernetesServiceConfig;
svcCfg.ApiVersion = HardCodedServiceApiVersion;
svcCfg.Kind = ServiceKind;
svcCfg.MetaData = new KubernetesConfig.ConfigMetaData()
{
Name = name.ToLower()
};
svcCfg.Spec = new KubernetesServiceConfig.ServiceSpec()
{
Ports = new List<KubernetesConfig.ServicePorts>()
{
new KubernetesConfig.ServicePorts()
{
Port = port
}
},
Selector = new Dictionary<string, string>()
{
{
"app", name.ToLower()
}
}
};
preSaveAction?.Invoke(deployCfg, svcCfg);
deployCfgFile.Store();
svcCfgFile.Store();
_kubectlCli.Run($"apply --filename {Path.GetFileName(deployCfgFile.File)}",
"applying Kubernetes deployment configuration");
_kubectlCli.Run($"apply --filename {Path.GetFileName(svcCfgFile.File)}",
"applying Kubernetes service configuration");
}
private void UndeployKubernetesService(string name)
{
try
{
_kubectlCli.Run($"delete --filename {name}-service.yaml", "deleting Kubernetes service");
}
catch (CliException)
{
_context.Console.WriteLine($"hmm, Kubernetes service doesn't seem to exist: {name}");
}
_kubectlCli.Run($"delete --filename {name}-deployment.yaml", "deleting Kubernetes deployment");
}
private Lifecycle.Status GetKubernetesServiceStatus(String name)
{
var podInfo = _kubectlCli.Run($"get pods --selector app={name.ToLower()}",
"getting Kubernetes deployment status");
if (podInfo.Contains("Running"))
{
return Lifecycle.Status.Online;
}
else if (podInfo.Contains("Pending") || podInfo.Contains("ContainerCreating"))
{
return Lifecycle.Status.Starting;
}
else if (podInfo.Contains("Terminating"))
{
return Lifecycle.Status.Stopping;
}
else if (podInfo.Contains("CrashLoopBackOff")) // TODO: is this the correct assumption? need a new state?
{
return Lifecycle.Status.Online;
}
else if (string.IsNullOrEmpty(podInfo))
{
try
{
_kubectlCli.Run($"get services {name.ToLower()}", "getting Kubernetes service status");
return Lifecycle.Status.Stopping;
}
catch (CliException)
{
return Lifecycle.Status.Offline;
}
}
return Lifecycle.Status.Unknown;
}
private string LookupImage(string type, string os)
{
var images = _context.Target.Configuration.ServiceTypeProperties[type];
return images.TryGetValue($"image-{os}", out var image) ? image : images["image"];
}
}
internal class KubernetesCli : Cli
{
internal KubernetesCli(Shell shell) : base("kubectl", shell)
{
}
}
internal class DockerCli : Cli
{
public DockerCli(Shell shell) : base("docker", shell)
{
}
}
}

Просмотреть файл

@ -1,69 +0,0 @@
// Copyright 2018 the original author or authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
using System.Text.RegularExpressions;
namespace Steeltoe.Tooling.Drivers.Kubernetes
{
internal class KubernetesTarget : Target
{
internal KubernetesTarget(TargetConfiguration configuration) : base(configuration)
{
}
public override IDriver GetDriver(Context context)
{
return new KubernetesDriver(context);
}
public override bool IsHealthy(Context context)
{
var cli = new KubernetesCli(context.Shell);
try
{
context.Console.Write($"Kubernetes ... ");
var versionInfo = cli.Run("version", "getting Kubernetes CLI version");
var matcher =
new Regex(@"Client Version:.*Major:""(\d+).*Minor:""(\d+)", RegexOptions.Multiline).Match(
versionInfo);
var clientVersion = $"{matcher.Groups[1]}.{matcher.Groups[2]}";
matcher =
new Regex(@"Server Version:.*Major:""(\d+).*Minor:""(\d+)", RegexOptions.Multiline).Match(
versionInfo);
var serverVersion = $"{matcher.Groups[1]}.{matcher.Groups[2]}";
context.Console.WriteLine($"kubectl client version {clientVersion}, server version {serverVersion}");
}
catch (ShellException)
{
context.Console.WriteLine($"!!! {cli.Command} command not found");
return false;
}
try
{
context.Console.Write("current context ... ");
var contextInfo = cli.Run("config get-contexts", "getting Kubernetes context");
var matcher = new Regex(@"\*\s+(\S+)", RegexOptions.Multiline).Match(contextInfo);
context.Console.WriteLine(matcher.Groups[1]);
}
catch (ToolingException)
{
context.Console.WriteLine("!!!");
return false;
}
return true;
}
}
}

Просмотреть файл

@ -1,71 +0,0 @@
// Copyright 2018 the original author or authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
using System.IO;
using System.Net.Http.Headers;
using System.Xml;
namespace Steeltoe.Tooling.Executors
{
/// <summary>
/// A workflow to add an application or service to the Steeltoe Tooling configuration.
/// </summary>
[RequiresInitialization]
public class AddAppExecutor : Executor
{
private readonly string _name;
private readonly string _framework;
private readonly string _runtime;
/// <summary>
/// Create a new workflow to add an application to the Steeltoe Tooling configuration.
/// </summary>
/// <param name="appName">Application name.</param>
/// <param name="framework">Target framework.</param>
/// <param name="runtime">Target runtime.</param>
public AddAppExecutor(string appName, string framework, string runtime)
{
_name = appName;
_framework = framework;
_runtime = runtime;
}
/// <summary>
/// Add the application or service to the Steeltoe Tooling configuration.
/// </summary>
protected override void Execute()
{
var framework = _framework ?? GuessFramework();
var runtime = _runtime ?? "ubuntu.16.04-x64";
Context.Configuration.AddApp(_name, framework, runtime);
Context.Console.WriteLine($"Added app '{_name}' ({framework}/{runtime})");
}
private string GuessFramework()
{
var projectFile = Path.Join(Context.ProjectDirectory, $"{_name}.csproj");
if (!File.Exists(projectFile))
{
throw new ToolingException($"project file does not exist: {projectFile}");
}
var doc = new XmlDocument();
doc.Load(projectFile);
var nodes = doc.GetElementsByTagName("TargetFramework");
var frameworks = nodes[0].InnerText;
return frameworks.Split(";")[0];
}
}
}

Просмотреть файл

@ -1,47 +0,0 @@
// Copyright 2018 the original author or authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
namespace Steeltoe.Tooling.Executors
{
/// <summary>
/// A workflow to add a service to the Steeltoe Tooling configuration.
/// </summary>
[RequiresInitialization]
public class AddServiceExecutor : Executor
{
private readonly string _name;
private readonly string _serviceType;
/// <summary>
/// Create a new workflow to add a service to the Steeltoe Tooling configuration.
/// </summary>
/// <param name="serviceName">Service name.</param>
/// <param name="serviceType">Service type.</param>
public AddServiceExecutor(string serviceName, string serviceType)
{
_name = serviceName;
_serviceType = serviceType;
}
/// <summary>
/// Add the application or service to the Steeltoe Tooling configuration.
/// </summary>
protected override void Execute()
{
Context.Configuration.AddService(_name, _serviceType);
Context.Console.WriteLine($"Added {_serviceType} service '{_name}'");
}
}
}

Просмотреть файл

@ -1,60 +0,0 @@
// Copyright 2018 the original author or authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
namespace Steeltoe.Tooling.Executors
{
/// <summary>
/// An abstract class representing a workflow relating to an application or service.
/// </summary>
public abstract class AppOrServiceExecutor : Executor
{
/// <summary>
/// The name of the related application or service.
/// </summary>
protected string AppOrServiceName { get; private set; }
/// <summary>
/// Create a workflow relating to an application or service.
/// </summary>
/// <param name="appOrServiceName"></param>
protected AppOrServiceExecutor(string appOrServiceName)
{
AppOrServiceName = appOrServiceName;
}
/// <summary>
/// Execute this workflow.
/// </summary>
/// <exception cref="ItemDoesNotExistException">If the application or service relating to this workflow does not exist.</exception>
protected override void Execute()
{
if (Context.Configuration.GetApps().Contains(AppOrServiceName))
{
ExecuteForApp();
}
else if (Context.Configuration.GetServices().Contains(AppOrServiceName))
{
ExecuteForService();
}
else
{
throw new ItemDoesNotExistException(AppOrServiceName, "app or service");
}
}
internal abstract void ExecuteForApp();
internal abstract void ExecuteForService();
}
}

Просмотреть файл

@ -1,84 +0,0 @@
// Copyright 2018 the original author or authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
using System;
using System.Collections.Generic;
using System.Threading;
namespace Steeltoe.Tooling.Executors
{
/// <summary>
/// A workflow to deploy applications and dependent services to the current target.
/// </summary>
[RequiresTarget]
public class DeployExecutor : GroupExecutor
{
/// <summary>
/// Create a new workflow to deploy applications and dependent services to the current target.
/// </summary>
public DeployExecutor() : base(false)
{
}
/// <summary>
/// Calls Driver.DeploySetup then defers to base class.
/// </summary>
protected override void Execute()
{
Context.Driver.DeploySetup();
base.Execute();
}
/// <summary>
/// Deploys apps then blocks until all apps online.
/// </summary>
/// <param name="apps">Apps to deploy.</param>
protected override void ExecuteForApps(List<string> apps)
{
base.ExecuteForApps(apps);
WaitUntilAllTransitioned(apps, Context.Driver.GetAppStatus, Lifecycle.Status.Online);
}
/// <summary>
/// Deploys services then blocks until all services online.
/// </summary>
/// <param name="services">Services to deploy.</param>
protected override void ExecuteForServices(List<string> services)
{
base.ExecuteForServices(services);
WaitUntilAllTransitioned(services, Context.Driver.GetServiceStatus, Lifecycle.Status.Online);
}
/// <summary>
/// Deploy the app.
/// </summary>
/// <param name="app">App name.</param>
protected override void ExecuteForApp(string app)
{
Context.Console.WriteLine($"Deploying app '{app}'");
new Lifecycle(Context, app).Deploy();
}
/// <summary>
/// Deploy the service.
/// </summary>
/// <param name="service">Service name.</param>
protected override void ExecuteForService(string service)
{
Context.Console.WriteLine($"Deploying service '{service}'");
new Lifecycle(Context, service).Deploy();
}
}
}

Просмотреть файл

@ -37,28 +37,6 @@ namespace Steeltoe.Tooling.Executors
{
var type = GetType();
Logger.LogDebug($"executor is {type}");
foreach (var attr in type.GetCustomAttributes(true))
{
if (attr is RequiresInitializationAttribute)
{
Logger.LogDebug($"{type} requires configuration");
if (context.Configuration == null)
{
throw new ToolingException("Steeltoe Developer Tools has not been initialized");
}
}
if (attr is RequiresTargetAttribute)
{
Logger.LogDebug($"{type} requires target");
if (context.Target == null)
{
throw new ToolingException("Target has not been set");
}
}
}
Context = context;
Execute();
}

Просмотреть файл

@ -1,59 +0,0 @@
// Copyright 2018 the original author or authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
namespace Steeltoe.Tooling.Executors
{
/// <summary>
/// A workflow to get the arguments of an application or service.
/// </summary>
[RequiresInitialization]
public class GetArgsExecutor : AppOrServiceExecutor
{
private readonly string _target;
/// <summary>
/// A workflow to display the arguments for an application or service.
/// If <code>target</code> is null, display the application or service arguments.
/// If <code>target</code> is not null, display the arguments for deploying the application or service.
/// </summary>
/// <param name="appOrServiceName">Application or service name.</param>
/// <param name="target">Deployment target name (can be null).</param>
public GetArgsExecutor(string appOrServiceName, string target = null) : base(appOrServiceName)
{
_target = target;
}
internal override void ExecuteForApp()
{
ShowArgs(_target == null
? Context.Configuration.GetAppArgs(AppOrServiceName)
: Context.Configuration.GetAppArgs(AppOrServiceName, _target));
}
internal override void ExecuteForService()
{
ShowArgs(_target == null
? Context.Configuration.GetServiceArgs(AppOrServiceName)
: Context.Configuration.GetServiceArgs(AppOrServiceName, _target));
}
private void ShowArgs(string args)
{
if (args != null)
{
Context.Console.WriteLine(args);
}
}
}
}

Просмотреть файл

@ -1,31 +0,0 @@
// Copyright 2018 the original author or authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
namespace Steeltoe.Tooling.Executors
{
/// <summary>
/// A workflow to display the current deployment target.
/// </summary>
[RequiresTarget]
public class GetTargetExecutor : Executor
{
/// <summary>
/// Display the current deployment target.
/// </summary>
protected override void Execute()
{
Context.Console.WriteLine(Context.Configuration.Target);
}
}
}

Просмотреть файл

@ -1,138 +0,0 @@
// Copyright 2018 the original author or authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
using System;
using System.Collections.Generic;
using System.Threading;
namespace Steeltoe.Tooling.Executors
{
/// <summary>
/// An abstract workflow operating on a group of applications and dependent services.
/// </summary>
public abstract class GroupExecutor : Executor
{
private readonly bool _appsFirst;
/// <summary>
/// Create a workflow to operate on a group of applications and dependent services.
/// </summary>
/// <param name="appsFirst">Whether applications or services are operated on first.</param>
protected GroupExecutor(Boolean appsFirst)
{
_appsFirst = appsFirst;
}
/// <summary>
/// Execute this workflow on the applications and dependent services.
/// </summary>
protected override void Execute()
{
var services = Context.Configuration.GetServices();
var apps = Context.Configuration.GetApps();
if (_appsFirst)
{
ExecuteForApps(apps);
ExecuteForServices(services);
}
else
{
ExecuteForServices(services);
ExecuteForApps(apps);
}
}
/// <summary>
/// Calls <see cref="ExecuteForApp"/> for each app.
/// </summary>
/// <param name="apps">Apps on which to be executed</param>
protected virtual void ExecuteForApps(List<string> apps)
{
foreach (var app in apps)
{
ExecuteForApp(app);
}
}
/// <summary>
/// Calls <see cref="ExecuteForService"/> for each service.
/// </summary>
/// <param name="services">Services on which to be executed</param>
protected virtual void ExecuteForServices(List<string> services)
{
foreach (var service in services)
{
ExecuteForService(service);
}
}
/// <summary>
/// Subclasses implement their business logic for executing on an app.
/// </summary>
/// <param name="app">App on which to be executed.</param>
protected abstract void ExecuteForApp(string app);
/// <summary>
/// Subclasses implement their business logic for executing on a service.
/// </summary>
/// <param name="service">Service on which to be executed.</param>
protected abstract void ExecuteForService(string service);
/// <summary>
/// A convenience for subclasses to wait until all apps (or services) have transitioned to a desired state.
/// </summary>
/// <param name="appsOrServices">A list of either app or service names.</param>
/// <param name="statusCheck">A function that returns the status of an app or service.</param>
/// <param name="status">The desired state.</param>
/// <exception cref="ToolingException">If <see cref="Settings.MaxChecks"/> exceeded.</exception>
protected void WaitUntilAllTransitioned(List<string> appsOrServices, Func<string, Lifecycle.Status> statusCheck,
Lifecycle.Status status)
{
foreach (var appOrService in appsOrServices)
{
var count = 0;
while (true)
{
++count;
if (Settings.MaxChecks > 0)
{
if (count > Settings.MaxChecks)
{
throw new ToolingException($"max checks exceeded ({Settings.MaxChecks})");
}
}
if (statusCheck(appOrService) == status)
{
break;
}
const int ticksPerMillis = 10000;
const int oneSecondMillis = 1000;
var startTicks = DateTime.Now.Ticks;
var elapsedMillis = (DateTime.Now.Ticks - startTicks) / ticksPerMillis;
var waitMillis = oneSecondMillis - elapsedMillis;
if (waitMillis > 0L)
{
Thread.Sleep((int) waitMillis);
}
Context.Console.WriteLine(
$"Waiting for '{appOrService}' to transition to {status.ToString().ToLower()} ({count})");
}
}
}
}
}

Просмотреть файл

@ -1,84 +0,0 @@
// Copyright 2018 the original author or authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
using System.IO;
using Steeltoe.Tooling.Scanners;
namespace Steeltoe.Tooling.Executors
{
/// <summary>
/// A workflow to initialize the Steeltoe Tooling configuration.
/// </summary>
public class InitializationExecutor : Executor
{
private readonly string _path;
private readonly bool _autodetect;
private readonly bool _force;
/// <summary>
/// Create a workflow to initialize the Steeltoe Tooling configuration file.
/// If the <paramref name="path"/> is null, the default path is used.
/// If the <paramref name="path"/> is a directory, the path is the directory joined with the default file name.
/// </summary>
/// <param name="path">Path to the Steeltoe Configuration file.</param>
/// <param name="autodetect">Detect apps when initializing.</param>
/// <param name="force">Forces the overwriting of an existing configuration file.</param>
/// <seealso cref="ConfigurationFile"/>.
public InitializationExecutor(string path = null, bool autodetect = false, bool force = false)
{
_path = path;
_autodetect = autodetect;
_force = force;
}
/// <summary>
/// Initialize the Steeltoe Configuration file.
/// </summary>
/// <exception cref="ToolingException">If an error occurs when initialization the Steeltoe Configuration file.</exception>
protected override void Execute()
{
var path = _path == null
? Context.ProjectDirectory
: Path.Combine(Context.ProjectDirectory, _path);
var cfgFile = new ConfigurationFile(path);
if (cfgFile.Exists())
{
if (!_force)
{
throw new ToolingException("Steeltoe Developer Tools already initialized");
}
File.Delete(cfgFile.File);
cfgFile = new ConfigurationFile(path);
}
Context.Configuration = cfgFile.Configuration;
if (_autodetect)
{
foreach (var appInfo in new AppScanner().Scan(Context.ProjectDirectory))
{
// TODO: guess framework/runtime rather than hardcode
new AddAppExecutor(appInfo.App, "netcoreapp2.1", "win10-x64").Execute(Context);
}
}
cfgFile.Store();
Context.Console.WriteLine("Initialized Steeltoe Developer Tools");
}
}
}

Просмотреть файл

@ -1,76 +0,0 @@
// Copyright 2018 the original author or authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
using System.Linq;
namespace Steeltoe.Tooling.Executors
{
/// <summary>
/// A workflow to display the applications and dependent services of the Steeltoe Tooling configuration.
/// </summary>
[RequiresInitialization]
public class ListExecutor : GroupExecutor
{
private readonly bool _verbose;
private string _format;
/// <summary>
/// Create a workflow to display the applications and dependent services of the Steeltoe Tooling configuration.
/// </summary>
/// <param name="verbose"></param>
public ListExecutor(bool verbose = false) : base(false)
{
_verbose = verbose;
}
/// <summary>
/// Display the applications and dependent services of the Steeltoe Tooling configuration.
/// </summary>
protected override void Execute()
{
var services = Context.Configuration.GetServices();
if (_verbose)
{
var max = services.Max(n => n.Length);
_format = "{0,-" + max + "} {1,5} {2}";
}
else
{
_format = "{0}";
}
base.Execute();
}
/// <summary>
/// Print app information.
/// </summary>
/// <param name="app">App name.</param>
protected override void ExecuteForApp(string app)
{
Context.Console.WriteLine(_format, app, "", "app");
}
/// <summary>
/// Print service information.
/// </summary>
/// <param name="service">Service name.</param>
protected override void ExecuteForService(string service)
{
var svcInfo = Context.Configuration.GetServiceInfo(service);
var svcTypeInfo = Registry.GetServiceTypeInfo(svcInfo.ServiceType);
Context.Console.WriteLine(_format, service, svcTypeInfo.Port, svcTypeInfo.Name);
}
}
}

Просмотреть файл

@ -1,52 +0,0 @@
// Copyright 2018 the original author or authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
using System.Linq;
namespace Steeltoe.Tooling.Executors
{
/// <summary>
/// A workflow to list available service types.
/// </summary>
public class ListServiceTypesExecutor : ListExecutor
{
/// <summary>
/// Creates a workflow to list available service types.
/// </summary>
/// <param name="verbose">if true, be verbose</param>
public ListServiceTypesExecutor(bool verbose = false) : base(verbose)
{
}
internal void ExecuteList(Context context)
{
foreach (var svcType in Registry.GetServiceTypes())
{
context.Console.WriteLine(svcType);
}
}
internal void ExecuteListVerbose(Context context)
{
var svcTypeNames = Registry.GetServiceTypes();
var max = svcTypeNames.Max(n => n.Length);
var format = "{0,-" + max + "} {1,5} {2}";
foreach (var svcTypeName in svcTypeNames)
{
var svcTypeInfo = Registry.GetServiceTypeInfo(svcTypeName);
context.Console.WriteLine(format, svcTypeInfo.Name, svcTypeInfo.Port, svcTypeInfo.Description);
}
}
}
}

Просмотреть файл

@ -1,52 +0,0 @@
// Copyright 2018 the original author or authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
using System.Linq;
namespace Steeltoe.Tooling.Executors
{
/// <summary>
/// A workflow to list available deployment targets.
/// </summary>
public class ListTargetsExecutor : ListExecutor
{
/// <summary>
/// Creates a workflow to list available deployment targets.
/// </summary>
/// <param name="verbose">if true, be verbose</param>
public ListTargetsExecutor(bool verbose = false) : base(verbose)
{
}
internal void ExecuteList(Context context)
{
foreach (var envName in Registry.Targets)
{
context.Console.WriteLine(envName);
}
}
internal void ExecuteListVerbose(Context context)
{
var targets = Registry.Targets;
var max = targets.Max(n => n.Length);
var format = "{0,-" + max + "} {1}";
foreach (var target in targets)
{
var tgtInfo = Registry.GetTarget(target);
context.Console.WriteLine(format, tgtInfo.Name, tgtInfo.Description);
}
}
}
}

Просмотреть файл

@ -1,44 +0,0 @@
// Copyright 2018 the original author or authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
namespace Steeltoe.Tooling.Executors
{
/// <summary>
/// A workflow to remove an application or service from the Steeltoe Tooling configuration.
/// </summary>
[RequiresInitialization]
public class RemoveExecutor : AppOrServiceExecutor
{
/// <summary>
/// Create a new workflow to remove an application or service from the Steeltoe Tooling configuration.
/// </summary>
/// <param name="appOrServiceName">Application or service name.</param>
public RemoveExecutor(string appOrServiceName) : base(appOrServiceName)
{
}
internal override void ExecuteForApp()
{
Context.Configuration.RemoveApp(AppOrServiceName);
Context.Console.WriteLine($"Removed app '{AppOrServiceName}'");
}
internal override void ExecuteForService()
{
var svcInfo = Context.Configuration.GetServiceInfo(AppOrServiceName);
Context.Configuration.RemoveService(AppOrServiceName);
Context.Console.WriteLine($"Removed {svcInfo.ServiceType} service '{AppOrServiceName}'");
}
}
}

Просмотреть файл

@ -1,26 +0,0 @@
// Copyright 2018 the original author or authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
using System;
namespace Steeltoe.Tooling.Executors
{
/// <summary>
/// An attribute indicating a workflow that needs an existing Steeltoe Configuration.
/// </summary>
[AttributeUsage(AttributeTargets.Class)]
public class RequiresInitializationAttribute : Attribute
{
}
}

Просмотреть файл

@ -1,26 +0,0 @@
// Copyright 2018 the original author or authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
using System;
namespace Steeltoe.Tooling.Executors
{
/// <summary>
/// An attribute that indicates a workflow that needs a configured deployment target.
/// </summary>
[AttributeUsage(AttributeTargets.Class)]
public class RequiresTargetAttribute: RequiresInitializationAttribute
{
}
}

Просмотреть файл

@ -1,143 +0,0 @@
// Copyright 2018 the original author or authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
namespace Steeltoe.Tooling.Executors
{
/// <summary>
/// A workflow to set the arguments of an application or service.
/// </summary>
[RequiresInitialization]
public class SetArgsExecutor : AppOrServiceExecutor
{
private readonly string _target;
private readonly string _args;
private readonly bool _force;
/// <summary>
/// A workflow to set the arguments for an application or service.
/// </summary>
/// <param name="appOrServiceName">Application or service name.</param>
/// <param name="args">Application or service arguments.</param>
/// <param name="force">Force replacement of existing arguments.</param>
public SetArgsExecutor(string appOrServiceName, string args, bool force = false)
: this(appOrServiceName, null, args, force)
{
}
/// <summary>
/// A workflow to set the arguments for an application or service.
/// If <code>target</code> is null, set the application or service arguments.
/// If <code>target</code> is not null, set the arguments for deploying the application or service.
/// </summary>
/// <param name="appOrServiceName">Application or service name.</param>
/// <param name="target">Deployment target name (can be null).</param>
/// <param name="args">Application or service arguments.</param>
/// <param name="force">Force replacement of existing arguments.</param>
public SetArgsExecutor(string appOrServiceName, string target, string args, bool force = false)
: base(appOrServiceName)
{
_target = target;
_args = args;
_force = force;
}
/// <summary>
/// Set the application arguments.
/// </summary>
internal override void ExecuteForApp()
{
if (_target == null)
{
ExecuteSetAppArgs();
}
else
{
ExecuteSetAppTargetArgs();
}
}
/// <summary>
/// Set the service arguments.
/// </summary>
internal override void ExecuteForService()
{
if (_target == null)
{
ExecuteSetServiceArgs();
}
else
{
ExecuteSetServiceTargetArgs();
}
}
private void ExecuteSetAppArgs()
{
var appName = AppOrServiceName;
var args = Context.Configuration.GetAppArgs(appName);
if (args != null && !_force)
{
throw new ToolingException($"'{appName}' app args already set to '{args}'");
}
Context.Configuration.SetAppArgs(appName, _args);
Context.Console.WriteLine($"Set '{appName}' app args to '{_args}'");
}
private void ExecuteSetAppTargetArgs()
{
var appName = AppOrServiceName;
var args = Context.Configuration.GetAppArgs(appName, _target);
if (args != null && !_force)
{
throw new ToolingException($"'{_target}' deploy args for '{appName}' app already set to '{args}'");
}
Context.Configuration.SetAppArgs(appName, _target, _args);
Context.Console.WriteLine($"Set '{_target}' deploy args for '{appName}' app to '{_args}'");
}
private void ExecuteSetServiceArgs()
{
var svcName = AppOrServiceName;
var svcInfo = Context.Configuration.GetServiceInfo(svcName);
var args = Context.Configuration.GetServiceArgs(svcName);
if (args != null && !_force)
{
throw new ToolingException($"'{svcName}' {svcInfo.ServiceType} service args already set to '{args}'");
}
Context.Configuration.SetServiceArgs(svcName, _args);
Context.Console.WriteLine($"Set '{svcName}' {svcInfo.ServiceType} service args to '{_args}'");
}
private void ExecuteSetServiceTargetArgs()
{
var svcName = AppOrServiceName;
var svcInfo = Context.Configuration.GetServiceInfo(svcName);
var args = Context.Configuration.GetServiceArgs(svcName, _target);
if (args != null && !_force)
{
throw new ToolingException(
$"'{_target}' deploy args for '{AppOrServiceName}' {svcInfo.ServiceType} service already set to '{args}'");
}
Context.Configuration.SetServiceArgs(AppOrServiceName, _target, _args);
Context.Console.WriteLine(
$"Set '{_target}' deploy args for '{AppOrServiceName}' {svcInfo.ServiceType} service to '{_args}'");
}
}
}

Просмотреть файл

@ -1,61 +0,0 @@
// Copyright 2018 the original author or authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
namespace Steeltoe.Tooling.Executors
{
/// <summary>
/// A workflow to set the current deployment target.
/// </summary>
[RequiresInitialization]
public class SetTargetExecutor : Executor
{
private readonly string _target;
private readonly bool _force;
/// <summary>
/// Create a workflow to set the current deployment target.
/// </summary>
/// <param name="target">Deployment target name.</param>
/// <param name="force">Overwrite an existing deployment target.</param>
public SetTargetExecutor(string target, bool force = false)
{
_target = target;
_force = force;
}
/// <summary>
/// Set the current deployment target.
/// </summary>
/// <exception cref="ToolingException">If an error occurs setting the deployment target.</exception>
protected override void Execute()
{
Target tgt = Registry.GetTarget(_target);
if (!tgt.IsHealthy(Context))
{
if (!_force)
{
Context.Console.WriteLine("Fix errors above or re-run with '-F|--force'");
throw new ToolingException($"Target '{_target}' does not appear healthy");
}
Context.Console.WriteLine("Ignoring poor health report above :-(");
}
Context.Configuration.Target = _target;
Context.Console.WriteLine($"Target set to '{_target}'");
}
}
}

Просмотреть файл

@ -1,50 +0,0 @@
// Copyright 2018 the original author or authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
namespace Steeltoe.Tooling.Executors
{
/// <summary>
/// A workflow to display the deployment status of applications and dependent services.
/// </summary>
[RequiresTarget]
public class StatusExecutor : GroupExecutor
{
/// <summary>
/// Create a workflow to display the deployment status of applications and dependent services.
/// </summary>
public StatusExecutor() : base(false)
{
}
/// <summary>
/// Print app status.
/// </summary>
/// <param name="app">App name.</param>
protected override void ExecuteForApp(string app)
{
var status = Context.Driver.GetAppStatus(app);
Context.Console.WriteLine($"{app} {status.ToString().ToLower()}");
}
/// <summary>
/// Print service status.
/// </summary>
/// <param name="service">Service name.</param>
protected override void ExecuteForService(string service)
{
var status = Context.Driver.GetServiceStatus(service);
Context.Console.WriteLine($"{service} {status.ToString().ToLower()}");
}
}
}

Просмотреть файл

@ -1,83 +0,0 @@
// Copyright 2018 the original author or authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
using System;
using System.Collections.Generic;
using System.Threading;
namespace Steeltoe.Tooling.Executors
{
/// <summary>
/// A workflow to undeploy applications and dependent services from the current target.
/// </summary>
[RequiresTarget]
public class UndeployExecutor : GroupExecutor
{
/// <summary>
/// Creates a workflow undeploy applications and dependent services from the current target.
/// </summary>
public UndeployExecutor() : base(true)
{
}
/// <summary>
/// Defers to base class then calls Driver.DeployTeardown.
/// </summary>
protected override void Execute()
{
base.Execute();
Context.Driver.DeployTeardown();
}
/// <summary>
/// Undeploys apps then blocks until all apps offline.
/// </summary>
/// <param name="apps">Apps to undeploy.</param>
protected override void ExecuteForApps(List<string> apps)
{
base.ExecuteForApps(apps);
WaitUntilAllTransitioned(apps, Context.Driver.GetAppStatus, Lifecycle.Status.Offline);
}
/// <summary>
/// Undeploys services then blocks until all apps offline.
/// </summary>
/// <param name="services">Services to undeploy.</param>
protected override void ExecuteForServices(List<string> services)
{
base.ExecuteForServices(services);
WaitUntilAllTransitioned(services, Context.Driver.GetServiceStatus, Lifecycle.Status.Offline);
}
/// <summary>
/// Undeploys an application to the current target.
/// </summary>
/// <param name="app">Application name.</param>
protected override void ExecuteForApp(string app)
{
Context.Console.WriteLine($"Undeploying app '{app}'");
new Lifecycle(Context, app).Undeploy();
}
/// <summary>
/// Undeploys a service to the current target.
/// </summary>
/// <param name="service">Service name.</param>
protected override void ExecuteForService(string service)
{
Context.Console.WriteLine($"Undeploying service '{service}'");
new Lifecycle(Context, service).Undeploy();
}
}
}

Просмотреть файл

@ -1,75 +0,0 @@
// Copyright 2018 the original author or authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
namespace Steeltoe.Tooling
{
/// <summary>
/// Defines the interface for Steeltoe Tooling drivers. Drivers are responsible for application and service
/// deployment and for reporting the state of applications and services.
/// </summary>
public interface IDriver
{
/// <summary>
/// Called before apps and/or services are deployed.
/// </summary>
void DeploySetup();
/// <summary>
/// Called affter apps and/or services are undeployed.
/// </summary>
void DeployTeardown();
/// <summary>
/// Deploys the named application.
/// </summary>
/// <param name="app">The application name.</param>
/// <remarks>Implementations may return before the application is fully deployed.</remarks>
void DeployApp(string app);
/// <summary>
/// Undeploys the named application.
/// </summary>
/// <param name="app">The application name.</param>
/// <remarks>Implementations may return before the application is fully undeployed.</remarks>
void UndeployApp(string app);
/// <summary>
/// Returns the named application's lifecycle status.
/// </summary>
/// <param name="app">The application name.</param>
/// <returns>The named application's lifecycle status.</returns>
Lifecycle.Status GetAppStatus(string app);
/// <summary>
/// Deploys the named service.
/// </summary>
/// <param name="service">The service name.</param>
/// <remarks>Implementations may return before the service is fully deployed.</remarks>
void DeployService(string service);
/// <summary>
/// Undeploys the named service.
/// </summary>
/// <param name="service">The service name.</param>
/// <remarks>Implementations may return before the service is fully undeployed.</remarks>
void UndeployService(string service);
/// <summary>
/// Returns the named service's lifecycle status.
/// </summary>
/// <param name="service">The service name.</param>
/// <returns>The named service's lifecycle status.</returns>
Lifecycle.Status GetServiceStatus(string service);
}
}

Просмотреть файл

@ -24,21 +24,14 @@ namespace Steeltoe.Tooling
/// </summary>
public string Name { get; }
/// <summary>
/// Item description.
/// </summary>
public string Description { get; }
/// <summary>
/// Creates a new ItemDoesNotExistException.
/// </summary>
/// <param name="name">Item name.</param>
/// <param name="description">Item description.</param>
public ItemDoesNotExistException(string name, string description) : base(
$"{char.ToUpper(description[0]) + description.Substring(1)} '{name}' does not exist")
public ItemDoesNotExistException(string name) : base(
$"'{name}' does not exist")
{
Name = name;
Description = description;
}
}
}

Просмотреть файл

@ -12,6 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
using System;
namespace Steeltoe.Tooling
{
/// <summary>
@ -52,8 +54,6 @@ namespace Steeltoe.Tooling
private readonly string _name;
private readonly DriverBridge _bridge;
/// <summary>
/// Creates a new lifecycle for the named application or application service.
/// </summary>
@ -61,16 +61,7 @@ namespace Steeltoe.Tooling
/// <param name="name">Application or application service name.</param>
public Lifecycle(Context context, string name)
{
var driver = context.Driver;
_name = name;
if (context.Configuration.GetApps().Contains(name))
{
_bridge = new AppDriverBridge(driver);
}
else
{
_bridge = new ServiceDriverBridge(driver);
}
}
/// <summary>
@ -79,25 +70,10 @@ namespace Steeltoe.Tooling
/// <returns></returns>
public Status GetStatus()
{
return _bridge.GetStatus(_name);
}
/// <summary>
/// Undeploy an application or application service in the context of this lifecycle.
/// </summary>
public void Undeploy()
{
GetState().Undeploy(_name, _bridge);
}
/// <summary>
/// Deploy an application or application service in the context of this lifecycle.
/// </summary>
public void Deploy()
{
GetState().Deploy(_name, _bridge);
throw new NotImplementedException();
}
/*
private State GetState()
{
var status = GetStatus();
@ -178,65 +154,6 @@ namespace Steeltoe.Tooling
return "stopping";
}
}
abstract class DriverBridge
{
protected readonly IDriver Driver;
protected DriverBridge(IDriver driver)
{
Driver = driver;
}
internal abstract Status GetStatus(string name);
internal abstract void Deploy(string name);
internal abstract void Undeploy(string name);
}
private class AppDriverBridge : DriverBridge
{
internal AppDriverBridge(IDriver driver) : base(driver)
{
}
internal override Status GetStatus(string name)
{
return Driver.GetAppStatus(name);
}
internal override void Deploy(string name)
{
Driver.DeployApp(name);
}
internal override void Undeploy(string name)
{
Driver.UndeployApp(name);
}
}
private class ServiceDriverBridge : DriverBridge
{
internal ServiceDriverBridge(IDriver driver) : base(driver)
{
}
internal override Status GetStatus(string name)
{
return Driver.GetServiceStatus(name);
}
internal override void Deploy(string name)
{
Driver.DeployService(name);
}
internal override void Undeploy(string name)
{
Driver.UndeployService(name);
}
}
*/
}
}

Просмотреть файл

@ -17,11 +17,8 @@ using System.IO;
using System.Linq;
using System.Reflection;
using Microsoft.Extensions.Logging;
using Steeltoe.Tooling.Drivers.CloudFoundry;
using Steeltoe.Tooling.Drivers.Docker;
using Steeltoe.Tooling.Drivers.Dummy;
using Steeltoe.Tooling.Drivers.Kubernetes;
using YamlDotNet.Serialization;
// ReSharper disable AutoPropertyCanBeMadeGetOnly.Global
namespace Steeltoe.Tooling
@ -162,34 +159,6 @@ namespace Steeltoe.Tooling
return null;
}
/// <summary>
/// Returns the named deployment target.
/// </summary>
/// <param name="target">Deployment target name.</param>
/// <returns>Named deployment target.</returns>
/// <exception cref="ToolingException">Thrown if there is no such deployment target.</exception>
public static Target GetTarget(string target)
{
TargetConfiguration targetCfg;
if (_configuration.TargetConfigurations.TryGetValue(target, out targetCfg))
{
targetCfg.Name = target;
switch (targetCfg.Name)
{
case "cloud-foundry":
return new CloudFoundryTarget(targetCfg);
case "docker":
return new DockerTarget(targetCfg);
case "kubernetes":
return new KubernetesTarget(targetCfg);
case "dummy-target":
return new DummyTarget(targetCfg);
}
}
throw new ToolingException($"Unknown target '{target}'");
}
private static void AddRegistryConfiguration(Configuration configuration)
{
foreach (var svcTypeEntry in configuration.ServiceTypes)

Просмотреть файл

@ -1,79 +0,0 @@
// Copyright 2018 the original author or authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
namespace Steeltoe.Tooling
{
/// <summary>
/// Represents a deployment target.
/// </summary>
public abstract class Target
{
/// <summary>
/// Deployment target configuration.
/// </summary>
public TargetConfiguration Configuration { get; }
/// <summary>
/// Deployment target name.
/// </summary>
public string Name => Configuration.Name;
/// <summary>
/// Deployment target description.
/// </summary>
public string Description => Configuration.Description;
/// <summary>
/// Creates a new Target.
/// </summary>
/// <param name="configuration">Deployment target configuration.</param>
protected Target(TargetConfiguration configuration)
{
Configuration = configuration;
}
/// <summary>
/// Return the deployment target driver.
/// </summary>
/// <param name="context">Steeltoe Tooling project context.</param>
/// <returns></returns>
public abstract IDriver GetDriver(Context context);
/// <summary>
/// Tests if the deployment target is healthy. E.g., is the target available.
/// </summary>
/// <param name="context">Steeltoe Tooling project context.</param>
/// <returns></returns>
public abstract bool IsHealthy(Context context);
/// <summary>
/// Return a human-readable representation of this Target.
/// </summary>
/// <returns>A human readable representation.</returns>
public override string ToString()
{
return $"Target[name={Name},desc=\"{Description}\"]";
}
/// <summary>
/// Return the named property value.
/// </summary>
/// <param name="name">Property name.</param>
/// <returns>Property value.</returns>
public string GetProperty(string name)
{
return Configuration.Properties[name];
}
}
}

Просмотреть файл

@ -1,115 +0,0 @@
// Copyright 2018 the original author or authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
using LightBDD.Framework.Scenarios.Extended;
using LightBDD.XUnit2;
namespace Steeltoe.Cli.Test
{
public class AddAppFeature : FeatureSpecs
{
[Scenario]
public void AddAppHelp()
{
Runner.RunScenario(
given => a_dotnet_project("add_app_help"),
when => the_developer_runs_cli_command("add-app --help"),
then => the_cli_should_output(new[]
{
"Add an app",
$"Usage: {Program.Name} add-app [arguments] [options]",
"Arguments:",
"name App name",
"Options:",
"-f|--framework Target framework",
"-r|--runtime Target runtime",
"-?|-h|--help Show help information",
})
);
}
[Scenario]
public void AddAppNotEnoughArgs()
{
Runner.RunScenario(
given => a_dotnet_project("add_app_not_enough"),
when => the_developer_runs_cli_command("add-app"),
then => the_cli_should_error(ErrorCode.Argument, "App name not specified")
);
}
[Scenario]
public void AddAppTooManyArgs()
{
Runner.RunScenario(
given => a_dotnet_project("add_app_too_many_args"),
when => the_developer_runs_cli_command("add-app arg1 arg2"),
then => the_cli_should_fail_parse("Unrecognized command or argument 'arg2'")
);
}
[Scenario]
public void AddAppUninitialized()
{
Runner.RunScenario(
given => a_dotnet_project("add_app_uninitialized"),
when => the_developer_runs_cli_command("add-app my-app"),
then => the_cli_should_error(ErrorCode.Tooling, "Steeltoe Developer Tools has not been initialized")
);
}
[Scenario]
public void AddApp()
{
Runner.RunScenario(
given => a_steeltoe_project("add_app"),
when => the_developer_runs_cli_command("add-app add_app"),
then => the_cli_should_output("Added app 'add_app' (netcoreapp3.1/ubuntu.16.04-x64)"),
and => the_configuration_should_contain_app("add_app")
);
}
[Scenario]
public void AddExistingApp()
{
Runner.RunScenario(
given => a_steeltoe_project("add_app_existing_app"),
when => the_developer_runs_cli_command("add-app add_app_existing_app"),
and => the_developer_runs_cli_command("add-app add_app_existing_app"),
then => the_cli_should_error(ErrorCode.Tooling, "App 'add_app_existing_app' already exists")
);
}
[Scenario]
public void AddAppFramework()
{
Runner.RunScenario(
given => a_steeltoe_project("add_app_framework"),
when => the_developer_runs_cli_command("add-app my-app -f dummy-framework"),
and => the_configuration_should_contain_app_framework("my-app", "dummy-framework")
);
}
[Scenario]
public void AddAppRuntime()
{
Runner.RunScenario(
given => a_steeltoe_project("add_app_runtime"),
when => the_developer_runs_cli_command("add-app add_app_runtime -r dummy-runtime"),
and => the_configuration_should_contain_app_runtime("add_app_runtime", "dummy-runtime")
);
}
}
}

Просмотреть файл

@ -0,0 +1,73 @@
// Copyright 2020 the original author or authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
using LightBDD.Framework.Scenarios.Extended;
using LightBDD.XUnit2;
namespace Steeltoe.Cli.Test
{
public class AddDependencyFeature : FeatureSpecs
{
[Scenario]
public void AddDependencyHelp()
{
Runner.RunScenario(
given => a_dotnet_project("add_dependency_help"),
when => the_developer_runs_cli_command("add-dep --help"),
then => the_cli_command_should_succeed(),
and => the_cli_should_output(new[]
{
"Adds a dependency",
$"Usage: {Program.Name} add-dep [arguments] [options]",
"Arguments:",
"dep The dependency to be added",
"Options:",
"-n|--name Sets the dependency name; default is <dep>",
"-?|-h|--help Show help information",
"Overview:",
"Explicitly add a dependency to the project. Useful when autodetection fails.",
"Examples:",
"Add a dependency on a Redis service:",
"$ st add-dep redis",
"Add a dependency on a Redis service and name it MyRedis:",
"$ st add-dep redis --name MyRedis",
"See Also:",
"rem-dep",
"list-deps",
})
);
}
[Scenario]
public void AddDependencyNotEnoughArgs()
{
Runner.RunScenario(
given => a_dotnet_project("add_dependency_not_enough_args"),
when => the_developer_runs_cli_command("add-dep"),
then => the_cli_should_error(ErrorCode.Argument, "Dependency not specified")
);
Console.Clear();
}
[Scenario]
public void AddDependencyTooManyArgs()
{
Runner.RunScenario(
given => a_dotnet_project("add_dependency_too_many_args"),
when => the_developer_runs_cli_command("add-dep arg1 arg2"),
then => the_cli_should_fail_parse("Unrecognized command or argument 'arg2'")
);
}
}
}

Просмотреть файл

@ -1,109 +0,0 @@
// Copyright 2018 the original author or authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
using LightBDD.Framework.Scenarios.Extended;
using LightBDD.XUnit2;
namespace Steeltoe.Cli.Test
{
public class AddServiceFeature : FeatureSpecs
{
[Scenario]
public void AddServiceHelp()
{
Runner.RunScenario(
given => a_dotnet_project("add_service_help"),
when => the_developer_runs_cli_command("add-service --help"),
then => the_cli_should_output(new[]
{
"Add a service",
$"Usage: {Program.Name} add-service [arguments] [options]",
"Arguments:",
"type Service type",
"name Service name",
"Options:",
"-?|-h|--help Show help information",
})
);
}
[Scenario]
public void AddServiceNotEnoughArgs()
{
Runner.RunScenario(
given => a_dotnet_project("add_service_not_enough"),
when => the_developer_runs_cli_command("add-service"),
then => the_cli_should_error(ErrorCode.Argument, "Service type not specified")
);
Console.Clear();
Runner.RunScenario(
given => a_dotnet_project("add_service_not_enough_args1"),
when => the_developer_runs_cli_command("add-service arg1"),
then => the_cli_should_error(ErrorCode.Argument, "Service name not specified")
);
}
[Scenario]
public void AddServiceTooManyArgs()
{
Runner.RunScenario(
given => a_dotnet_project("add_service_too_many_args"),
when => the_developer_runs_cli_command("add-service arg1 arg2 arg3"),
then => the_cli_should_fail_parse("Unrecognized command or argument 'arg3'")
);
}
[Scenario]
public void AddServiceUninitialized()
{
Runner.RunScenario(
given => a_dotnet_project("add_service_uninitialized"),
when => the_developer_runs_cli_command("add-service dummy-svc my-service"),
then => the_cli_should_error(ErrorCode.Tooling, "Steeltoe Developer Tools has not been initialized")
);
}
[Scenario]
public void AddUnknownServiceType()
{
Runner.RunScenario(
given => a_steeltoe_project("add_service_unknown_type"),
when => the_developer_runs_cli_command("add-service no-such-service-type foo"),
then => the_cli_should_error(ErrorCode.Tooling, "Service type 'no-such-service-type' does not exist")
);
}
[Scenario]
public void AddService()
{
Runner.RunScenario(
given => a_steeltoe_project("add_service"),
when => the_developer_runs_cli_command("add-service dummy-svc my-service"),
then => the_cli_should_output("Added dummy-svc service 'my-service'"),
and => the_configuration_should_contain_service("my-service", "dummy-svc")
);
}
[Scenario]
public void AddExistingService()
{
Runner.RunScenario(
given => a_steeltoe_project("add_service_existing_service"),
when => the_developer_runs_cli_command("add-service dummy-svc existing-service"),
and => the_developer_runs_cli_command("add-service dummy-svc existing-service"),
then => the_cli_should_error(ErrorCode.Tooling, "Service 'existing-service' already exists")
);
}
}
}

Просмотреть файл

@ -1,224 +0,0 @@
// Copyright 2018 the original author or authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
using LightBDD.Framework.Scenarios.Extended;
using LightBDD.XUnit2;
namespace Steeltoe.Cli.Test
{
public class ArgsFeature : FeatureSpecs
{
[Scenario]
public void ArgsHelp()
{
Runner.RunScenario(
given => a_dotnet_project("args_help"),
when => the_developer_runs_cli_command("args --help"),
then => the_cli_should_output(new[]
{
"Set or get the arguments for an app or service",
$"Usage: {Program.Name} args [arguments] [options] [[--] <arg>...]",
"Arguments:",
"name App or service name",
"args App or service arguments",
"Options:",
"-t|--target Apply the args to the deployment on the specified target",
"-F|--force Overwrite existing arguments",
"-?|-h|--help Show help information",
"If run with no arguments, show the current arguments for the app or service.",
})
);
}
[Scenario]
public void ArgsNotEnoughArgs()
{
Runner.RunScenario(
given => a_dotnet_project("args_not_enough"),
when => the_developer_runs_cli_command("args"),
then => the_cli_should_error(ErrorCode.Argument, "App or service name not specified")
);
}
[Scenario]
public void ArgsUninitialized()
{
Runner.RunScenario(
given => a_dotnet_project("args_uninitialized"),
when => the_developer_runs_cli_command("args foo arg1"),
then => the_cli_should_error(ErrorCode.Tooling, "Steeltoe Developer Tools has not been initialized"),
when => the_developer_runs_cli_command("args foo"),
then => the_cli_should_error(ErrorCode.Tooling, "Steeltoe Developer Tools has not been initialized")
);
}
[Scenario]
public void ArgsUnknownAppOrService()
{
Runner.RunScenario(
given => a_steeltoe_project("args_unknown_app_or_service"),
when => the_developer_runs_cli_command("args no-such-thing arg1"),
then => the_cli_should_error(ErrorCode.Tooling, "App or service 'no-such-thing' does not exist"),
when => the_developer_runs_cli_command("args no-such-thing"),
then => the_cli_should_error(ErrorCode.Tooling, "App or service 'no-such-thing' does not exist")
);
}
[Scenario]
public void ArgsApp()
{
Runner.RunScenario(
given => a_steeltoe_project("args_app"),
when => the_developer_runs_cli_command("add-app args_app"),
and => the_developer_runs_cli_command("args args_app"),
then => the_cli_should_output_nothing(),
when => the_developer_runs_cli_command("args args_app arg1 arg2"),
then => the_cli_should_output("Set 'args_app' app args to 'arg1 arg2'"),
and => the_configuration_should_contain_app_args("args_app", "arg1 arg2"),
when => the_developer_runs_cli_command("args args_app arg3"),
then => the_cli_should_error(ErrorCode.Tooling, "'args_app' app args already set to 'arg1 arg2'"),
when => the_developer_runs_cli_command("args args_app arg3 --force"),
then => the_cli_should_output("Set 'args_app' app args to 'arg3'"),
and => the_configuration_should_contain_app_args("args_app", "arg3"),
when => the_developer_runs_cli_command("args args_app"),
then => the_cli_should_output("arg3")
);
}
[Scenario]
public void ArgsAppDeploy()
{
Runner.RunScenario(
given => a_steeltoe_project("args_app_deploy"),
when => the_developer_runs_cli_command("add-app args_app_deploy"),
and => the_developer_runs_cli_command("args args_app_deploy -t dummy-target"),
then => the_cli_should_output_nothing(),
when => the_developer_runs_cli_command("args args_app_deploy -t dummy-target arg1 arg2"),
then => the_cli_should_output("Set 'dummy-target' deploy args for 'args_app_deploy' app to 'arg1 arg2'"),
and => the_configuration_should_contain_app_args("args_app_deploy", "dummy-target", "arg1 arg2"),
when => the_developer_runs_cli_command("args args_app_deploy -t dummy-target arg3"),
then => the_cli_should_error(ErrorCode.Tooling,
"'dummy-target' deploy args for 'args_app_deploy' app already set to 'arg1 arg2'"),
when => the_developer_runs_cli_command("args args_app_deploy -t dummy-target arg3 --force"),
then => the_cli_should_output("Set 'dummy-target' deploy args for 'args_app_deploy' app to 'arg3'"),
and => the_configuration_should_contain_app_args("args_app_deploy", "dummy-target", "arg3"),
when => the_developer_runs_cli_command("args args_app_deploy -t dummy-target"),
then => the_cli_should_output("arg3")
);
}
[Scenario]
public void ArgsAppWithOpt()
{
Runner.RunScenario(
given => a_steeltoe_project("args_app_with_opt"),
when => the_developer_runs_cli_command("add-app args_app_with_opt"),
and => the_developer_runs_cli_command("args args_app_with_opt -- arg1 -opt2"),
then => the_cli_should_output("Set 'args_app_with_opt' app args to 'arg1 -opt2'"),
and => the_configuration_should_contain_app_args("args_app_with_opt", "arg1 -opt2"),
when => the_developer_runs_cli_command("args args_app_with_opt"),
then => the_cli_should_output("arg1 -opt2")
);
}
[Scenario]
public void ArgsAppDeployWithOpt()
{
Runner.RunScenario(
given => a_steeltoe_project("args_app_deploy_with_opt"),
when => the_developer_runs_cli_command("add-app args_app_deploy_with_opt"),
and => the_developer_runs_cli_command("args args_app_deploy_with_opt -t dummy-target -- arg1 -opt2"),
then => the_cli_should_output("Set 'dummy-target' deploy args for 'args_app_deploy_with_opt' app to 'arg1 -opt2'"),
and => the_configuration_should_contain_app_args("args_app_deploy_with_opt", "dummy-target", "arg1 -opt2"),
when => the_developer_runs_cli_command("args args_app_deploy_with_opt -t dummy-target"),
then => the_cli_should_output("arg1 -opt2")
);
}
[Scenario]
public void ArgsService()
{
Runner.RunScenario(
given => a_steeltoe_project("args_service"),
when => the_developer_runs_cli_command("add-service dummy-svc my-service"),
and => the_developer_runs_cli_command("args my-service"),
then => the_cli_should_output_nothing(),
when => the_developer_runs_cli_command("args my-service arg1 arg2"),
then => the_cli_should_output("Set 'my-service' dummy-svc service args to 'arg1 arg2'"),
and => the_configuration_should_contain_service_args("my-service", "arg1 arg2"),
when => the_developer_runs_cli_command("args my-service arg3"),
then => the_cli_should_error(ErrorCode.Tooling,
"'my-service' dummy-svc service args already set to 'arg1 arg2'"),
when => the_developer_runs_cli_command("args my-service arg3 --force"),
then => the_cli_should_output("Set 'my-service' dummy-svc service args to 'arg3'"),
and => the_configuration_should_contain_service_args("my-service", "arg3"),
when => the_developer_runs_cli_command("args my-service"),
then => the_cli_should_output("arg3")
);
}
[Scenario]
public void ArgsServiceDeploy()
{
Runner.RunScenario(
given => a_steeltoe_project("args_service"),
when => the_developer_runs_cli_command("add-service dummy-svc my-service"),
and => the_developer_runs_cli_command("args my-service -t dummy-target"),
then => the_cli_should_output_nothing(),
when => the_developer_runs_cli_command("args my-service -t dummy-target arg1 arg2"),
then => the_cli_should_output(
"Set 'dummy-target' deploy args for 'my-service' dummy-svc service to 'arg1 arg2'"),
and => the_configuration_should_contain_service_args("my-service", "dummy-target", "arg1 arg2"),
when => the_developer_runs_cli_command("args my-service -t dummy-target arg3"),
then => the_cli_should_error(ErrorCode.Tooling,
"'dummy-target' deploy args for 'my-service' dummy-svc service already set to 'arg1 arg2'"),
when => the_developer_runs_cli_command("args my-service -t dummy-target arg3 --force"),
then => the_cli_should_output(
"Set 'dummy-target' deploy args for 'my-service' dummy-svc service to 'arg3'"),
and => the_configuration_should_contain_service_args("my-service", "dummy-target", "arg3"),
when => the_developer_runs_cli_command("args my-service -t dummy-target"),
then => the_cli_should_output("arg3")
);
}
[Scenario]
public void ArgsServiceWithOpt()
{
Runner.RunScenario(
given => a_steeltoe_project("args_service_with_opt"),
when => the_developer_runs_cli_command("add-service dummy-svc my-service"),
and => the_developer_runs_cli_command("args my-service -- arg1 -opt2"),
then => the_cli_should_output("Set 'my-service' dummy-svc service args to 'arg1 -opt2'"),
and => the_configuration_should_contain_service_args("my-service", "arg1 -opt2"),
when => the_developer_runs_cli_command("args my-service"),
then => the_cli_should_output("arg1 -opt2")
);
}
[Scenario]
public void ArgsServiceDeployWithOpt()
{
Runner.RunScenario(
given => a_steeltoe_project("args_service_deploy_with_opt"),
when => the_developer_runs_cli_command("add-service dummy-svc my-service"),
and => the_developer_runs_cli_command("args my-service -t dummy-target -- arg1 -opt2"),
then => the_cli_should_output(
"Set 'dummy-target' deploy args for 'my-service' dummy-svc service to 'arg1 -opt2'"),
and => the_configuration_should_contain_service_args("my-service", "dummy-target", "arg1 -opt2"),
when => the_developer_runs_cli_command("args my-service -t dummy-target"),
then => the_cli_should_output("arg1 -opt2")
);
}
}
}

Просмотреть файл

@ -0,0 +1,79 @@
// Copyright 2020 the original author or authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
using LightBDD.Framework.Scenarios.Extended;
using LightBDD.XUnit2;
namespace Steeltoe.Cli.Test
{
public class DefineDependencyFeature : FeatureSpecs
{
[Scenario]
public void DefineDependencyHelp()
{
Runner.RunScenario(
given => a_dotnet_project("define_dependency_help"),
when => the_developer_runs_cli_command("def-dep --help"),
then => the_cli_command_should_succeed(),
and => the_cli_should_output(new[]
{
"Adds a custom dependency definition",
$"Usage: {Program.Name} def-dep [arguments] [options]",
"Arguments:",
"dep Dependency",
"image Docker image",
"Options:",
"-p|--port <port> Sets a network port; may be specified multiple times",
"--nuget-package <name> Sets a NuGet package name for autodetection; may be specified multiple times",
"--scope <scope> Sets the dependency definition scope (one of: project, global); default is project",
"-?|-h|--help Show help information",
"Overview:",
"*** under construction ***",
"Examples:",
"Add a dependency definition for a service that listens on a couple of network ports:",
"$ st def-dep MyService myrepo/myimage --port 9876 --port 9877",
"Add a dependency definition for a service that can used in all projects:",
"$ st def-dep MyService myrepo/myimage --scope global",
"Add a dependency definition for a service that can be autodetected:",
"$ st def-dep MyService myrepo/myimage --nuget-package My.Service.NuGet",
"See Also:",
"undef-dep",
"list-deps",
})
);
}
[Scenario]
public void DefineDependencyNotEnoughArgs()
{
Runner.RunScenario(
given => a_dotnet_project("define_dependency_not_enough_args"),
when => the_developer_runs_cli_command("def-dep"),
then => the_cli_should_error(ErrorCode.Argument, "Dependency not specified"),
when => the_developer_runs_cli_command("def-dep arg1"),
then => the_cli_should_error(ErrorCode.Argument, "Docker image not specified")
);
}
[Scenario]
public void RemoveDependencyTooManyArgs()
{
Runner.RunScenario(
given => a_dotnet_project("define_dependency_too_many_args"),
when => the_developer_runs_cli_command("def-dep arg1 arg2 arg3"),
then => the_cli_should_fail_parse("Unrecognized command or argument 'arg3'")
);
}
}
}

Просмотреть файл

@ -1,100 +0,0 @@
// Copyright 2018 the original author or authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
using LightBDD.Framework.Scenarios.Extended;
using LightBDD.XUnit2;
namespace Steeltoe.Cli.Test
{
public class DeployFeature : FeatureSpecs
{
[Scenario]
public void DeployHelp()
{
Runner.RunScenario(
given => a_steeltoe_project("deploy_help"),
when => the_developer_runs_cli_command("deploy --help"),
then => the_cli_should_output(new[]
{
"Deploy apps and services to the target",
$"Usage: {Program.Name} deploy [options]",
"Options:",
"-?|-h|--help Show help information",
})
);
}
[Scenario]
public void DeployTooManyArgs()
{
Runner.RunScenario(
given => a_steeltoe_project("deploy_too_many_args"),
when => the_developer_runs_cli_command("deploy arg1"),
then => the_cli_should_fail_parse("Unrecognized command or argument 'arg1'")
);
}
[Scenario]
public void DeployUninitialized()
{
Runner.RunScenario(
given => a_dotnet_project("deploy_uninitialized"),
when => the_developer_runs_cli_command("deploy"),
then => the_cli_should_error(ErrorCode.Tooling, "Steeltoe Developer Tools has not been initialized")
);
}
[Scenario]
public void Deploy()
{
Runner.RunScenario(
given => a_steeltoe_project("deploy_services"),
when => the_developer_runs_cli_command("add-app deploy_services"),
and => the_developer_runs_cli_command("add-service dummy-svc my-service-a"),
and => the_developer_runs_cli_command("add-service dummy-svc my-service-b"),
and => the_developer_runs_cli_command("deploy"),
then => the_cli_should_output(new[]
{
"Deploying service 'my-service-a'",
"Deploying service 'my-service-b'",
"Waiting for 'my-service-a' to transition to online (1)",
"Waiting for 'my-service-b' to transition to online (1)",
"Deploying app 'deploy_services'",
})
);
}
[Scenario]
public void DeployNothing()
{
Runner.RunScenario(
given => a_steeltoe_project("deploy_nothing"),
when => the_developer_runs_cli_command("deploy"),
then => the_cli_should_output_nothing()
);
}
[Scenario]
public void DeployNoTarget()
{
Runner.RunScenario(
given => a_dotnet_project("deploy_no_target"),
when => the_developer_runs_cli_command("init"),
and => the_developer_runs_cli_command("add dummy-svc a-server"),
and => the_developer_runs_cli_command("deploy"),
then => the_cli_should_error(ErrorCode.Tooling, "Target not set")
);
}
}
}

Просмотреть файл

@ -27,7 +27,7 @@ namespace Steeltoe.Cli.Test
when => the_developer_runs_cli_command("doctor --help"),
then => the_cli_should_output(new[]
{
"Check for potential problems",
"Checks for potential problems",
$"Usage: {Program.Name} doctor [options]",
"Options:",
"-?|-h|--help Show help information",
@ -45,27 +45,6 @@ namespace Steeltoe.Cli.Test
);
}
[Scenario]
public void DoctorUninitialized()
{
Runner.RunScenario(
given => a_dotnet_project("doctor_uninitialized"),
when => the_developer_runs_cli_command("doctor"),
then => the_cli_output_should_include(
$"initialized ... !!! no (run '{Program.Name} init' to initialize)")
);
}
[Scenario]
public void DoctorInitialized()
{
Runner.RunScenario(
given => a_steeltoe_project("doctor_initialized"),
when => the_developer_runs_cli_command("doctor"),
then => the_cli_output_should_include("initialized ... yes")
);
}
[Scenario]
public void DoctorVersion()
{
@ -85,27 +64,5 @@ namespace Steeltoe.Cli.Test
then => the_cli_output_should_include("DotNet ... dotnet version ")
);
}
[Scenario]
public void DoctorTarget()
{
Runner.RunScenario(
given => a_steeltoe_project("doctor_target"),
when => the_developer_runs_cli_command("doctor"),
then => the_cli_output_should_include("target ... dummy-target")
);
}
[Scenario]
public void DoctorNoTarget()
{
Runner.RunScenario(
given => a_dotnet_project("doctor_no_target"),
when => the_developer_runs_cli_command("init"),
and => the_developer_runs_cli_command("doctor"),
then => the_cli_output_should_include(
$"target ... !!! not set (run '{Program.Name} target <env>' to set)")
);
}
}
}

Просмотреть файл

@ -90,7 +90,6 @@ namespace scratch
a_dotnet_project(name);
Logger.LogInformation($"enabling steeltoe developer tools");
var cfgFile = new ConfigurationFile(ProjectDirectory);
cfgFile.Configuration.Target = "dummy-target";
cfgFile.Store();
}
@ -114,7 +113,12 @@ namespace scratch
.UseConstructorInjection(svcs);
CommandException = null;
var args = command.Split(null);
var args = command.Split();
if (args.Length == 1 && args[0].Length == 0)
{
args = new string[0];
}
try
{
CommandExitCode = app.Execute(args);
@ -178,29 +182,21 @@ namespace scratch
actualMessages.ShouldBe(messages);
}
protected void the_cli_should_output(string message)
{
the_cli_should_output(new[] {message});
}
protected void the_cli_output_should_include(string message)
{
the_cli_command_should_succeed();
Logger.LogInformation($"checking the cli output includes '{message}'");
NormalizeString(Console.Out.ToString()).ShouldContain(message);
}
protected void the_cli_should_output_nothing()
protected void the_cli_should_error(ErrorCode code)
{
the_cli_command_should_succeed();
Logger.LogInformation($"checking the cli output nothing");
Console.Out.ToString().Trim().ShouldBeEmpty();
Logger.LogInformation($"checking the command failed with {(int) code}");
CommandExitCode.ShouldBe((int) code);
}
protected void the_cli_should_error(ErrorCode code, string error)
{
Logger.LogInformation($"checking the command failed with {(int) code}");
CommandExitCode.ShouldBe((int) code);
the_cli_should_error(code);
Logger.LogInformation($"checking the cli errored '{error}'");
NormalizeString(Console.Error.ToString()).ShouldBe(error);
}
@ -225,17 +221,10 @@ namespace scratch
{
Logger.LogInformation($"checking the configuration should be empty");
var config = new ConfigurationFile(ProjectDirectory).Configuration;
config.Target.ShouldBeNull();
config.Apps.Count.ShouldBe(0);
config.Services.Count.ShouldBe(0);
}
protected void the_configuration_should_target(string env)
{
Logger.LogInformation($"checking the target config '{env}' exists");
new ConfigurationFile(ProjectDirectory).Configuration.Target.ShouldBe(env);
}
protected void the_configuration_should_contain_app(string app)
{
Logger.LogInformation($"checking the app '{app}' exists");

Просмотреть файл

@ -1,105 +0,0 @@
// Copyright 2018 the original author or authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
using LightBDD.Framework.Scenarios.Extended;
using LightBDD.XUnit2;
namespace Steeltoe.Cli.Test
{
public class InitFeature : FeatureSpecs
{
[Scenario]
public void InitHelp()
{
Runner.RunScenario(
given => a_dotnet_project("init_help"),
when => the_developer_runs_cli_command("init --help"),
then => the_cli_should_output(new[]
{
"Initialize Steeltoe Developer Tools",
$"Usage: {Program.Name} init [options]",
"Options:",
"-a|--autodetect Autodetect application",
"-F|--force Initialize the project even if already initialized",
"-?|-h|--help Show help information",
})
);
}
[Scenario]
public void InitTooManyArgs()
{
Runner.RunScenario(
given => a_dotnet_project("init_too_many_args"),
when => the_developer_runs_cli_command("init arg1"),
then => the_cli_should_fail_parse("Unrecognized command or argument 'arg1'")
);
}
[Scenario]
public void Init()
{
Runner.RunScenario(
given => a_dotnet_project("init"),
when => the_developer_runs_cli_command("init"),
then => the_cli_should_output(new[]
{
"Initialized Steeltoe Developer Tools",
})
);
}
[Scenario]
public void InitAutodetect()
{
Runner.RunScenario(
given => a_dotnet_project("init_autodetect"),
when => the_developer_runs_cli_command("init --autodetect"),
then => the_configuration_should_contain_app("init_autodetect"),
then => the_cli_should_output(new[]
{
"Added app 'init_autodetect' (netcoreapp2.1/win10-x64)",
"Initialized Steeltoe Developer Tools",
})
);
}
[Scenario]
public void InitEmptyDirectory()
{
Runner.RunScenario(
given => an_empty_directory("empty_directory"),
when => the_developer_runs_cli_command("init"),
then => the_configuration_should_be_empty(),
and => the_cli_should_output("Initialized Steeltoe Developer Tools")
);
}
[Scenario]
public void InitForce()
{
Runner.RunScenario(
given => a_steeltoe_project("init_force"),
and => the_developer_runs_cli_command("init"),
then => the_cli_should_error(ErrorCode.Tooling, "Steeltoe Developer Tools already initialized"),
when => the_developer_runs_cli_command("init --force"),
then => the_configuration_should_be_empty(),
and => the_cli_should_output(new[]
{
"Initialized Steeltoe Developer Tools",
})
);
}
}
}

Просмотреть файл

@ -0,0 +1,50 @@
// Copyright 2020 the original author or authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
using LightBDD.Framework.Scenarios.Extended;
using LightBDD.XUnit2;
namespace Steeltoe.Cli.Test
{
public class ListConfigurations : FeatureSpecs
{
[Scenario]
public void ListConfigurationsHelp()
{
Runner.RunScenario(
given => a_dotnet_project("list_configurations_help"),
when => the_developer_runs_cli_command("list-cfgs --help"),
then => the_cli_should_output(new[]
{
"Displays a list of available configurations",
$"Usage: {Program.Name} list-cfgs [options]",
"Options:",
"-?|-h|--help Show help information",
"Overview:",
"*** under construction ***",
})
);
}
[Scenario]
public void ListConfigurationsTooManyArgs()
{
Runner.RunScenario(
given => a_dotnet_project("list_configurations_too_many_args"),
when => the_developer_runs_cli_command("list-cfgs arg1"),
then => the_cli_should_fail_parse("Unrecognized command or argument 'arg1'")
);
}
}
}

Просмотреть файл

@ -0,0 +1,50 @@
// Copyright 2020 the original author or authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
using LightBDD.Framework.Scenarios.Extended;
using LightBDD.XUnit2;
namespace Steeltoe.Cli.Test
{
public class ListDependencies : FeatureSpecs
{
[Scenario]
public void ListDependenciesHelp()
{
Runner.RunScenario(
given => a_dotnet_project("list_dependencies_help"),
when => the_developer_runs_cli_command("list-deps --help"),
then => the_cli_should_output(new[]
{
"Displays a list of available dependencies",
$"Usage: {Program.Name} list-deps [options]",
"Options:",
"-?|-h|--help Show help information",
"Overview:",
"*** under construction ***",
})
);
}
[Scenario]
public void ListDependenciesTooManyArgs()
{
Runner.RunScenario(
given => a_dotnet_project("list_dependencies_too_many_args"),
when => the_developer_runs_cli_command("list-deps arg1"),
then => the_cli_should_fail_parse("Unrecognized command or argument 'arg1'")
);
}
}
}

Просмотреть файл

@ -1,175 +0,0 @@
// Copyright 2018 the original author or authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
using LightBDD.Framework.Scenarios.Extended;
using LightBDD.XUnit2;
namespace Steeltoe.Cli.Test
{
public class ListFeature : FeatureSpecs
{
[Scenario]
public void ListHelp()
{
Runner.RunScenario(
given => a_dotnet_project("list_help"),
when => the_developer_runs_cli_command("list --help"),
then => the_cli_should_output(new[]
{
"List apps and services",
$"Usage: {Program.Name} list [options]",
"Options:",
"-v|--verbose Verbose",
"-?|-h|--help Show help information",
})
);
}
[Scenario]
public void ListTooManyArgs()
{
Runner.RunScenario(
given => a_dotnet_project("list_too_many_args"),
when => the_developer_runs_cli_command("list arg1"),
then => the_cli_should_fail_parse("Unrecognized command or argument 'arg1'")
);
}
[Scenario]
public void ListUninitialized()
{
Runner.RunScenario(
given => a_dotnet_project("list_uninitialized"),
when => the_developer_runs_cli_command("list"),
then => the_cli_should_error(ErrorCode.Tooling, "Steeltoe Developer Tools has not been initialized")
);
}
/*
[Scenario]
public void ListEnvironments()
{
Runner.RunScenario(
given => a_steeltoe_project("list_environments"),
when => the_developer_runs_cli_command("list -e"),
then => the_cli_should_output(new[]
{
"cloud-foundry",
"docker",
"dummy-target",
})
);
}
*/
/*
[Scenario]
public void ListEnvironmentsVerbose()
{
Runner.RunScenario(
given => a_steeltoe_project("list_environments_verbose"),
when => the_developer_runs_cli_command("list -e -v"),
then => the_cli_should_output(new[]
{
"cloud-foundry Cloud Foundry",
"docker Docker",
"dummy-target A Dummy Target",
})
);
}
*/
/*
[Scenario]
public void ListServiceTypes()
{
Runner.RunScenario(
given => a_steeltoe_project("list_service_types"),
when => the_developer_runs_cli_command("list -t"),
then => the_cli_should_output(new[]
{
"config-server",
"dummy-svc",
"eureka-server",
"hystrix-dashboard",
"mssql",
"mysql",
"redis",
"zipkin",
})
);
}
*/
/*
[Scenario]
public void ListServiceTypesVerbose()
{
Runner.RunScenario(
given => a_steeltoe_project("list_service_types_verbose"),
when => the_developer_runs_cli_command("list -t -v"),
then => the_cli_should_output(new[]
{
"config-server 8888 Cloud Foundry Config Server",
"dummy-svc 0 A Dummy Service",
"eureka-server 8761 Netflix Eureka Server",
"hystrix-dashboard 7979 Netflix Hystrix Dashboard",
"mssql 1433 Microsoft SQL Server",
"mysql 3306 Microsoft SQL Server",
"postgresql 5432 PostgreSQL Server",
"rabbitmq 5672 RabbitMQ Message Broker",
"redis 6379 Redis In-Memory Datastore",
"zipkin 9411 Zipkin Tracing Collector and UI",
})
);
}
*/
[Scenario]
public void ListServices()
{
Runner.RunScenario(
given => a_steeltoe_project("list_services"),
when => the_developer_runs_cli_command("add-service dummy-svc my-service-c"),
and => the_developer_runs_cli_command("add-service dummy-svc my-service-b"),
and => the_developer_runs_cli_command("add-service dummy-svc my-service-a"),
and => the_developer_runs_cli_command("list"),
then => the_cli_should_output(new[]
{
"my-service-a",
"my-service-b",
"my-service-c",
})
);
}
[Scenario]
public void ListServicesVerbose()
{
Runner.RunScenario(
given => a_steeltoe_project("list_services_verbose"),
when => the_developer_runs_cli_command("add-service dummy-svc my-service-c"),
and => the_developer_runs_cli_command("add-service dummy-svc my-service-b"),
and => the_developer_runs_cli_command("add-service dummy-svc my-service-a"),
and => the_developer_runs_cli_command("list -v"),
then => the_cli_should_output(new[]
{
"my-service-a 0 dummy-svc",
"my-service-b 0 dummy-svc",
"my-service-c 0 dummy-svc",
})
);
}
}
}

Просмотреть файл

@ -0,0 +1,50 @@
// Copyright 2020 the original author or authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
using LightBDD.Framework.Scenarios.Extended;
using LightBDD.XUnit2;
namespace Steeltoe.Cli.Test
{
public class ListTemplates : FeatureSpecs
{
[Scenario]
public void ListTemplatesHelp()
{
Runner.RunScenario(
given => a_dotnet_project("list_dependencies_help"),
when => the_developer_runs_cli_command("list-deps --help"),
then => the_cli_should_output(new[]
{
"Displays a list of available dependencies",
$"Usage: {Program.Name} list-deps [options]",
"Options:",
"-?|-h|--help Show help information",
"Overview:",
"*** under construction ***",
})
);
}
[Scenario]
public void ListTemplatesTooManyArgs()
{
Runner.RunScenario(
given => a_dotnet_project("list_dependencies_too_many_args"),
when => the_developer_runs_cli_command("list-deps arg1"),
then => the_cli_should_fail_parse("Unrecognized command or argument 'arg1'")
);
}
}
}

Просмотреть файл

@ -0,0 +1,74 @@
// Copyright 2020 the original author or authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
using LightBDD.Framework.Scenarios.Extended;
using LightBDD.XUnit2;
namespace Steeltoe.Cli.Test
{
public class NewConfigurationFeature : FeatureSpecs
{
[Scenario]
public void NewConfigurationHelp()
{
Runner.RunScenario(
given => a_dotnet_project("generate_configuration_help"),
when => the_developer_runs_cli_command("new-cfg --help"),
then => the_cli_should_output(new[]
{
"Creates configuration files for a target",
$"Usage: {Program.Name} new-cfg [options]",
"Options:",
"-T|--target <target> Sets the configuration target (one of: Docker, Kubernetes, Cloud-Foundry); default is 'Docker'",
"-n|--name <cfgname> Sets the configuration name; default is the project name",
"-o|--output <path> Sets the location to place the generated configuration; default is the current directory",
"-f|--framework <framework> Sets the framework; default is the project framework",
"-a|--arg <arg> Sets a command line argument for the application",
"-e|--env <name>=<value> Sets an environment variable for the application; may be specified multiple times",
"--dep-arg <depname>:<arg> Sets a command line argument for the named dependency",
"--dep-env <depname>:<name>=<value> Sets an environment variable for the named dependency; may be specified multiple times",
"-F|--force Forces configuration to be generated even if it would change existing files",
"-?|-h|--help Show help information",
"Overview:",
"Creates configuration files for a target. By default, files are generated for the Docker target.",
"Docker configurations can subsequently be used by the run command.",
"Examples:",
"Create the default configuration:",
"$ st new-cfg",
"Re-create the default configuration for a project in a specific directory:",
"$ st new-cfg --force --project-dir src/MyProj",
"Create a configuration for Kubernetes using the netcoreapp2.1 framework:",
"$ st new-cfg --target k8s --framework netcoreapp2.1",
"Create a named configuration with application arguments:",
"$ st new-cfg --name MyCustomDockerConfig --application-arg arg1 --application-arg arg2",
"Create a configuration that sets an environment variable for a dependency:",
"$ st new-cfg --dependency-env MyDB:ACCEPT_EULA=Y",
"See Also:",
"show-cfg",
"run",
})
);
}
[Scenario]
public void NewConfigurationTooManyArgs()
{
Runner.RunScenario(
given => a_dotnet_project("new_configuration_too_many_args"),
when => the_developer_runs_cli_command("new-cfg arg1"),
then => the_cli_should_fail_parse("Unrecognized command or argument 'arg1'")
);
}
}
}

Просмотреть файл

@ -0,0 +1,75 @@
// Copyright 2020 the original author or authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
using LightBDD.Framework.Scenarios.Extended;
using LightBDD.XUnit2;
namespace Steeltoe.Cli.Test
{
public class NewFeature : FeatureSpecs
{
[Scenario]
public void NewHelp()
{
Runner.RunScenario(
given => a_dotnet_project("new_help"),
when => the_developer_runs_cli_command("new --help"),
then => the_cli_should_output(new[]
{
"Creates a new project using Steeltoe Initializr",
$"Usage: {Program.Name} new [options]",
"Options:",
"-n|--name <name> Sets the project name; default is the name of the current directory",
"--project-dir <path> Sets the location to place the generated project files; default is the current directory",
"-f|--framework <framework> Sets the project framework",
"-t|--template <template> Sets the Initializr template",
"-d|--dependency <dep>|<dep>:<depname> Adds the named Initializr dependency; may be specified multiple times",
"-F|--force Forces project files to be generated even if it would change existing files",
"-?|-h|--help Show help information",
"Overview:",
"Create a new project using Steeltoe Initializr. If the output directory exists and is not empty, --force must be specified.",
"Examples:",
"Create a new project in the current directory:",
"$ st new",
"Re-create a project in the current directory:",
"$ st new --force",
"Create a new project in a new directory:",
"$ st new --project-dir src/MyProj",
"Create a new project with dependencies on SQL Server and Redis:",
"$ st new --dependency sqlserver --dep redis",
"Create a new project with dependencies on a SQL Server service named MyDB:",
"$ st new --dependency sqlserver:MyDB",
"Create a new project with a custom name and using the Steeltoe-React template:",
"$ st new --name MyCompany.MySample --template Steeltoe-React",
"Create a new project for netcoreapp2.2:",
"$ st new --framework netcoreapp2.2",
"See Also:",
"show",
"list-templates",
"list-deps",
})
);
}
[Scenario]
public void NewTooManyArgs()
{
Runner.RunScenario(
given => a_dotnet_project("new_too_many_args"),
when => the_developer_runs_cli_command("new arg1"),
then => the_cli_should_fail_parse("Unrecognized command or argument 'arg1'")
);
}
}
}

Просмотреть файл

@ -20,15 +20,16 @@ namespace Steeltoe.Cli.Test
{
public class ProgramFeature : FeatureSpecs
{
// [Scenario]
// public void ProgramNoArgs()
// {
// Runner.RunScenario(
// given => a_dotnet_project("program_no_args"),
// when => the_developer_runs_cli_command(""),
// and => the_cli_should_error(1, "Usage: steeltoe [options] [command]")
// );
// }
[Scenario]
public void ProgramNoArgs()
{
Runner.RunScenario(
given => a_dotnet_project("program_no_args"),
when => the_developer_runs_cli_command(""),
and => the_cli_should_error(ErrorCode.Argument),
and => the_cli_output_should_include("Usage: st [options] [command]")
);
}
[Scenario]
public void ProgramHelp()
@ -36,7 +37,8 @@ namespace Steeltoe.Cli.Test
Runner.RunScenario(
given => a_dotnet_project("program_help"),
when => the_developer_runs_cli_command("--help"),
then => the_cli_should_output(new[]
then => the_cli_command_should_succeed(),
and => the_cli_should_output(new[]
{
"*",
"Steeltoe Developer Tools",
@ -48,17 +50,21 @@ namespace Steeltoe.Cli.Test
"-v|--verbose Enable verbose output",
"-?|-h|--help Show help information",
"Commands:",
"add-app Add an app",
"add-service Add a service",
"args Set or get the arguments for an app or service",
"deploy Deploy apps and services to the target",
"doctor Check for potential problems",
"init Initialize Steeltoe Developer Tools",
"list List apps and services",
"remove Remove an app or service",
"status Show app and service statuses",
"target Set or get the deployment target",
"undeploy Undeploy apps and services from the target",
"add-dep Adds a dependency",
"def-dep Adds a custom dependency definition",
"doctor Checks for potential problems",
"list-cfgs Displays a list of available configurations",
"list-deps Displays a list of available dependencies",
"list-templates Displays a list of available templates",
"new Creates a new project using Steeltoe Initializr",
"new-cfg Creates configuration files for a target",
"rem-dep Removes a dependency that was added using the add-dep command",
"run Runs the project in the local Docker environment",
"show Displays the project details",
"show-cfg Displays configuration details",
"show-topic Displays documentation on a topic",
"stop Stops the project running in the local Docker environment",
"undef-dep Removes a custom dependency definition",
$"Run 'st [command] --help' for more information about a command.",
})
);

Просмотреть файл

@ -0,0 +1,69 @@
// Copyright 2020 the original author or authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
using LightBDD.Framework.Scenarios.Extended;
using LightBDD.XUnit2;
namespace Steeltoe.Cli.Test
{
public class RemoveDependencyFeature : FeatureSpecs
{
[Scenario]
public void RemoveDependencyHelp()
{
Runner.RunScenario(
given => a_dotnet_project("remove_dependency_help"),
when => the_developer_runs_cli_command("rem-dep --help"),
then => the_cli_command_should_succeed(),
and => the_cli_should_output(new[]
{
"Removes a dependency that was added using the add-dep command",
$"Usage: {Program.Name} rem-dep [arguments] [options]",
"Arguments:",
"depname The name of the dependency to be removed",
"Options:",
"-?|-h|--help Show help information",
"Overview:",
"Remove the named dependency from the project.",
"Examples:",
"Remove the dependency named MyRedis:",
"$ st rem-dep MyRedis",
"See Also:",
"add-dep",
"list-deps",
})
);
}
[Scenario]
public void RemoveDependencyNotEnoughArgs()
{
Runner.RunScenario(
given => a_dotnet_project("remove_dependency_not_enough_args"),
when => the_developer_runs_cli_command("rem-dep"),
then => the_cli_should_error(ErrorCode.Argument, "Dependency name not specified")
);
}
[Scenario]
public void RemoveDependencyTooManyArgs()
{
Runner.RunScenario(
given => a_dotnet_project("remove_dependency_too_many_args"),
when => the_developer_runs_cli_command("rem-dep arg1 arg2"),
then => the_cli_should_fail_parse("Unrecognized command or argument 'arg2'")
);
}
}
}

Просмотреть файл

@ -1,104 +0,0 @@
// Copyright 2018 the original author or authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
using LightBDD.Framework.Scenarios.Extended;
using LightBDD.XUnit2;
namespace Steeltoe.Cli.Test
{
public class RemoveFeature : FeatureSpecs
{
[Scenario]
public void RemoveHelp()
{
Runner.RunScenario(
given => a_dotnet_project("remove_help"),
when => the_developer_runs_cli_command("remove --help"),
then => the_cli_should_output(new[]
{
"Remove an app or service",
$"Usage: {Program.Name} remove [arguments] [options]",
"Arguments:",
"name App or service name",
"Options:",
"-?|-h|--help Show help information",
})
);
}
[Scenario]
public void RemoveNotEnoughArgs()
{
Runner.RunScenario(
given => a_dotnet_project("remove_not_enough_args"),
when => the_developer_runs_cli_command("remove"),
then => the_cli_should_error(ErrorCode.Argument, "App or service name not specified")
);
}
[Scenario]
public void RemoveTooManyArgs()
{
Runner.RunScenario(
given => a_dotnet_project("remove_too_many_args"),
when => the_developer_runs_cli_command("remove arg1 arg2"),
then => the_cli_should_fail_parse("Unrecognized command or argument 'arg2'")
);
}
[Scenario]
public void RemoveUninitialized()
{
Runner.RunScenario(
given => a_dotnet_project("remove_uninitialized"),
when => the_developer_runs_cli_command("remove my-service"),
then => the_cli_should_error(ErrorCode.Tooling, "Steeltoe Developer Tools has not been initialized")
);
}
[Scenario]
public void RemoveApp()
{
Runner.RunScenario(
given => a_steeltoe_project("remove_app"),
when => the_developer_runs_cli_command("add-app remove_app"),
and => the_developer_runs_cli_command("remove remove_app"),
then => the_cli_should_output("Removed app 'remove_app'"),
and => the_configuration_should_not_contain_app("remove_app")
);
}
[Scenario]
public void RemoveService()
{
Runner.RunScenario(
given => a_steeltoe_project("remove_service"),
when => the_developer_runs_cli_command("add-service dummy-svc my-service"),
and => the_developer_runs_cli_command("remove my-service"),
then => the_cli_should_output("Removed dummy-svc service 'my-service'"),
and => the_configuration_should_not_contain_service("my-service")
);
}
[Scenario]
public void RemoveUnknownItem()
{
Runner.RunScenario(
given => a_steeltoe_project("remove_unknown_item"),
when => the_developer_runs_cli_command("remove no-such-item"),
then => the_cli_should_error(ErrorCode.Tooling, "App or service 'no-such-item' does not exist")
);
}
}
}

Просмотреть файл

@ -0,0 +1,59 @@
// Copyright 2020 the original author or authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
using LightBDD.Framework.Scenarios.Extended;
using LightBDD.XUnit2;
namespace Steeltoe.Cli.Test
{
public class RunFeature : FeatureSpecs
{
[Scenario]
public void RunHelp()
{
Runner.RunScenario(
given => a_dotnet_project("run_help"),
when => the_developer_runs_cli_command("run --help"),
then => the_cli_should_output(new[]
{
"Runs the project in the local Docker environment",
$"Usage: {Program.Name} run [options]",
"Options:",
"-n|--name <name> Sets the name of the configuration to be run (must be a Docker configuration)",
"-?|-h|--help Show help information",
"Overview:",
"Starts the project application and its dependencies in the local Docker environment.",
"Examples:",
"Run the default configuration:",
"$ st run",
"Run a specific configuration:",
"$ st run -n MyDockerConfig",
"See Also:",
"stop",
"list-cfgs",
})
);
}
[Scenario]
public void RunTooManyArgs()
{
Runner.RunScenario(
given => a_dotnet_project("run_too_many_args"),
when => the_developer_runs_cli_command("run arg1"),
then => the_cli_should_fail_parse("Unrecognized command or argument 'arg1'")
);
}
}
}

Просмотреть файл

@ -0,0 +1,56 @@
// Copyright 2020 the original author or authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
using LightBDD.Framework.Scenarios.Extended;
using LightBDD.XUnit2;
namespace Steeltoe.Cli.Test
{
public class ShowConfigurationFeature : FeatureSpecs
{
[Scenario]
public void ShowConfigurationHelp()
{
Runner.RunScenario(
given => a_dotnet_project("show_configuration_help"),
when => the_developer_runs_cli_command("show-cfg --help"),
then => the_cli_should_output(new[]
{
"Displays configuration details",
$"Usage: {Program.Name} show-cfg [options]",
"Options:",
"-n|--name <name> Sets the name of the configuration to be displayed",
"-?|-h|--help Show help information",
"Overview:",
"*** under construction ***",
"Examples:",
"Display the details of the default configuration:",
"$ st show-cfg",
"Display the details of a specific configuration:",
"$ st show-cfg --name MyCustomDockerConfig",
})
);
}
[Scenario]
public void ShowConfigurationTooManyArgs()
{
Runner.RunScenario(
given => a_dotnet_project("show_configuration_too_many_args"),
when => the_developer_runs_cli_command("show-cfg arg1"),
then => the_cli_should_fail_parse("Unrecognized command or argument 'arg1'")
);
}
}
}

Просмотреть файл

@ -0,0 +1,56 @@
// Copyright 2020 the original author or authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
using LightBDD.Framework.Scenarios.Extended;
using LightBDD.XUnit2;
namespace Steeltoe.Cli.Test
{
public class ShowFeature : FeatureSpecs
{
[Scenario]
public void ShowHelp()
{
Runner.RunScenario(
given => a_dotnet_project("show_help"),
when => the_developer_runs_cli_command("show --help"),
then => the_cli_should_output(new[]
{
"Displays the project details",
$"Usage: {Program.Name} show [options]",
"Options:",
"--project-dir <path> Sets the location of the project; default is the current directory",
"-?|-h|--help Show help information",
"Overview:",
"*** under construction ***",
"Examples:",
"Show the details of the project in the current directory:",
"$ st show",
"Show the details of the project in a specific directory:",
"$ st show --project src/MyProj",
})
);
}
[Scenario]
public void ShowTooManyArgs()
{
Runner.RunScenario(
given => a_dotnet_project("show_too_many_args"),
when => the_developer_runs_cli_command("show arg1"),
then => the_cli_should_fail_parse("Unrecognized command or argument 'arg1'")
);
}
}
}

Просмотреть файл

@ -0,0 +1,56 @@
// Copyright 2020 the original author or authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
using LightBDD.Framework.Scenarios.Extended;
using LightBDD.XUnit2;
namespace Steeltoe.Cli.Test
{
public class ShowTopicFeature : FeatureSpecs
{
[Scenario]
public void ShowTopicHelp()
{
Runner.RunScenario(
given => a_dotnet_project("show_topic_help"),
when => the_developer_runs_cli_command("show-topic --help"),
then => the_cli_command_should_succeed(),
and => the_cli_should_output(new[]
{
"Displays documentation on a topic",
$"Usage: {Program.Name} show-topic [arguments] [options]",
"Arguments:",
"topic Topic",
"Options:",
"-?|-h|--help Show help information",
"Overview:",
"*** under construction ***",
"Examples:",
"Display documentation on autodetection:",
"$ st show-topic autodetection",
})
);
}
[Scenario]
public void ShowTopicTooManyArgs()
{
Runner.RunScenario(
given => a_dotnet_project("show_topic_too_many_args"),
when => the_developer_runs_cli_command("show-topic arg1 arg2"),
then => the_cli_should_fail_parse("Unrecognized command or argument 'arg2'")
);
}
}
}

Просмотреть файл

@ -1,96 +0,0 @@
// Copyright 2018 the original author or authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
using LightBDD.Framework.Scenarios.Extended;
using LightBDD.XUnit2;
namespace Steeltoe.Cli.Test
{
public class StatusFeature : FeatureSpecs
{
[Scenario]
public void StatusHelp()
{
Runner.RunScenario(
given => a_dotnet_project("status_help"),
when => the_developer_runs_cli_command("status --help"),
then => the_cli_should_output(new[]
{
"Show app and service statuses",
$"Usage: {Program.Name} status [options]",
"Options:",
"-?|-h|--help Show help information",
})
);
}
[Scenario]
public void StatusTooManyArgs()
{
Runner.RunScenario(
given => a_dotnet_project("status_too_many_args"),
when => the_developer_runs_cli_command("status arg1"),
then => the_cli_should_fail_parse("Unrecognized command or argument 'arg1'")
);
}
[Scenario]
public void StatusUninitialized()
{
Runner.RunScenario(
given => a_dotnet_project("status_uninitialized"),
when => the_developer_runs_cli_command("status"),
then => the_cli_should_error(ErrorCode.Tooling, "Steeltoe Developer Tools has not been initialized")
);
}
[Scenario]
public void StatusServices()
{
Runner.RunScenario(
given => a_steeltoe_project("status_services"),
when => the_developer_runs_cli_command("add-service dummy-svc my-service-a"),
and => the_developer_runs_cli_command("add-service dummy-svc my-service-b"),
and => the_developer_runs_cli_command("status"),
then => the_cli_should_output(new[]
{
"my-service-a offline",
"my-service-b offline",
})
);
}
[Scenario]
public void StatusNoServices()
{
Runner.RunScenario(
given => a_steeltoe_project("status_no_services"),
when => the_developer_runs_cli_command("status"),
then => the_cli_should_output_nothing()
);
}
[Scenario]
public void StatusNoTarget()
{
Runner.RunScenario(
given => a_dotnet_project("status_no_target"),
when => the_developer_runs_cli_command("init"),
and => the_developer_runs_cli_command("add dummy-svc a-server"),
and => the_developer_runs_cli_command("status"),
then => the_cli_should_error(ErrorCode.Tooling, "Target not set")
);
}
}
}

Просмотреть файл

@ -0,0 +1,55 @@
// Copyright 2020 the original author or authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
using LightBDD.Framework.Scenarios.Extended;
using LightBDD.XUnit2;
namespace Steeltoe.Cli.Test
{
public class StopFeature : FeatureSpecs
{
[Scenario]
public void StopHelp()
{
Runner.RunScenario(
given => a_dotnet_project("stop_help"),
when => the_developer_runs_cli_command("stop --help"),
then => the_cli_should_output(new[]
{
"Stops the project running in the local Docker environment",
$"Usage: {Program.Name} stop [options]",
"Options:",
"-?|-h|--help Show help information",
"Overview:",
"Stops the project application and its dependencies in the local Docker environment.",
"Examples:",
"Stop the running project:",
"$ st stop",
"See Also:",
"run",
})
);
}
[Scenario]
public void StopTooManyArgs()
{
Runner.RunScenario(
given => a_dotnet_project("stop_too_many_args"),
when => the_developer_runs_cli_command("stop arg1"),
then => the_cli_should_fail_parse("Unrecognized command or argument 'arg1'")
);
}
}
}

Просмотреть файл

@ -1,98 +0,0 @@
// Copyright 2018 the original author or authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
using LightBDD.Framework.Scenarios.Extended;
using LightBDD.XUnit2;
namespace Steeltoe.Cli.Test
{
public class TargetFeature : FeatureSpecs
{
[Scenario]
public void TargetHelp()
{
Runner.RunScenario(
given => a_dotnet_project("target_help"),
when => the_developer_runs_cli_command("target --help"),
then => the_cli_should_output(new[]
{
"Set or get the deployment target",
$"Usage: {Program.Name} target [arguments] [options]",
"Arguments:",
"target Deployment target name",
"Options:",
"-F|--force Set the deployment target even if checks fail",
"-?|-h|--help Show help information",
"If run with no args, show the current deployment target.",
})
);
}
[Scenario]
public void TargetTooManyArgs()
{
Runner.RunScenario(
given => a_dotnet_project("target_too_many_args"),
when => the_developer_runs_cli_command("target arg1 arg2"),
then => the_cli_should_fail_parse("Unrecognized command or argument 'arg2'")
);
}
[Scenario]
public void TargetUninitialized()
{
Runner.RunScenario(
given => a_dotnet_project("target_uninitialized"),
when => the_developer_runs_cli_command("target"),
then => the_cli_should_error(ErrorCode.Tooling, "Steeltoe Developer Tools has not been initialized")
);
}
[Scenario]
public void TargetSet()
{
Runner.RunScenario(
given => a_dotnet_project("target_set"),
when => the_developer_runs_cli_command("init"),
and => the_developer_runs_cli_command("target dummy-target"),
then => the_cli_should_output(new[]
{
"dummy tool version ... 0.0.0",
"Target set to 'dummy-target'",
}),
and => the_configuration_should_target("dummy-target")
);
}
[Scenario]
public void TargetSetUnknown()
{
Runner.RunScenario(
given => a_steeltoe_project("target_set_unknown"),
when => the_developer_runs_cli_command("target no-such-target"),
then => the_cli_should_error(ErrorCode.Tooling, "Unknown target 'no-such-target'")
);
}
[Scenario]
public void ShowTargetEnvironment()
{
Runner.RunScenario(
given => a_steeltoe_project("show_target_environment"),
when => the_developer_runs_cli_command("target"),
then => the_cli_should_output("dummy-target")
);
}
}
}

Просмотреть файл

@ -0,0 +1,70 @@
// Copyright 2020 the original author or authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
using LightBDD.Framework.Scenarios.Extended;
using LightBDD.XUnit2;
namespace Steeltoe.Cli.Test
{
public class UndefineDependencyFeature : FeatureSpecs
{
[Scenario]
public void UndefineDependencyHelp()
{
Runner.RunScenario(
given => a_dotnet_project("undefine_dependency_help"),
when => the_developer_runs_cli_command("undef-dep --help"),
then => the_cli_command_should_succeed(),
and => the_cli_should_output(new[]
{
"Removes a custom dependency definition",
$"Usage: {Program.Name} undef-dep [arguments] [options]",
"Arguments:",
"dep Dependency",
"Options:",
"--scope <scope> Sets the dependency definition scope (one of: project, global); default is project",
"-?|-h|--help Show help information",
"Overview:",
"*** under construction ***",
"Examples:",
"Remove a dependency definition:",
"$ st undef-dep MyService",
"See Also:",
"def-dep",
"list-deps",
})
);
}
[Scenario]
public void DefineDependencyNotEnoughArgs()
{
Runner.RunScenario(
given => a_dotnet_project("undefine_dependency_not_enough_args"),
when => the_developer_runs_cli_command("undef-dep"),
then => the_cli_should_error(ErrorCode.Argument, "Dependency not specified")
);
}
[Scenario]
public void RemoveDependencyTooManyArgs()
{
Runner.RunScenario(
given => a_dotnet_project("undefine_dependency_too_many_args"),
when => the_developer_runs_cli_command("undef-dep arg1 arg2"),
then => the_cli_should_fail_parse("Unrecognized command or argument 'arg2'")
);
}
}
}

Просмотреть файл

@ -1,102 +0,0 @@
// Copyright 2018 the original author or authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
using LightBDD.Framework.Scenarios.Extended;
using LightBDD.XUnit2;
namespace Steeltoe.Cli.Test
{
public class UndeployFeature : FeatureSpecs
{
[Scenario]
public void UndeployHelp()
{
Runner.RunScenario(
given => a_steeltoe_project("undeploy_help"),
when => the_developer_runs_cli_command("undeploy --help"),
then => the_cli_should_output(new[]
{
"Undeploy apps and services from the target",
$"Usage: {Program.Name} undeploy [options]",
"Options:",
"-?|-h|--help Show help information",
})
);
}
[Scenario]
public void UndeployTooManyArgs()
{
Runner.RunScenario(
given => a_steeltoe_project("undeploy_too_many_args"),
when => the_developer_runs_cli_command("undeploy arg1"),
then => the_cli_should_fail_parse("Unrecognized command or argument 'arg1'")
);
}
[Scenario]
public void UndeployUninitialized()
{
Runner.RunScenario(
given => a_dotnet_project("undeploy_uninitialized"),
when => the_developer_runs_cli_command("undeploy"),
then => the_cli_should_error(ErrorCode.Tooling, "Steeltoe Developer Tools has not been initialized")
);
}
[Scenario]
public void Undeploy()
{
Runner.RunScenario(
given => a_steeltoe_project("undeploy_services"),
when => the_developer_runs_cli_command("add-app undeploy_services"),
and => the_developer_runs_cli_command("add-service dummy-svc my-service-a"),
and => the_developer_runs_cli_command("add-service dummy-svc my-service-b"),
and => the_developer_runs_cli_command("deploy"),
and => the_developer_runs_cli_command("status"),
and => the_developer_runs_cli_command("undeploy"),
then => the_cli_should_output(new[]
{
"Undeploying app 'undeploy_services'",
"Undeploying service 'my-service-a'",
"Undeploying service 'my-service-b'",
"Waiting for 'my-service-a' to transition to offline (1)",
"Waiting for 'my-service-b' to transition to offline (1)",
})
);
}
[Scenario]
public void DeployNothing()
{
Runner.RunScenario(
given => a_steeltoe_project("undeploy_nothing"),
when => the_developer_runs_cli_command("deploy"),
then => the_cli_should_output_nothing()
);
}
[Scenario]
public void UndeployNoTarget()
{
Runner.RunScenario(
given => a_dotnet_project("undeploy_no_target"),
when => the_developer_runs_cli_command("init"),
and => the_developer_runs_cli_command("add dummy-svc a-server"),
and => the_developer_runs_cli_command("undeploy"),
then => the_cli_should_error(ErrorCode.Tooling, "Target not set")
);
}
}
}

Просмотреть файл

@ -26,7 +26,6 @@ namespace Steeltoe.Tooling.Test
var file = Path.Combine(Context.ProjectDirectory, "config-file");
File.WriteAllText(file, SampleConfig);
var cfgFile = new ConfigurationFile(file);
cfgFile.Configuration.Target.ShouldBe("dummy-target");
cfgFile.Configuration.GetServices().ShouldContain("my-service");
cfgFile.Configuration.GetServiceInfo("my-service").ServiceType.ShouldBe("dummy-svc");
}
@ -37,7 +36,6 @@ namespace Steeltoe.Tooling.Test
var defaultFile = Path.Combine(Context.ProjectDirectory, ConfigurationFile.DefaultFileName);
File.WriteAllText(defaultFile, SampleConfig);
var cfgFile = new ConfigurationFile(Context.ProjectDirectory);
cfgFile.Configuration.Target.ShouldBe("dummy-target");
cfgFile.Configuration.GetServices().ShouldContain("my-service");
cfgFile.Configuration.GetServiceInfo("my-service").ServiceType.ShouldBe("dummy-svc");
}
@ -47,7 +45,6 @@ namespace Steeltoe.Tooling.Test
{
var file = Path.Combine(Context.ProjectDirectory, "config-file");
var cfgFile = new ConfigurationFile(file);
cfgFile.Configuration.Target = "dummy-target";
cfgFile.Configuration.AddApp("my-app", "dummy-framework", "dummy-runtime");
cfgFile.Configuration.AddService("my-service", "dummy-svc");
cfgFile.Store();
@ -58,7 +55,6 @@ namespace Steeltoe.Tooling.Test
public void TestStoreToDirectory()
{
var cfgFile = new ConfigurationFile(Context.ProjectDirectory);
cfgFile.Configuration.Target = "dummy-target";
cfgFile.Configuration.AddApp("my-app", "dummy-framework", "dummy-runtime");
cfgFile.Configuration.AddService("my-service", "dummy-svc");
cfgFile.Store();
@ -66,8 +62,7 @@ namespace Steeltoe.Tooling.Test
File.ReadAllText(defaultFile).ShouldBe(SampleConfig);
}
private const string SampleConfig = @"target: dummy-target
apps:
private const string SampleConfig = @"apps:
my-app:
targetFramework: dummy-framework
targetRuntime: dummy-runtime

Просмотреть файл

@ -66,7 +66,6 @@ namespace Steeltoe.Tooling.Test
() => _cfg.RemoveApp("no-such-app")
);
e.Name.ShouldBe("no-such-app");
e.Description.ShouldBe("app");
}
[Fact]
@ -96,7 +95,6 @@ namespace Steeltoe.Tooling.Test
() => _cfg.GetAppInfo("no-such-app")
);
e.Name.ShouldBe("no-such-app");
e.Description.ShouldBe("app");
}
[Fact]
@ -124,7 +122,6 @@ namespace Steeltoe.Tooling.Test
() => _cfg.SetAppArgs("no-such-app", "arg1 arg2")
);
e.Name.ShouldBe("no-such-app");
e.Description.ShouldBe("app");
}
[Fact]
@ -134,7 +131,6 @@ namespace Steeltoe.Tooling.Test
() => _cfg.SetAppArgs("no-such-app", "dummy-target", "arg1 arg2")
);
e.Name.ShouldBe("no-such-app");
e.Description.ShouldBe("app");
}
[Fact]
@ -145,7 +141,6 @@ namespace Steeltoe.Tooling.Test
() => _cfg.SetAppArgs("my-app", "no-such-target", "arg1 arg2")
);
e.Name.ShouldBe("no-such-target");
e.Description.ShouldBe("target");
}
[Fact]
@ -185,7 +180,6 @@ namespace Steeltoe.Tooling.Test
() => _cfg.GetAppArgs("no-such-app")
);
e.Name.ShouldBe("no-such-app");
e.Description.ShouldBe("app");
}
[Fact]
@ -195,7 +189,6 @@ namespace Steeltoe.Tooling.Test
() => _cfg.GetAppArgs("no-such-app", "dummy-target")
);
e.Name.ShouldBe("no-such-app");
e.Description.ShouldBe("app");
}
[Fact]
@ -206,7 +199,6 @@ namespace Steeltoe.Tooling.Test
() => _cfg.GetAppArgs("my-app", "no-such-target")
);
e.Name.ShouldBe("no-such-target");
e.Description.ShouldBe("target");
}
[Fact]
@ -216,7 +208,6 @@ namespace Steeltoe.Tooling.Test
() => _cfg.AddService("my-service", "no-such-service-type")
);
e.Name.ShouldBe("no-such-service-type");
e.Description.ShouldBe("service type");
}
[Fact]
@ -256,7 +247,6 @@ namespace Steeltoe.Tooling.Test
() => _cfg.RemoveService("no-such-service")
);
e.Name.ShouldBe("no-such-service");
e.Description.ShouldBe("service");
}
[Fact]
@ -287,7 +277,6 @@ namespace Steeltoe.Tooling.Test
() => _cfg.GetServiceInfo("no-such-service")
);
e.Name.ShouldBe("no-such-service");
e.Description.ShouldBe("service");
}
[Fact]
@ -315,7 +304,6 @@ namespace Steeltoe.Tooling.Test
() => _cfg.SetServiceArgs("no-such-service", "arg1 arg2")
);
e.Name.ShouldBe("no-such-service");
e.Description.ShouldBe("service");
}
[Fact]
@ -325,7 +313,6 @@ namespace Steeltoe.Tooling.Test
() => _cfg.SetServiceArgs("no-such-service", "dummy-target", "arg1 arg2")
);
e.Name.ShouldBe("no-such-service");
e.Description.ShouldBe("service");
}
[Fact]
@ -336,7 +323,6 @@ namespace Steeltoe.Tooling.Test
() => _cfg.SetServiceArgs("my-service", "no-such-target", "arg1 arg2")
);
e.Name.ShouldBe("no-such-target");
e.Description.ShouldBe("target");
}
[Fact]
@ -376,7 +362,6 @@ namespace Steeltoe.Tooling.Test
() => _cfg.GetServiceArgs("no-such-service")
);
e.Name.ShouldBe("no-such-service");
e.Description.ShouldBe("service");
}
[Fact]
@ -386,7 +371,6 @@ namespace Steeltoe.Tooling.Test
() => _cfg.GetServiceArgs("no-such-service", "dummy-target")
);
e.Name.ShouldBe("no-such-service");
e.Description.ShouldBe("service");
}
[Fact]
@ -397,7 +381,6 @@ namespace Steeltoe.Tooling.Test
() => _cfg.GetServiceArgs("my-service", "no-such-target")
);
e.Name.ShouldBe("no-such-target");
e.Description.ShouldBe("target");
}
private class MyListener : IConfigurationListener

Просмотреть файл

@ -23,11 +23,9 @@ namespace Steeltoe.Tooling.Test
public void TestContext()
{
var cfg = new Configuration();
cfg.Target = "dummy-target";
var ctx = new Context(null, cfg, Console, Shell);
ctx.Configuration.ShouldBe(cfg);
ctx.Shell.ShouldBe(Shell);
ctx.Target.Name.ShouldBe("dummy-target");
}
}
}

Просмотреть файл

@ -1,228 +0,0 @@
// Copyright 2018 the original author or authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
using System.IO;
using Shouldly;
using Steeltoe.Tooling.Drivers.CloudFoundry;
using Xunit;
namespace Steeltoe.Tooling.Test.Drivers.CloudFoundry
{
public class CloudFoundryDriverTest : ToolingTest
{
private readonly CloudFoundryDriver _driver;
public CloudFoundryDriverTest()
{
Context.Configuration.Target = "cloud-foundry";
_driver = Context.Target.GetDriver(Context) as CloudFoundryDriver;
}
[Fact]
public void TestDeployAppWindows()
{
Context.Configuration.AddService("my-service", "dummy-svc");
Context.Configuration.AddApp("my-app", "dummy-framework", "win");
_driver.DeployApp("my-app");
Shell.Commands.Count.ShouldBe(2);
Shell.Commands[0].ShouldBe("dotnet publish -f dummy-framework -r win");
Shell.Commands[1].ShouldBe("cf push -f manifest-steeltoe.yaml -p bin/Debug/dummy-framework/win/publish");
var manifestFile = Path.Combine(Context.ProjectDirectory, "manifest-steeltoe.yaml");
File.Exists(manifestFile).ShouldBeTrue();
}
[Fact]
public void TestDeployAppUbuntu()
{
Context.Configuration.AddService("my-service", "dummy-svc");
Context.Configuration.AddApp("my-app", "dummy-framework", "ubuntu");
_driver.DeployApp("my-app");
Shell.Commands.Count.ShouldBe(2);
Shell.Commands[0].ShouldBe("dotnet publish -f dummy-framework -r ubuntu");
Shell.Commands[1].ShouldBe("cf push -f manifest-steeltoe.yaml -p bin/Debug/dummy-framework/ubuntu/publish");
var manifestFile = Path.Combine(Context.ProjectDirectory, "manifest-steeltoe.yaml");
File.Exists(manifestFile).ShouldBeTrue();
}
[Fact]
public void TestUndeployApp()
{
Context.Configuration.AddApp("my-app", "dummy-framework", "dummy-runtime");
_driver.UndeployApp("my-app");
Shell.LastCommand.ShouldBe("cf delete my-app -f");
}
[Fact]
public void TestDeployService()
{
Context.Configuration.AddService("my-service", "dummy-svc");
_driver.DeployService("my-service");
Shell.LastCommand.ShouldBe("cf create-service dummy-server dummy-plan my-service");
}
[Fact]
public void TestDeployServiceWithArgs()
{
Context.Configuration.AddService("my-service", "dummy-svc");
Context.Configuration.SetServiceArgs("my-service", "cloud-foundry", "arg1 \"arg2\"");
_driver.DeployService("my-service");
Shell.LastCommand.ShouldBe("cf create-service dummy-server dummy-plan my-service arg1 \"\"\"arg2\"\"\"");
}
[Fact]
public void TestDeployConfigServer()
{
Context.Configuration.AddService("my-service", "config-server");
_driver.DeployService("my-service");
Shell.LastCommand.ShouldBe("cf create-service p-config-server standard my-service");
}
[Fact]
public void TestDeployEurekaServer()
{
Context.Configuration.AddService("my-service", "eureka-server");
_driver.DeployService("my-service");
Shell.LastCommand.ShouldBe("cf create-service p-service-registry standard my-service");
}
[Fact]
public void TestDeployHystrixDashboard()
{
Context.Configuration.AddService("my-service", "hystrix-dashboard");
_driver.DeployService("my-service");
Shell.LastCommand.ShouldBe("cf create-service p-circuit-breaker-dashboard standard my-service");
}
[Fact]
public void TestDeployMySql()
{
Context.Configuration.AddService("my-service", "mysql");
_driver.DeployService("my-service");
Shell.LastCommand.ShouldBe("cf create-service p.mysql db-small my-service");
}
[Fact]
public void TestDeployPostgreSql()
{
Context.Configuration.AddService("my-service", "postgresql");
_driver.DeployService("my-service");
Shell.LastCommand.ShouldBe("cf create-service postgresql-10-odb standalone my-service");
}
[Fact]
public void TestDeployRabbitMq()
{
Context.Configuration.AddService("my-service", "rabbitmq");
_driver.DeployService("my-service");
Shell.LastCommand.ShouldBe("cf create-service p-rabbitmq standard my-service");
}
[Fact]
public void TestDeployRedis()
{
Context.Configuration.AddService("my-service", "redis");
_driver.DeployService("my-service");
Shell.LastCommand.ShouldBe("cf create-service p-redis shared-vm my-service");
}
[Fact]
public void TestDeployUnavailableService()
{
Context.Configuration.AddService("my-service", "zipkin");
var e = Assert.Throws<ToolingException>(
() => _driver.DeployService("my-service")
);
e.Message.ShouldBe("No Cloud Foundry service available for 'my-service' [zipkin]");
}
[Fact]
public void TestUndeployService()
{
Context.Configuration.AddService("my-service", "dummy-svc");
_driver.UndeployService("my-service");
Shell.LastCommand.ShouldBe("cf delete-service my-service -f");
}
[Fact]
public void TestCheckApp()
{
Context.Configuration.AddApp("my-app", "dummy-framework", "dummy-runtime");
_driver.GetAppStatus("my-app");
Shell.LastCommand.ShouldBe("cf app my-app");
}
[Fact]
public void TestCheckService()
{
Context.Configuration.AddService("my-service", "dummy-svc");
_driver.GetServiceStatus("my-service");
Shell.LastCommand.ShouldBe("cf service my-service");
}
[Fact]
public void TestAppOnline()
{
Context.Configuration.AddApp("my-app", "dummy-framework", "dummy-runtime");
Shell.AddResponse("#0 running 2018-11-02T16:32:37Z 16.9% 129.2M of 512M 124.8M of 1G");
var status = _driver.GetAppStatus("my-app");
status.ShouldBe(Lifecycle.Status.Online);
}
[Fact]
public void TestAppOffline()
{
Context.Configuration.AddApp("my-app", "dummy-framework", "dummy-runtime");
Shell.AddResponse("App my-app not found.", -1);
_driver.GetAppStatus("my-app").ShouldBe(Lifecycle.Status.Offline);
Shell.AddResponse("App 'my-app' not found.", -1);
_driver.GetAppStatus("my-app").ShouldBe(Lifecycle.Status.Offline);
}
[Fact]
public void TestServiceStarting()
{
Context.Configuration.AddService("my-service", "dummy-svc");
Shell.AddResponse("status: create in progress");
var status = _driver.GetServiceStatus("my-service");
status.ShouldBe(Lifecycle.Status.Starting);
}
[Fact]
public void TestServiceOnline()
{
Context.Configuration.AddService("my-service", "dummy-svc");
Shell.AddResponse("status: create succeeded");
var status = _driver.GetServiceStatus("my-service");
status.ShouldBe(Lifecycle.Status.Online);
}
[Fact]
public void TestServiceOffline()
{
Context.Configuration.AddService("my-service", "dummy-svc");
Shell.AddResponse("Service instance my-service not found", 1);
var status = _driver.GetServiceStatus("my-service");
status.ShouldBe(Lifecycle.Status.Offline);
}
[Fact]
public void TestServiceStopping()
{
Context.Configuration.AddService("my-service", "dummy-svc");
Shell.AddResponse("status: delete in progress");
var status = _driver.GetServiceStatus("my-service");
status.ShouldBe(Lifecycle.Status.Stopping);
}
}
}

Просмотреть файл

@ -1,78 +0,0 @@
// Copyright 2018 the original author or authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
using Shouldly;
using Steeltoe.Tooling.Drivers.CloudFoundry;
using Xunit;
namespace Steeltoe.Tooling.Test.Drivers.CloudFoundry
{
public class CloudFoundryTargetTest : ToolingTest
{
private readonly CloudFoundryTarget _target;
public CloudFoundryTargetTest()
{
_target = Registry.GetTarget("cloud-foundry") as CloudFoundryTarget;
}
[Fact]
public void TestGetName()
{
_target.Name.ShouldBe("cloud-foundry");
}
[Fact]
public void TestGetDescription()
{
_target.Description.ShouldBe("Cloud Foundry");
}
[Fact]
public void TestGetDriver()
{
_target.GetDriver(Context).ShouldBeOfType<CloudFoundryDriver>();
}
[Fact]
public void TestIsHealthy()
{
Shell.AddResponse("cf version SOME VERSION");
var healthy = _target.IsHealthy(Context);
healthy.ShouldBeTrue();
var expected = new[]
{
"cf --version",
"cf target",
};
Shell.Commands.Count.ShouldBe(expected.Length);
for (int i = 0; i < expected.Length; ++i)
{
Shell.Commands[i].ShouldBe(expected[i]);
}
Console.ToString().ShouldContain("Cloud Foundry ... cf version SOME VERSION");
Console.ToString().ShouldContain("logged into Cloud Foundry ... yes");
}
[Fact]
public void TestIsHealthyNotLoggedIn()
{
Shell.AddResponse("");
Shell.AddResponse("", 1);
var healthy = _target.IsHealthy(Context);
healthy.ShouldBeFalse();
Console.ToString().ShouldContain("logged into Cloud Foundry ... !!! no");
}
}
}

Просмотреть файл

@ -1,243 +0,0 @@
// Copyright 2018 the original author or authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
using System.IO;
using Shouldly;
using Steeltoe.Tooling.Drivers.Docker;
using Xunit;
namespace Steeltoe.Tooling.Test.Drivers.Docker
{
public class DockerDriverTest : ToolingTest
{
private readonly DockerDriver _driver;
public DockerDriverTest()
{
Context.Configuration.Target = "docker";
_driver = Context.Target.GetDriver(Context) as DockerDriver;
}
[Fact]
public void TestDeployApp()
{
Context.Configuration.AddApp("my-app", "dummy-framework", "dummy-runtime");
_driver.DeployApp("my-app");
Shell.Commands[0].ShouldBe("dotnet publish -f netcoreapp2.1");
Shell.Commands[1].ShouldBe(
$"docker run --name my-app --volume {Path.GetFullPath(Context.ProjectDirectory)}:/app --workdir /app --env ASPNETCORE_ENVIRONMENT=Docker --publish 8080:80 --rm --detach steeltoeoss/dotnet-runtime:2.1 dotnet bin/Debug/netcoreapp2.1/publish/{Path.GetFileName(Context.ProjectDirectory)}.dll");
Shell.Commands[2].ShouldBe("docker network connect my-app-network my-app");
Shell.Commands.Count.ShouldBe(3);
}
[Fact]
public void TestUndeployApp()
{
Context.Configuration.AddApp("my-app", "dummy-framework", "dummy-runtime");
_driver.UndeployApp("my-app");
Shell.Commands[0].ShouldBe("docker network disconnect my-app-network my-app");
Shell.Commands[1].ShouldBe("docker stop my-app");
Shell.Commands.Count.ShouldBe(2);
}
[Fact]
public void TestGetAppLifecycleStateCommand()
{
Context.Configuration.AddApp("my-app", "dummy-framework", "dummy-runtime");
_driver.GetAppStatus("my-app");
Shell.LastCommand.ShouldBe("docker ps --no-trunc --filter name=^/my-app$");
}
[Fact]
public void TestGetAppLifecycleStateOffline()
{
Context.Configuration.AddApp("my-app", "dummy-framework", "dummy-runtime");
var state = _driver.GetAppStatus("my-app");
state.ShouldBe(Lifecycle.Status.Offline);
}
[Fact]
public void TestGetAppLifecycleStateStarting()
{
Context.Configuration.AddApp("my-app", "dummy-framework", "dummy-runtime");
Shell.AddResponse(
@"CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
d2832b55b9e348d98b495f4432e05bc5e54dbe562d7294b48ba1ac5470b591b2 steeltoeoss/dotnet-sdk:2.1 ""dotnet /work/bin/Debug/netcoreapp2.1/MyWebApp.dll"" 56 seconds ago Up 55 seconds 0.0.0.0:8080->80/tcp my-app
");
var state = _driver.GetAppStatus("my-app");
state.ShouldBe(Lifecycle.Status.Starting);
}
[Fact]
public void TestDeployService()
{
Context.Configuration.AddService("my-service", "dummy-svc");
_driver.DeployService("my-service");
Shell.Commands[0].ShouldBe("docker info");
Shell.Commands[1].ShouldBe("docker run --name my-service --publish 0:0 --detach --rm dummy-server:0.1");
Shell.Commands[2].ShouldBe("docker network connect my-service-network my-service");
Shell.Commands.Count.ShouldBe(3);
}
[Fact]
public void TestDeployServiceWithArgs()
{
Context.Configuration.AddService("my-service", "dummy-svc");
Context.Configuration.SetServiceArgs("my-service", "docker", "arg1 \"arg2\"");
_driver.DeployService("my-service", "dummy-svc");
Shell.LastCommand.ShouldBe(
"docker run --name my-service --publish 0:0 --detach --rm arg1 \"\"\"arg2\"\"\" dummy-server:0.1");
}
[Fact]
public void TestDeployServiceForOs()
{
Context.Configuration.AddService("my-service", "dummy-svc");
Shell.AddResponse("OSType: dummyos");
_driver.DeployService("my-service");
Shell.Commands[1].ShouldBe("docker run --name my-service --publish 0:0 --detach --rm dummy-server:for_dummyos");
}
[Fact]
public void TestDeployConfigServer()
{
Context.Configuration.AddService("my-service", "config-server");
_driver.DeployService("my-service");
Shell.Commands[1].ShouldBe("docker run --name my-service --publish 8888:8888 --detach --rm steeltoeoss/config-server:2.0");
}
[Fact]
public void TestDeployEurekaServer()
{
Context.Configuration.AddService("my-service", "eureka-server");
_driver.DeployService("my-service");
Shell.Commands[1].ShouldBe("docker run --name my-service --publish 8761:8761 --detach --rm steeltoeoss/eureka-server:2.0");
}
[Fact]
public void TestDeployHystrixDashboard()
{
Context.Configuration.AddService("my-service", "hystrix-dashboard");
_driver.DeployService("my-service");
Shell.Commands[1].ShouldBe("docker run --name my-service --publish 7979:7979 --detach --rm steeltoeoss/hystrix-dashboard:1.4");
}
[Fact]
public void TestDeployMicrosoftSqlServer()
{
Context.Configuration.AddService("my-service", "mssql");
_driver.DeployService("my-service", "linux");
Shell.LastCommand.ShouldBe(
"docker run --name my-service --publish 1433:1433 --detach --rm steeltoeoss/mssql-amd64-linux:2017-CU11");
_driver.DeployService("my-service", "windows");
Shell.LastCommand.ShouldBe(
"docker run --name my-service --publish 1433:1433 --detach --rm steeltoeoss/mssql-amd64-windows:2017-CU1");
}
[Fact]
public void TestDeployMySql()
{
Context.Configuration.AddService("my-service", "mysql");
_driver.DeployService("my-service");
Shell.Commands[1].ShouldBe("docker run --name my-service --publish 3306:3306 --detach --rm steeltoeoss/mysql:5.7");
}
[Fact]
public void TestDeployMyPostgreSql()
{
Context.Configuration.AddService("my-service", "postgresql");
_driver.DeployService("my-service");
Shell.Commands[1].ShouldBe("docker run --name my-service --publish 5432:5432 --detach --rm steeltoeoss/postgresql:10.8");
}
[Fact]
public void TestDeployMyRabbitMQ()
{
Context.Configuration.AddService("my-service", "rabbitmq");
_driver.DeployService("my-service");
Shell.Commands[1].ShouldBe("docker run --name my-service --publish 5672:5672 --detach --rm steeltoeoss/rabbitmq:3.7");
}
[Fact]
public void TestDeployRedis()
{
Context.Configuration.AddService("my-service", "redis");
_driver.DeployService("my-service", "linux");
Shell.LastCommand.ShouldBe(
"docker run --name my-service --publish 6379:6379 --detach --rm steeltoeoss/redis-amd64-linux:4.0.11");
_driver.DeployService("my-service", "windows");
Shell.LastCommand.ShouldBe(
"docker run --name my-service --publish 6379:6379 --detach --rm steeltoeoss/redis-amd64-windows:3.0.504");
}
[Fact]
public void TestDeployZipkin()
{
Context.Configuration.AddService("my-service", "zipkin");
_driver.DeployService("my-service");
Shell.Commands[1].ShouldBe("docker run --name my-service --publish 9411:9411 --detach --rm steeltoeoss/zipkin:2.11");
}
[Fact]
public void TestUndeployService()
{
Context.Configuration.AddService("my-service", "dummy-svc");
_driver.UndeployService("my-service");
Shell.Commands[0].ShouldBe("docker network disconnect my-service-network my-service");
Shell.Commands[1].ShouldBe("docker stop my-service");
Shell.Commands.Count.ShouldBe(2);
}
[Fact]
public void TestGetServiceLifecycleStateCommand()
{
Context.Configuration.AddService("my-service", "dummy-svc");
_driver.GetServiceStatus("my-service");
Shell.LastCommand.ShouldBe("docker ps --no-trunc --filter name=^/my-service$");
}
[Fact]
public void TestGetServiceLifecycleStateOffline()
{
Context.Configuration.AddService("my-service", "dummy-svc");
var state = _driver.GetServiceStatus("my-service");
state.ShouldBe(Lifecycle.Status.Offline);
}
[Fact]
public void TestGetServiceLifecycleStateStarting()
{
Context.Configuration.AddService("my-service", "dummy-svc");
Shell.AddResponse(
@"CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
0000000000000000000000000000000000000000000000000000000000000000 dummy-server:0.1 java -Djava.security.egd=file:/dev/./urandom -jar config-server.jar 37 seconds ago Up 36 seconds 0.0.0.0:0000->0000/tcp my-service
");
var state = _driver.GetServiceStatus("my-service");
state.ShouldBe(Lifecycle.Status.Starting);
}
[Fact]
public void TestGetServiceLifecycleStateStartingForOs()
{
Context.Configuration.AddService("my-service", "dummy-svc");
Shell.AddResponse(
@"CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
0000000000000000000000000000000000000000000000000000000000000000 dummy-server:for_dummyos java -Djava.security.egd=file:/dev/./urandom -jar config-server.jar 37 seconds ago Up 36 seconds 0.0.0.0:0000->0000/tcp my-service
");
Shell.AddResponse("OSType: dummyos");
var state = _driver.GetServiceStatus("my-service");
state.ShouldBe(Lifecycle.Status.Starting);
}
}
}

Просмотреть файл

@ -1,83 +0,0 @@
// Copyright 2018 the original author or authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
using Shouldly;
using Steeltoe.Tooling.Drivers.Docker;
using Xunit;
namespace Steeltoe.Tooling.Test.Drivers.Docker
{
public class DockerTargetTest : ToolingTest
{
private readonly DockerTarget _env;
public DockerTargetTest()
{
_env = Registry.GetTarget("docker") as DockerTarget;
}
[Fact]
public void TestGetName()
{
_env.Name.ShouldBe("docker");
}
[Fact]
public void TestGetDescription()
{
_env.Description.ShouldBe("Docker");
}
[Fact]
public void TestGetDriver()
{
_env.GetDriver(Context).ShouldBeOfType<DockerDriver>();
}
[Fact]
public void TestIsHealthy()
{
Shell.AddResponse("Docker version SOME VERSION");
Shell.AddResponse(@"
Operating System: SOME HOST OS
OSType: SOME CONTAINER OS
");
var healthy = _env.IsHealthy(Context);
healthy.ShouldBeTrue();
var expected = new[]
{
"docker --version",
"docker info",
};
Shell.Commands.Count.ShouldBe(expected.Length);
for (int i = 0; i < expected.Length; ++i)
{
Shell.Commands[i].ShouldBe(expected[i]);
}
Console.ToString().ShouldContain("Docker ... Docker version SOME VERSION");
Console.ToString().ShouldContain("Docker host OS ... SOME HOST OS");
Console.ToString().ShouldContain("Docker container OS ... SOME CONTAINER OS");
}
[Fact]
public void TestIsHealthyDockerNotRunning()
{
Shell.AddResponse("");
Shell.AddResponse("", 1);
var healthy = _env.IsHealthy(Context);
healthy.ShouldBeFalse();
}
}
}

Просмотреть файл

@ -1,56 +0,0 @@
// Copyright 2018 the original author or authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
using System.IO;
using Shouldly;
using Steeltoe.Tooling.Drivers.Dummy;
using Xunit;
// ReSharper disable ObjectCreationAsStatement
namespace Steeltoe.Tooling.Test.Drivers.Dummy
{
public class DummyDriverTest : ToolingTest
{
private readonly string _dbFile;
private readonly DummyDriver _driver;
public DummyDriverTest()
{
Directory.CreateDirectory(Context.ProjectDirectory);
_dbFile = Path.Combine(Context.ProjectDirectory, "dummy.db");
_driver = new DummyDriver(_dbFile);
}
[Fact]
public void TestLifecyle()
{
File.Exists(_dbFile).ShouldBeTrue();
// start state -> offline
_driver.GetServiceStatus("my-service").ShouldBe(Lifecycle.Status.Offline);
// offline -> deploy -> starting -> online
_driver.DeployService("my-service");
_driver.GetServiceStatus("my-service").ShouldBe(Lifecycle.Status.Starting);
_driver.GetServiceStatus("my-service").ShouldBe(Lifecycle.Status.Online);
// online -> undeploy -> stopping -> offline
_driver.UndeployService("my-service");
_driver.GetServiceStatus("my-service").ShouldBe(Lifecycle.Status.Stopping);
_driver.GetServiceStatus("my-service").ShouldBe(Lifecycle.Status.Offline);
}
}
}

Просмотреть файл

@ -1,42 +0,0 @@
// Copyright 2018 the original author or authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
using Shouldly;
using Steeltoe.Tooling.Drivers.Dummy;
using Xunit;
namespace Steeltoe.Tooling.Test.Drivers.Dummy
{
public class DummyTargetTest : ToolingTest
{
private readonly DummyTarget _target;
public DummyTargetTest()
{
_target = Registry.GetTarget("dummy-target") as DummyTarget;
}
[Fact]
public void TestGetName()
{
_target.Name.ShouldBe("dummy-target");
}
[Fact]
public void TestGetDescription()
{
_target.Description.ShouldBe("A Dummy Target");
}
}
}

Просмотреть файл

@ -1,298 +0,0 @@
// Copyright 2018 the original author or authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
using System.IO;
using Shouldly;
using Steeltoe.Tooling.Drivers.Kubernetes;
using Xunit;
namespace Steeltoe.Tooling.Test.Drivers.Kubernetes
{
public class KubernetesDriverTest : ToolingTest
{
private readonly KubernetesDriver _driver;
public KubernetesDriverTest()
{
Context.Configuration.Target = "kubernetes";
_driver = Context.Target.GetDriver(Context) as KubernetesDriver;
}
[Fact]
public void TestDeployApp()
{
Context.Configuration.AddApp("my-App", "dummy-framework", "dummy-runtime");
_driver.DeployApp("my-App");
// Dockerfile
var dockerfileFile =
new KubernetesDotnetAppDockerfileFile(Path.Join(Context.ProjectDirectory, "Dockerfile"));
dockerfileFile.Exists().ShouldBeTrue();
// service config
var svcCfgFile =
new KubernetesServiceConfigFile(Path.Join(Context.ProjectDirectory, "my-App-service.yaml"));
svcCfgFile.Exists().ShouldBeTrue();
// commands
Shell.Commands.Count.ShouldBe(3);
Shell.Commands[0].ShouldBe("docker build --tag my-app .");
Shell.Commands[1].ShouldBe("kubectl apply --filename my-App-deployment.yaml");
Shell.Commands[2].ShouldBe("kubectl apply --filename my-App-service.yaml");
}
[Fact]
public void TestUndeployApp()
{
Context.Configuration.AddApp("my-App", "dummy-framework", "dummy-runtime");
_driver.UndeployApp("my-App");
Shell.Commands.Count.ShouldBe(2);
Shell.Commands[0].ShouldBe("kubectl delete --filename my-App-service.yaml");
Shell.Commands[1].ShouldBe("kubectl delete --filename my-App-deployment.yaml");
}
[Fact]
public void TestDeployService()
{
Context.Configuration.AddService("my-Service", "dummy-svc");
_driver.DeployService("my-Service");
// deployment config
var deployCfgFile =
new KubernetesDeploymentConfigFile(Path.Join(Context.ProjectDirectory, "my-Service-deployment.yaml"));
deployCfgFile.Exists().ShouldBeTrue();
var deployCfg = deployCfgFile.KubernetesDeploymentConfig;
// deployCfg.ApiVersion.ShouldBe("apps/v1");
// deployCfg.Kind.ShouldBe("Deployment");
// deployCfg.MetaData.Name.ShouldBe("my-service");
// deployCfg.MetaData.Labels["app"].ShouldBe("my-service");
// deployCfg.Spec.Selector.MatchLabels["app"].ShouldBe("my-service");
// deployCfg.Spec.Template.MetaData.Labels["app"].ShouldBe("my-service");
// deployCfg.Spec.Template.Spec.Containers[0].Name.ShouldBe("my-service");
// service config
var svcCfgFile =
new KubernetesServiceConfigFile(Path.Join(Context.ProjectDirectory, "my-Service-service.yaml"));
svcCfgFile.Exists().ShouldBeTrue();
// var svcCfg = new KubernetesServiceConfigFile("my-Service-service.yaml").KubernetesServiceConfig;
// svcCfg.ApiVersion.ShouldBe("v1");
// svcCfg.Kind.ShouldBe("Service");
// svcCfg.MetaData.Name.ShouldBe("my-service");
// svcCfg.Spec.Selector["app"].ShouldBe("my-service");
// commands
Shell.Commands.Count.ShouldBe(2);
Shell.Commands[0].ShouldBe("kubectl apply --filename my-Service-deployment.yaml");
Shell.Commands[1].ShouldBe("kubectl apply --filename my-Service-service.yaml");
}
[Fact]
public void TestDeployConfigServer()
{
Context.Configuration.AddService("my-service", "config-server");
_driver.DeployService("my-service");
var deployCfg = new KubernetesDeploymentConfigFile("my-service-deployment.yaml").KubernetesDeploymentConfig;
// deployCfg.Spec.Template.Spec.Containers[0].Image.ShouldBe("steeltoeoss/config-server:2.0");
// deployCfg.Spec.Template.Spec.Containers[0].Ports.Count.ShouldBe(1);
// deployCfg.Spec.Template.Spec.Containers[0].Ports[0].ContainerPort.ShouldBe(8888);
var svcCfg = new KubernetesServiceConfigFile("my-service-service.yaml").KubernetesServiceConfig;
// svcCfg.Spec.Ports[0].Port.ShouldBe(8888);
}
[Fact]
public void TestDeployEurekaServer()
{
Context.Configuration.AddService("my-service", "eureka-server");
_driver.DeployService("my-service");
// var deployCfg = new KubernetesDeploymentConfigFile("my-service-deployment.yaml").KubernetesDeploymentConfig;
// deployCfg.Spec.Template.Spec.Containers[0].Image.ShouldBe("steeltoeoss/eureka-server:2.0");
// deployCfg.Spec.Template.Spec.Containers[0].Ports.Count.ShouldBe(1);
// deployCfg.Spec.Template.Spec.Containers[0].Ports[0].ContainerPort.ShouldBe(8761);
// var svcCfg = new KubernetesServiceConfigFile("my-service-service.yaml").KubernetesServiceConfig;
// svcCfg.Spec.Ports[0].Port.ShouldBe(8761);
}
[Fact]
public void TestDeployHystrixDashboard()
{
Context.Configuration.AddService("my-service", "hystrix-dashboard");
_driver.DeployService("my-service");
// var deployCfg = new KubernetesDeploymentConfigFile("my-service-deployment.yaml").KubernetesDeploymentConfig;
// deployCfg.Spec.Template.Spec.Containers[0].Image.ShouldBe("steeltoeoss/hystrix-dashboard:1.4");
// deployCfg.Spec.Template.Spec.Containers[0].Ports.Count.ShouldBe(1);
// deployCfg.Spec.Template.Spec.Containers[0].Ports[0].ContainerPort.ShouldBe(7979);
// var svcCfg = new KubernetesServiceConfigFile("my-service-service.yaml").KubernetesServiceConfig;
// svcCfg.Spec.Ports[0].Port.ShouldBe(7979);
}
[Fact]
public void TestDeployMicrosoftSqlServer()
{
Context.Configuration.AddService("my-service", "mssql");
_driver.DeployService("my-service");
// var deployCfg = new KubernetesDeploymentConfigFile("my-service-deployment.yaml").KubernetesDeploymentConfig;
// deployCfg.Spec.Template.Spec.Containers[0].Ports.Count.ShouldBe(1);
// deployCfg.Spec.Template.Spec.Containers[0].Ports[0].ContainerPort.ShouldBe(1433);
// var svcCfg = new KubernetesServiceConfigFile("my-service-service.yaml").KubernetesServiceConfig;
// svcCfg.Spec.Ports[0].Port.ShouldBe(1433);
// _driver.DeployService("my-service", "linux");
// deployCfg = new KubernetesDeploymentConfigFile("my-service-deployment.yaml").KubernetesDeploymentConfig;
// deployCfg.Spec.Template.Spec.Containers[0].Image.ShouldBe("steeltoeoss/mssql-amd64-linux:2017-CU11");
// _driver.DeployService("my-service", "windows");
// deployCfg = new KubernetesDeploymentConfigFile("my-service-deployment.yaml").KubernetesDeploymentConfig;
// deployCfg.Spec.Template.Spec.Containers[0].Image.ShouldBe("steeltoeoss/mssql-amd64-windows:2017-CU1");
}
[Fact]
public void TestDeployMySql()
{
Context.Configuration.AddService("my-service", "mysql");
_driver.DeployService("my-service");
// var deployCfg = new KubernetesDeploymentConfigFile("my-service-deployment.yaml").KubernetesDeploymentConfig;
// deployCfg.Spec.Template.Spec.Containers[0].Image.ShouldBe("steeltoeoss/mysql:5.7");
// deployCfg.Spec.Template.Spec.Containers[0].Ports.Count.ShouldBe(1);
// deployCfg.Spec.Template.Spec.Containers[0].Ports[0].ContainerPort.ShouldBe(3306);
// var svcCfg = new KubernetesServiceConfigFile("my-service-service.yaml").KubernetesServiceConfig;
// svcCfg.Spec.Ports[0].Port.ShouldBe(3306);
}
[Fact]
public void TestDeployPostgreSql()
{
Context.Configuration.AddService("my-service", "postgresql");
_driver.DeployService("my-service");
// var deployCfg = new KubernetesDeploymentConfigFile("my-service-deployment.yaml").KubernetesDeploymentConfig;
// deployCfg.Spec.Template.Spec.Containers[0].Image.ShouldBe("steeltoeoss/postgresql:10.8");
// deployCfg.Spec.Template.Spec.Containers[0].Ports.Count.ShouldBe(1);
// deployCfg.Spec.Template.Spec.Containers[0].Ports[0].ContainerPort.ShouldBe(5432);
// var svcCfg = new KubernetesServiceConfigFile("my-service-service.yaml").KubernetesServiceConfig;
// svcCfg.Spec.Ports[0].Port.ShouldBe(5432);
}
[Fact]
public void TestDeployRabbitMQ()
{
Context.Configuration.AddService("my-service", "rabbitmq");
_driver.DeployService("my-service");
// var deployCfg = new KubernetesDeploymentConfigFile("my-service-deployment.yaml").KubernetesDeploymentConfig;
// deployCfg.Spec.Template.Spec.Containers[0].Image.ShouldBe("steeltoeoss/rabbitmq:3.7");
// deployCfg.Spec.Template.Spec.Containers[0].Ports.Count.ShouldBe(1);
// deployCfg.Spec.Template.Spec.Containers[0].Ports[0].ContainerPort.ShouldBe(5672);
// var svcCfg = new KubernetesServiceConfigFile("my-service-service.yaml").KubernetesServiceConfig;
// svcCfg.Spec.Ports[0].Port.ShouldBe(5672);
}
[Fact]
public void TestDeployRedis()
{
Context.Configuration.AddService("my-service", "redis");
_driver.DeployService("my-service");
// var deployCfg = new KubernetesDeploymentConfigFile("my-service-deployment.yaml").KubernetesDeploymentConfig;
// deployCfg.Spec.Template.Spec.Containers[0].Ports.Count.ShouldBe(1);
// deployCfg.Spec.Template.Spec.Containers[0].Ports[0].ContainerPort.ShouldBe(6379);
// var svcCfg = new KubernetesServiceConfigFile("my-service-service.yaml").KubernetesServiceConfig;
// svcCfg.Spec.Ports[0].Port.ShouldBe(6379);
// _driver.DeployService("my-service", "linux");
// deployCfg = new KubernetesDeploymentConfigFile("my-service-deployment.yaml").KubernetesDeploymentConfig;
// deployCfg.Spec.Template.Spec.Containers[0].Image.ShouldBe("steeltoeoss/redis-amd64-linux:4.0.11");
// _driver.DeployService("my-service", "windows");
// deployCfg = new KubernetesDeploymentConfigFile("my-service-deployment.yaml").KubernetesDeploymentConfig;
// deployCfg.Spec.Template.Spec.Containers[0].Image.ShouldBe("steeltoeoss/redis-amd64-windows:3.0.504");
}
[Fact]
public void TestDeployZipkin()
{
Context.Configuration.AddService("my-service", "zipkin");
_driver.DeployService("my-service");
// var deployCfg = new KubernetesDeploymentConfigFile("my-service-deployment.yaml").KubernetesDeploymentConfig;
// deployCfg.Spec.Template.Spec.Containers[0].Image.ShouldBe("steeltoeoss/zipkin:2.11");
// deployCfg.Spec.Template.Spec.Containers[0].Ports.Count.ShouldBe(1);
// deployCfg.Spec.Template.Spec.Containers[0].Ports[0].ContainerPort.ShouldBe(9411);
// var svcCfg = new KubernetesServiceConfigFile("my-service-service.yaml").KubernetesServiceConfig;
// svcCfg.Spec.Ports[0].Port.ShouldBe(9411);
}
[Fact]
public void TestUndeployService()
{
Context.Configuration.AddService("my-Service", "dummy-svc");
_driver.UndeployService("my-Service");
Shell.Commands.Count.ShouldBe(2);
Shell.Commands[0].ShouldBe("kubectl delete --filename my-Service-service.yaml");
Shell.Commands[1].ShouldBe("kubectl delete --filename my-Service-deployment.yaml");
}
[Fact]
public void TestCheckApp()
{
Context.Configuration.AddApp("my-App", "dummy-framework", "dummy-runtime");
_driver.GetAppStatus("my-App");
Shell.Commands.Count.ShouldBe(2);
Shell.Commands[0].ShouldBe("kubectl get pods --selector app=my-app");
Shell.Commands[1].ShouldBe("kubectl get services my-app");
}
[Fact]
public void TestCheckService()
{
Context.Configuration.AddService("my-Service", "dummy-svc");
Shell.AddResponse("Running");
_driver.GetServiceStatus("my-Service");
Shell.Commands.Count.ShouldBe(1);
Shell.Commands[0].ShouldBe("kubectl get pods --selector app=my-service");
// Shell.Commands[1].ShouldBe("kubectl get services my-service");
}
[Fact]
public void TestServiceStarting()
{
Context.Configuration.AddService("my-Service", "dummy-svc");
Shell.AddResponse("Pending");
_driver.GetServiceStatus("my-Service").ShouldBe(Lifecycle.Status.Starting);
Shell.AddResponse("ContainerCreating");
_driver.GetServiceStatus("my-Service").ShouldBe(Lifecycle.Status.Starting);
}
[Fact]
public void TestServiceStopping()
{
Context.Configuration.AddService("my-Service", "dummy-svc");
Shell.AddResponse("Terminating");
_driver.GetServiceStatus("my-Service").ShouldBe(Lifecycle.Status.Stopping);
Shell.AddResponse("");
_driver.GetServiceStatus("my-Service").ShouldBe(Lifecycle.Status.Stopping);
}
[Fact]
public void TestAppOnline()
{
Context.Configuration.AddApp("my-App", "dummy-framework", "dummy-runtime");
Shell.AddResponse("Running");
_driver.GetAppStatus("my-App").ShouldBe(Lifecycle.Status.Online);
}
[Fact]
public void TestServiceOnline()
{
Context.Configuration.AddService("my-Service", "dummy-svc");
Shell.AddResponse("Running");
_driver.GetServiceStatus("my-Service").ShouldBe(Lifecycle.Status.Online);
}
[Fact]
public void TestServiceOffline()
{
Context.Configuration.AddService("my-Service", "dummy-svc");
Shell.AddResponse("");
Shell.AddResponse("", -1);
_driver.GetServiceStatus("my-Service").ShouldBe(Lifecycle.Status.Offline);
}
}
}

Просмотреть файл

@ -1,73 +0,0 @@
// Copyright 2018 the original author or authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
using Shouldly;
using Steeltoe.Tooling.Drivers.Kubernetes;
using Xunit;
namespace Steeltoe.Tooling.Test.Drivers.Kubernetes
{
public class KubernetesTargetTest : ToolingTest
{
private readonly KubernetesTarget _target;
public KubernetesTargetTest()
{
_target = Registry.GetTarget("kubernetes") as KubernetesTarget;
}
[Fact]
public void TestGetName()
{
_target.Name.ShouldBe("kubernetes");
}
[Fact]
public void TestGetDescription()
{
_target.Description.ShouldBe("Kubernetes");
}
[Fact]
public void TestGetDriver()
{
_target.GetDriver(Context).ShouldBeOfType<KubernetesDriver>();
}
[Fact]
public void TestIsHealthy()
{
Shell.AddResponse(@"Client Version: version.Info{Major:""9"", Minor:""87"", ...
Server Version: version.Info{Major:""6"", Minor:""54"", ...");
Shell.AddResponse(@"CURRENT NAME CLUSTER AUTHINFO NAMESPACE
* context1 cluster1 authinfo1
context2 cluster2 authinfo2
");
var healthy = _target.IsHealthy(Context);
healthy.ShouldBeTrue();
var expected = new[]
{
"kubectl version",
"kubectl config get-contexts",
};
Shell.Commands.Count.ShouldBe(expected.Length);
for (int i = 0; i < expected.Length; ++i)
{
Shell.Commands[i].ShouldBe(expected[i]);
}
Console.ToString().ShouldContain("Kubernetes ... kubectl client version 9.87, server version 6.54");
Console.ToString().ShouldContain("current context ... context1");
}
}
}

Просмотреть файл

@ -1,45 +0,0 @@
// Copyright 2018 the original author or authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
using Shouldly;
using Steeltoe.Tooling.Executors;
using Xunit;
namespace Steeltoe.Tooling.Test.Executors
{
public class AddExecutorTest : ToolingTest
{
[Fact]
public void TestAdd()
{
new AddAppExecutor("my-app", "dummy-framework", "dummy-runtime").Execute(Context);
Console.ToString().Trim().ShouldBe("Added app 'my-app' (dummy-framework/dummy-runtime)");
Context.Configuration.GetApps().Count.ShouldBe(1);
Context.Configuration.GetApps()[0].ShouldBe("my-app");
var appInfo = Context.Configuration.GetAppInfo("my-app");
appInfo.App.ShouldBe("my-app");
}
[Fact]
public void TestAddExistingApp()
{
Context.Configuration.AddApp("existing-app", "dummy-framework", "dummy-runtime");
var e = Assert.Throws<ItemExistsException>(
() => new AddAppExecutor("existing-app", "dummy-framework", "dummy-runtime").Execute(Context)
);
e.Name.ShouldBe("existing-app");
e.Description.ShouldBe("app");
}
}
}

Просмотреть файл

@ -1,57 +0,0 @@
// Copyright 2018 the original author or authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
using Shouldly;
using Steeltoe.Tooling.Executors;
using Xunit;
namespace Steeltoe.Tooling.Test.Executors
{
public class AddServiceExecutorTest : ToolingTest
{
[Fact]
public void TestAddService()
{
new AddServiceExecutor("my-service", "dummy-svc").Execute(Context);
Console.ToString().Trim().ShouldBe("Added dummy-svc service 'my-service'");
Context.Configuration.GetServices().Count.ShouldBe(1);
var svcName = Context.Configuration.GetServices()[0];
svcName.ShouldBe("my-service");
var svcInfo = Context.Configuration.GetServiceInfo(svcName);
svcInfo.Service.ShouldBe("my-service");
svcInfo.ServiceType.ShouldBe("dummy-svc");
}
[Fact]
public void TestAddExistingService()
{
Context.Configuration.AddService("existing-service", "dummy-svc");
var e = Assert.Throws<ItemExistsException>(
() => new AddServiceExecutor("existing-service", "dummy-svc").Execute(Context)
);
e.Name.ShouldBe("existing-service");
e.Description.ShouldBe("service");
}
[Fact]
public void TestAddUnknownServiceType()
{
var e = Assert.Throws<ItemDoesNotExistException>(
() => new AddServiceExecutor("unknown-service", "unknown-service-type").Execute(Context)
);
e.Name.ShouldBe("unknown-service-type");
e.Description.ShouldBe("service type");
}
}
}

Просмотреть файл

@ -1,57 +0,0 @@
// Copyright 2018 the original author or authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
using Shouldly;
using Steeltoe.Tooling.Executors;
using Xunit;
namespace Steeltoe.Tooling.Test.Executors
{
public class DeployExecutorTest : ToolingTest
{
[Fact]
public void TestDeploy()
{
Context.Configuration.AddApp("my-app", "dummy-framework", "dummy-runtime");
Context.Configuration.AddService("my-service", "dummy-svc");
Context.Configuration.AddService("another-service", "dummy-svc");
ClearConsole();
new DeployExecutor().Execute(Context);
Console.ToString().ShouldContain("Deploying service 'my-service'");
Console.ToString().ShouldContain("Deploying service 'another-service'");
Console.ToString().ShouldContain("Deploying app 'my-app'");
Context.Driver.GetServiceStatus("my-service").ShouldBe(Lifecycle.Status.Online);
Context.Driver.GetServiceStatus("another-service").ShouldBe(Lifecycle.Status.Online);
Context.Driver.GetAppStatus("my-app").ShouldBe(Lifecycle.Status.Online);
}
[Fact]
public void TestDeployNothing()
{
new DeployExecutor().Execute(Context);
Console.ToString().Trim().ShouldBeEmpty();
}
[Fact]
public void TestDeployNoTarget()
{
Context.Configuration.Target = null;
Context.Configuration.AddService("my-service", "dummy-svc");
var e = Assert.Throws<ToolingException>(
() => new DeployExecutor().Execute(Context)
);
e.Message.ShouldBe("Target not set");
}
}
}

Просмотреть файл

@ -1,141 +0,0 @@
// Copyright 2018 the original author or authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
using Shouldly;
using Steeltoe.Tooling.Executors;
using Xunit;
namespace Steeltoe.Tooling.Test.Executors
{
public class GetArgsExecutorTest : ToolingTest
{
[Fact]
public void TestGetArgsUnknownAppOrService()
{
var e = Assert.Throws<ItemDoesNotExistException>(
() => new GetArgsExecutor("no-such-app-or-svc").Execute(Context)
);
e.Name.ShouldBe("no-such-app-or-svc");
e.Description.ShouldBe("app or service");
}
[Fact]
public void TestGetTargetArgsUnknownAppOrService()
{
var e = Assert.Throws<ItemDoesNotExistException>(
() => new GetArgsExecutor("no-such-app-or-svc", "dummy-target").Execute(Context)
);
e.Name.ShouldBe("no-such-app-or-svc");
e.Description.ShouldBe("app or service");
}
[Fact]
public void TestGetAppArgs()
{
new AddAppExecutor("my-app", "dummy-framework", "dummy-runtime").Execute(Context);
new SetArgsExecutor("my-app", "arg1 arg2").Execute(Context);
ClearConsole();
new GetArgsExecutor("my-app").Execute(Context);
Console.ToString().Trim().ShouldBe("arg1 arg2");
}
[Fact]
public void TestGetAppTargetArgs()
{
new AddAppExecutor("my-app", "dummy-framework", "dummy-runtime").Execute(Context);
new SetArgsExecutor("my-app", "dummy-target", "arg1 arg2").Execute(Context);
ClearConsole();
new GetArgsExecutor("my-app", "dummy-target").Execute(Context);
Console.ToString().Trim().ShouldBe("arg1 arg2");
}
[Fact]
public void TestGetAppNoArgs()
{
new AddAppExecutor("my-app", "dummy-framework", "dummy-runtime").Execute(Context);
ClearConsole();
new GetArgsExecutor("my-app").Execute(Context);
Console.ToString().Trim().ShouldBeEmpty();
}
[Fact]
public void TestGetAppTargetNoArgs()
{
new AddAppExecutor("my-app", "dummy-framework", "dummy-runtime").Execute(Context);
ClearConsole();
new GetArgsExecutor("my-app", "dummy-target").Execute(Context);
Console.ToString().Trim().ShouldBeEmpty();
}
[Fact]
public void TestGetAppArgsUnknownTarget()
{
new AddAppExecutor("my-app", "dummy-framework", "dummy-runtime").Execute(Context);
var e = Assert.Throws<ItemDoesNotExistException>(
() => new GetArgsExecutor("my-app", "no-such-target").Execute(Context)
);
e.Name.ShouldBe("no-such-target");
e.Description.ShouldBe("target");
}
[Fact]
public void TestGetServiceArgs()
{
new AddServiceExecutor("my-service", "dummy-svc").Execute(Context);
new SetArgsExecutor("my-service", "arg1 arg2").Execute(Context);
ClearConsole();
new GetArgsExecutor("my-service").Execute(Context);
Console.ToString().Trim().ShouldBe("arg1 arg2");
}
[Fact]
public void TestGetServiceTargetArgs()
{
new AddServiceExecutor("my-service", "dummy-svc").Execute(Context);
new SetArgsExecutor("my-service", "dummy-target", "arg1 arg2").Execute(Context);
ClearConsole();
new GetArgsExecutor("my-service", "dummy-target").Execute(Context);
Console.ToString().Trim().ShouldBe("arg1 arg2");
}
[Fact]
public void TestGetServiceNoArgs()
{
new AddServiceExecutor("my-service", "dummy-svc").Execute(Context);
ClearConsole();
new GetArgsExecutor("my-service").Execute(Context);
Console.ToString().Trim().ShouldBeEmpty();
}
[Fact]
public void TestGetServiceTargetNoArgs()
{
new AddServiceExecutor("my-service", "dummy-svc").Execute(Context);
ClearConsole();
new GetArgsExecutor("my-service", "dummy-target").Execute(Context);
Console.ToString().Trim().ShouldBeEmpty();
}
[Fact]
public void TestGetServiceArgsUnknownTarget()
{
new AddServiceExecutor("my-service", "dummy-svc").Execute(Context);
var e = Assert.Throws<ItemDoesNotExistException>(
() => new GetArgsExecutor("my-service", "no-such-target").Execute(Context)
);
e.Name.ShouldBe("no-such-target");
e.Description.ShouldBe("target");
}
}
}

Просмотреть файл

@ -1,41 +0,0 @@
// Copyright 2018 the original author or authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
using Shouldly;
using Steeltoe.Tooling.Executors;
using Xunit;
namespace Steeltoe.Tooling.Test.Executors
{
public class GetTargetExecutorTest : ToolingTest
{
[Fact]
public void TestGetTarget()
{
Context.Configuration.Target = "dummy-target";
new GetTargetExecutor().Execute(Context);
Console.ToString().Trim().ShouldBe("dummy-target");
}
[Fact]
public void TestGetTargetNotSet()
{
Context.Configuration.Target = null;
var e = Assert.Throws<ToolingException>(
() => new GetTargetExecutor().Execute(Context)
);
e.Message.ShouldBe("Target not set");
}
}
}

Просмотреть файл

@ -1,59 +0,0 @@
// Copyright 2018 the original author or authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
using System.IO;
using Shouldly;
using Steeltoe.Tooling.Executors;
using Xunit;
namespace Steeltoe.Tooling.Test.Executors
{
public class InitializationExecutorTest : ToolingTest
{
[Fact]
public void TestInitialization()
{
new InitializationExecutor().Execute(Context);
File.Exists(Path.Join(Context.ProjectDirectory, ConfigurationFile.DefaultFileName)).ShouldBeTrue();
Console.ToString().Trim().ShouldBe("Initialized Steeltoe Developer Tools");
}
[Fact]
public void TestInitializationAutodetectApp()
{
var projectFile = Path.Combine(Context.ProjectDirectory, "my-autodetected-app.csproj");
File.Create(projectFile).Dispose();
new InitializationExecutor(autodetect: true).Execute(Context);
File.Exists(Path.Join(Context.ProjectDirectory, ConfigurationFile.DefaultFileName)).ShouldBeTrue();
Context.Configuration.GetAppInfo("my-autodetected-app").App.ShouldBe("my-autodetected-app");
var reader = new StringReader(Console.ToString());
reader.ReadLine().ShouldBe("Added app 'my-autodetected-app' (netcoreapp2.1/win10-x64)");
reader.ReadLine().ShouldBe("Initialized Steeltoe Developer Tools");
reader.ReadLine().ShouldBeNull();
}
[Fact]
public void TestInitializationForce()
{
var file = "config-file";
new ConfigurationFile(Path.Combine(Context.ProjectDirectory, file)).Store();
var e = Assert.Throws<ToolingException>(
() => new InitializationExecutor(file).Execute(Context)
);
e.Message.ShouldBe("Steeltoe Developer Tools already initialized");
new InitializationExecutor(file, force: true).Execute(Context);
Console.ToString().Trim().ShouldBe("Initialized Steeltoe Developer Tools");
}
}
}

Просмотреть файл

@ -1,65 +0,0 @@
// Copyright 2018 the original author or authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
using System.IO;
using Shouldly;
using Steeltoe.Tooling.Executors;
using Xunit;
namespace Steeltoe.Tooling.Test.Executors
{
public class ListExecutorTest : ToolingTest
{
[Fact]
public void TestListNone()
{
new ListExecutor().Execute(Context);
Console.ToString().ShouldBeEmpty();
}
[Fact]
public void TestList()
{
Context.Configuration.AddApp("my-app", "dummy-framework", "dummy-runtime");
Context.Configuration.AddService("my-service-c", "dummy-svc");
Context.Configuration.AddService("my-service-a", "dummy-svc");
Context.Configuration.AddService("my-service-b", "dummy-svc");
ClearConsole();
new ListExecutor().Execute(Context);
var reader = new StringReader(Console.ToString());
reader.ReadLine().ShouldBe("my-service-a");
reader.ReadLine().ShouldBe("my-service-b");
reader.ReadLine().ShouldBe("my-service-c");
reader.ReadLine().ShouldBe("my-app");
reader.ReadLine().ShouldBeNull();
}
[Fact]
public void TestListVerbose()
{
Context.Configuration.AddApp("my-app", "dummy-framework", "dummy-runtime");
Context.Configuration.AddService("my-service-c", "dummy-svc");
Context.Configuration.AddService("my-service-a", "dummy-svc");
Context.Configuration.AddService("my-service-b", "dummy-svc");
ClearConsole();
new ListExecutor(true).Execute(Context);
var reader = new StringReader(Console.ToString());
reader.ReadLine().ShouldBe("my-service-a 0 dummy-svc");
reader.ReadLine().ShouldBe("my-service-b 0 dummy-svc");
reader.ReadLine().ShouldBe("my-service-c 0 dummy-svc");
reader.ReadLine().ShouldBe("my-app app");
reader.ReadLine().ShouldBeNull();
}
}
}

Просмотреть файл

@ -1,59 +0,0 @@
// Copyright 2018 the original author or authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
using System.IO;
using Shouldly;
using Steeltoe.Tooling.Executors;
namespace Steeltoe.Tooling.Test.Executors
{
public class ListServiceTypesExecutorTest : ToolingTest
{
// [Fact]
public void TestListServiceTypes()
{
new ListServiceTypesExecutor().Execute(Context);
var reader = new StringReader(Console.ToString());
reader.ReadLine().ShouldBe("config-server");
reader.ReadLine().ShouldBe("dummy-svc");
reader.ReadLine().ShouldBe("eureka-server");
reader.ReadLine().ShouldBe("hystrix-dashboard");
reader.ReadLine().ShouldBe("mssql");
reader.ReadLine().ShouldBe("mysql");
reader.ReadLine().ShouldBe("postgresql");
reader.ReadLine().ShouldBe("rabbitmq");
reader.ReadLine().ShouldBe("redis");
reader.ReadLine().ShouldBe("zipkin");
reader.ReadLine().ShouldBeNull();
}
// [Fact]
public void TestListServiceTypesVerbose()
{
new ListServiceTypesExecutor(true).Execute(Context);
var reader = new StringReader(Console.ToString());
reader.ReadLine().ShouldBe("config-server 8888 Cloud Foundry Config Server");
reader.ReadLine().ShouldBe("dummy-svc 0 A Dummy Service");
reader.ReadLine().ShouldBe("eureka-server 8761 Netflix Eureka Server");
reader.ReadLine().ShouldBe("hystrix-dashboard 7979 Netflix Hystrix Dashboard");
reader.ReadLine().ShouldBe("mssql 1433 Microsoft SQL Server");
reader.ReadLine().ShouldBe("mysql 3306 MySQL Server");
reader.ReadLine().ShouldBe("postgresql 5432 PostgreSQL SQL Server");
reader.ReadLine().ShouldBe("rabbitmq 5672 RabbitMQ Message Broker");
reader.ReadLine().ShouldBe("redis 6379 Redis In-Memory Datastore");
reader.ReadLine().ShouldBe("zipkin 9411 Zipkin Tracing Collector and UI");
reader.ReadLine().ShouldBeNull();
}
}
}

Некоторые файлы не были показаны из-за слишком большого количества измененных файлов Показать больше