Finishes initial implementation of remove-service

This commit is contained in:
Chris Cheetham 2018-08-15 11:03:46 -04:00
Родитель 8bb0ec1af6
Коммит 32b5131cf9
14 изменённых файлов: 319 добавлений и 73 удалений

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

@ -69,6 +69,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Steeltoe.Tooling.Base", "sr
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Steeltoe.Tooling.Test.Base", "test\Steeltoe.Tooling.Test.Base\Steeltoe.Tooling.Test.Base.csproj", "{B4F6680A-3479-47D7-A073-33E05B46DB74}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Steeltoe.Tooling.DotnetCli.Feature", "feature\Steeltoe.Tooling.DotnetCli.Feature\Steeltoe.Tooling.DotnetCli.Feature.csproj", "{BD4A2CBD-33AF-48C3-914D-8A7F58A15348}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -247,6 +249,18 @@ Global
{B4F6680A-3479-47D7-A073-33E05B46DB74}.Release|x64.Build.0 = Release|Any CPU
{B4F6680A-3479-47D7-A073-33E05B46DB74}.Release|x86.ActiveCfg = Release|Any CPU
{B4F6680A-3479-47D7-A073-33E05B46DB74}.Release|x86.Build.0 = Release|Any CPU
{BD4A2CBD-33AF-48C3-914D-8A7F58A15348}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BD4A2CBD-33AF-48C3-914D-8A7F58A15348}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BD4A2CBD-33AF-48C3-914D-8A7F58A15348}.Debug|x64.ActiveCfg = Debug|Any CPU
{BD4A2CBD-33AF-48C3-914D-8A7F58A15348}.Debug|x64.Build.0 = Debug|Any CPU
{BD4A2CBD-33AF-48C3-914D-8A7F58A15348}.Debug|x86.ActiveCfg = Debug|Any CPU
{BD4A2CBD-33AF-48C3-914D-8A7F58A15348}.Debug|x86.Build.0 = Debug|Any CPU
{BD4A2CBD-33AF-48C3-914D-8A7F58A15348}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BD4A2CBD-33AF-48C3-914D-8A7F58A15348}.Release|Any CPU.Build.0 = Release|Any CPU
{BD4A2CBD-33AF-48C3-914D-8A7F58A15348}.Release|x64.ActiveCfg = Release|Any CPU
{BD4A2CBD-33AF-48C3-914D-8A7F58A15348}.Release|x64.Build.0 = Release|Any CPU
{BD4A2CBD-33AF-48C3-914D-8A7F58A15348}.Release|x86.ActiveCfg = Release|Any CPU
{BD4A2CBD-33AF-48C3-914D-8A7F58A15348}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@ -266,6 +280,7 @@ Global
{5E8A4528-A1E3-425F-A924-C7CED998A457} = {67CB55E8-C6E9-471F-A799-7AE925E921ED}
{02E9CE85-F31D-4B1C-BD82-B911596E6B19} = {D86CBDAE-DF37-4BDF-8F81-C79FB11DEC0D}
{B4F6680A-3479-47D7-A073-33E05B46DB74} = {67CB55E8-C6E9-471F-A799-7AE925E921ED}
{BD4A2CBD-33AF-48C3-914D-8A7F58A15348} = {D95EB329-EB3F-4287-90D6-304D509B305F}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {A443975C-C563-4CBC-9EBA-A21E6D258E77}

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

@ -40,7 +40,7 @@ namespace Steeltoe.Tooling.DotnetCli.Base.Feature
protected void a_dotnet_project(string name)
{
Logger.LogInformation($"creating dotnet project '{name}'");
Logger.LogInformation($"rigging a dotnet project '{name}'");
ProjectDirectory = Path.Combine(Path.Combine(Directory.GetCurrentDirectory(), "feature-tests"), name);
if (Directory.Exists(ProjectDirectory))
{
@ -53,6 +53,22 @@ namespace Steeltoe.Tooling.DotnetCli.Base.Feature
result.ExitCode.ShouldBe(0);
}
protected void a_target(string name)
{
Logger.LogInformation($"rigging a target '{name}'");
var cfg = GetProjectConfiguration();
cfg.target = name;
cfg.Store(ProjectDirectory);
}
protected void a_service_named_(string name)
{
Logger.LogInformation($"rigging a service named '{name}'");
var cfg = GetProjectConfiguration();
cfg.services.Add(name, new ToolingConfiguration.Service("foo-type"));
cfg.Store(ProjectDirectory);
}
//
// Whens
//
@ -106,5 +122,33 @@ namespace Steeltoe.Tooling.DotnetCli.Base.Feature
cfg.services.ShouldContainKey(name);
cfg.services[name].type.ShouldBe(type);
}
protected void the_service_does_not_exist(string name)
{
Logger.LogInformation($"checking tooling config does not define the service '{name}'");
var cfg = ToolingConfiguration.Load(ProjectDirectory);
cfg.services.ShouldNotContainKey(name);
}
protected void the_target_exists(string name)
{
var cfg = ToolingConfiguration.Load(ProjectDirectory);
cfg.target.ShouldBe(name);
}
// utilities
private ToolingConfiguration GetProjectConfiguration()
{
try
{
return ToolingConfiguration.Load(ProjectDirectory);
}
catch (FileNotFoundException)
{
return new ToolingConfiguration();
}
}
}
}

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

@ -0,0 +1,3 @@
using LightBDD.XUnit2;
[assembly: LightBddScope]

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

@ -0,0 +1,55 @@
// 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
//
// http://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;
using LightBDD.Framework.Scenarios.Extended;
using LightBDD.XUnit2;
using Steeltoe.Tooling.DotnetCli.Base.Feature;
namespace Steeltoe.Tooling.DotnetCli.Feature
{
[Label("main")]
public class SetTargetFeature : DotnetCliFeatureSpecs
{
[Scenario]
[Label("help")]
public void MainHelp()
{
Runner.RunScenario(
given => a_dotnet_project("main_help"),
when => the_developer_runs_steeltoe_("--help"),
then => the_command_succeeds(),
and => the_developer_sees_("Steeltoe Developer Tools"),
and => the_developer_sees_(@"add-service\s+Add a service."),
and => the_developer_sees_(@"check-service\s+Check a service in the current target."),
and => the_developer_sees_(@"list-services\s+List available service types."),
and => the_developer_sees_(@"list-targets\s+List available target environments."),
and => the_developer_sees_(@"remove-service\s+Remove a service."),
and => the_developer_sees_(@"set-target\s+Set the target environment."),
and => the_developer_sees_(@"start-service\s+Start a service in the current target."),
and => the_developer_sees_(@"stop-service\s+Stop a service in the current target.")
);
}
[Scenario]
public void MainNoArgs()
{
Runner.RunScenario(
given => a_dotnet_project("main_no_args"),
when => the_developer_runs_steeltoe_(""),
then => the_command_succeeds()
);
}
}
}

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

@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="..\..\versions.props" />
<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="LightBDD.XUnit2" Version="$(LightBDDXUnit2Version)" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="$(TestSdkVersion)" />
<PackageReference Include="Shouldly" Version="$(ShouldlyVersion)" />
<PackageReference Include="xunit" Version="$(XunitVersion)" />
<PackageReference Include="xunit.runner.visualstudio" Version="$(XunitStudioVersion)" />
<DotNetCliToolReference Include="dotnet-xunit" Version="$(XunitVersion)" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Steeltoe.Tooling.DotnetCli.Base.Feature\Steeltoe.Tooling.DotnetCli.Base.Feature.csproj" />
</ItemGroup>
</Project>

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

@ -70,10 +70,10 @@ namespace Steeltoe.Tooling.DotnetCli.Service.Feature
}
[Scenario]
public void AddUnknownService()
public void AddUnknownServiceType()
{
Runner.RunScenario(
given => a_dotnet_project("add_unknown_service"),
given => a_dotnet_project("add_unknown_service_type"),
when => the_developer_runs_steeltoe_("add-service foo -s no-such-type"),
then => the_command_fails(),
and => the_developer_sees_the_error_("Unknown service type 'no-such-type'")
@ -85,10 +85,12 @@ namespace Steeltoe.Tooling.DotnetCli.Service.Feature
{
Runner.RunScenario(
given => a_dotnet_project("add_cloud_foundry_config_server_service"),
and => a_target("keep-this-target"),
when => the_developer_runs_steeltoe_("add-service MyConfigServer -s cloud-foundry-config-server"),
then => the_command_succeeds(),
and => the_developer_sees_("Added cloud-foundry-config-server service 'MyConfigServer'"),
and => the_tooling_config_defines_the_service_("MyConfigServer", "cloud-foundry-config-server")
and => the_tooling_config_defines_the_service_("MyConfigServer", "cloud-foundry-config-server"),
and => the_target_exists("keep-this-target")
);
}
}

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

@ -0,0 +1,98 @@
// 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
//
// http://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;
using LightBDD.Framework.Scenarios.Extended;
using LightBDD.XUnit2;
using Steeltoe.Tooling.DotnetCli.Base.Feature;
namespace Steeltoe.Tooling.DotnetCli.Service.Feature
{
[Label("service")]
public class UndefineServiceFeature : DotnetCliFeatureSpecs
{
[Scenario]
[Label("help")]
public void RemoveServiceHelp()
{
Runner.RunScenario(
given => a_dotnet_project("remove_service_help"),
when => the_developer_runs_steeltoe_("remove-service --help"),
then => the_command_succeeds(),
and => the_developer_sees_("Remove a service from the target environment."),
and => the_developer_sees_(@"name\s+The service name")
);
}
[Scenario]
public void RemoveServiceNotEnoughArgs()
{
Runner.RunScenario(
given => a_dotnet_project("remove_service_not_enough_args"),
when => the_developer_runs_steeltoe_("remove-service"),
then => the_command_fails(),
and => the_developer_sees_the_error_("Service name not specified")
);
}
[Scenario]
public void RemoveServiceTooManyArgs()
{
Runner.RunScenario(
given => a_dotnet_project("remove_service_too_many_args"),
when => the_developer_runs_steeltoe_("remove-service arg1 arg2"),
then => the_command_fails(),
and => the_developer_sees_the_error_("Unrecognized command or argument 'arg2'")
);
}
[Scenario]
public void RemoveServiceWithoutToolingConfiguration()
{
Runner.RunScenario(
given => a_dotnet_project("remove_service_without_tooling_configuration"),
when => the_developer_runs_steeltoe_("remove-service unknown-service"),
then => the_command_fails(),
and => the_developer_sees_the_error_("No such service 'unknown-service'")
);
}
[Scenario]
public void RemoveUnknownService()
{
Runner.RunScenario(
given => a_dotnet_project("remove_unknown_service"),
and => a_service_named_("known-service"),
when => the_developer_runs_steeltoe_("remove-service unknown-service"),
then => the_command_fails(),
and => the_developer_sees_the_error_("No such service 'unknown-service'")
);
}
[Scenario]
public void RemoveKnownService()
{
Runner.RunScenario(
given => a_dotnet_project("remove_known_service"),
and => a_target("keep-this-target"),
and => a_service_named_("known-service"),
when => the_developer_runs_steeltoe_("remove-service known-service"),
then => the_command_succeeds(),
and => the_developer_sees_("Removed service 'known-service'"),
and => the_service_does_not_exist("known-service"),
and => the_target_exists("keep-this-target")
);
}
}
}

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

@ -1,35 +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
//
// http://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;
using LightBDD.Framework.Scenarios.Extended;
using LightBDD.XUnit2;
using Steeltoe.Tooling.DotnetCli.Base.Feature;
namespace Steeltoe.Tooling.DotnetCli.Service.Feature
{
[Label("service")]
public class UndefineServiceFeature : DotnetCliFeatureSpecs
{
[Scenario]
public void RunUndefineNoArgs()
{
Runner.RunScenario(
given => a_dotnet_project("undefine_no_args"),
when => the_developer_runs_steeltoe_("undefine-service"),
then => the_command_succeeds()
);
}
}
}

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

@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.IO;
using YamlDotNet.Serialization;
@ -47,6 +48,15 @@ namespace Steeltoe.Tooling.Base
public class Service
{
public string type { get; set; }
public Service()
{
}
public Service(string type)
{
this.type = type;
}
}
}
}

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

@ -27,6 +27,7 @@ namespace Steeltoe.Tooling.DotnetCli.Base
}
catch (Exception e)
{
// app.Error.WriteLine(e);
app.Error.WriteLine(e.Message);
return 1;
}

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

@ -12,13 +12,14 @@
// See the License for the specific language governing permissions and
// limitations under the License.
using System.IO;
using McMaster.Extensions.CommandLineUtils;
using Steeltoe.Tooling.Base;
using Steeltoe.Tooling.DotnetCli.Base;
namespace Steeltoe.Tooling.DotnetCli.Service
{
[Command(Description = "Add a service to the target environment.")]
[Command(Description = "Add a service.")]
public class AddServiceCommand : DotnetCliCommand
{
[Argument(0, Description = "The service name")]
@ -47,10 +48,17 @@ namespace Steeltoe.Tooling.DotnetCli.Service
throw new CommandException($"Unknown service type '{type}'");
}
var cfg = new ToolingConfiguration();
var svc = new ToolingConfiguration.Service();
svc.type = type;
cfg.services.Add(name, svc);
ToolingConfiguration cfg;
try
{
cfg = ToolingConfiguration.Load(".");
}
catch (FileNotFoundException)
{
cfg = new ToolingConfiguration();
}
cfg.services.Add(name, new ToolingConfiguration.Service(type));
cfg.Store(".");
app.Out.WriteLine($"Added {type} service '{name}'");
}

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

@ -0,0 +1,54 @@
// 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
//
// http://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 McMaster.Extensions.CommandLineUtils;
using Steeltoe.Tooling.Base;
using Steeltoe.Tooling.DotnetCli.Base;
namespace Steeltoe.Tooling.DotnetCli.Service
{
[Command(Description = "Remove a service.")]
public class RemoveServiceCommand : DotnetCliCommand
{
[Argument(0, Description = "The service name")]
private string name { get; }
protected override void OnCommandExecute(CommandLineApplication app)
{
if (string.IsNullOrEmpty(name))
{
throw new UsageException("Service name not specified");
}
try
{
var cfg = ToolingConfiguration.Load(".");
if (cfg.services.ContainsKey(name))
{
cfg.services.Remove(name);
cfg.Store(".");
app.Out.WriteLine($"Removed service '{name}'");
return;
}
}
catch (FileNotFoundException)
{
// pass
}
throw new CommandException($"No such service '{name}'");
}
}
}

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

@ -1,27 +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
//
// http://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.DotnetCli.Base;
namespace Steeltoe.Tooling.DotnetCli.Service
{
[Command(Description = "Undefine a service.")]
public class UndefineServiceCommand : DotnetCliCommand
{
protected override void OnCommandExecute(CommandLineApplication app)
{
}
}
}

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

@ -18,7 +18,7 @@ namespace Steeltoe.Tooling.DotnetCli
{
[Command(Name = "steeltoe", Description = "Steeltoe Developer Tools")]
[Subcommand("add-service", typeof(Service.AddServiceCommand))]
[Subcommand("undefine-service", typeof(Service.UndefineServiceCommand))]
[Subcommand("remove-service", typeof(Service.RemoveServiceCommand))]
[Subcommand("list-services", typeof(Service.ListServicesCommand))]
[Subcommand("start-service", typeof(Service.StartServiceCommand))]
[Subcommand("stop-service", typeof(Service.StopServiceCommand))]