Finishes initial implementation of list-services and list-service-types

This commit is contained in:
Chris Cheetham 2018-08-16 10:44:06 -04:00
Родитель bd79b80cf3
Коммит 0ab53417c3
9 изменённых файлов: 117 добавлений и 10 удалений

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

@ -57,11 +57,11 @@ namespace Steeltoe.Tooling.DotnetCli.Feature
cfg.Store(ProjectDirectory);
}
protected void a_service(string name)
protected void a_service(string name, string type)
{
Logger.LogInformation($"rigging a service '{name}'");
var cfg = GetProjectConfiguration();
cfg.services.Add(name, new ToolingConfiguration.Service("foo-type"));
cfg.services.Add(name, new ToolingConfiguration.Service(type));
cfg.Store(ProjectDirectory);
}

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

@ -32,7 +32,8 @@ namespace Steeltoe.Tooling.DotnetCli.Feature
and => the_developer_should_see("Steeltoe Developer Tools"),
and => the_developer_should_see(@"add-service\s+Add a service."),
and => the_developer_should_see(@"check-service\s+Check a service in the current target."),
and => the_developer_should_see(@"list-services\s+List available service types."),
and => the_developer_should_see(@"list-service-types\s+List available service types."),
and => the_developer_should_see(@"list-services\s+List available services."),
and => the_developer_should_see(@"list-targets\s+List available target environments."),
and => the_developer_should_see(@"remove-service\s+Remove a service."),
and => the_developer_should_see(@"set-target\s+Set the target environment."),

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

@ -0,0 +1,58 @@
// 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;
namespace Steeltoe.Tooling.DotnetCli.Feature.Service
{
[Label("service")]
public class ListServiceTypesFeature : DotnetCliFeatureSpecs
{
[Scenario]
[Label("help")]
public void ListServiceTypesHelp()
{
Runner.RunScenario(
given => a_dotnet_project("list_service_types_help"),
when => the_developer_runs_steeltoe_command("list-service-types --help"),
then => the_command_should_succeed(),
and => the_developer_should_see("List available service types.")
);
}
[Scenario]
public void ListServiceTypes()
{
Runner.RunScenario(
given => a_dotnet_project("list_service_types"),
when => the_developer_runs_steeltoe_command("list-service-types"),
then => the_command_should_succeed(),
and => the_developer_should_see("cloud-foundry-config-server")
);
}
[Scenario]
public void ListServiceTypesTooManyArgs()
{
Runner.RunScenario(
given => a_dotnet_project("list_service_types_too_many_args"),
when => the_developer_runs_steeltoe_command("list-service-types arg1"),
then => the_command_should_fail(),
and => the_developer_should_see_the_error("Unrecognized command or argument 'arg1'")
);
}
}
}

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

@ -29,7 +29,7 @@ namespace Steeltoe.Tooling.DotnetCli.Feature.Service
given => a_dotnet_project("list_services_help"),
when => the_developer_runs_steeltoe_command("list-services --help"),
then => the_command_should_succeed(),
and => the_developer_should_see("List available service types.")
and => the_developer_should_see("List available services.")
);
}
@ -40,7 +40,12 @@ namespace Steeltoe.Tooling.DotnetCli.Feature.Service
given => a_dotnet_project("list_services"),
when => the_developer_runs_steeltoe_command("list-services"),
then => the_command_should_succeed(),
and => the_developer_should_see("cloud-foundry-config-server")
and => the_developer_should_see(""),
given => a_service("service-z", "service-type-Z"),
and => a_service("service-a", "service-type-A"),
when => the_developer_runs_steeltoe_command("list-services"),
then => the_command_should_succeed(),
and => the_developer_should_see(@"service-a\s+\(service-type-A\)\s+service-z\s\(service-type-Z\)")
);
}

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

@ -72,7 +72,7 @@ namespace Steeltoe.Tooling.DotnetCli.Feature.Service
{
Runner.RunScenario(
given => a_dotnet_project("remove_unknown_service"),
and => a_service("known-service"),
and => a_service("known-service", "known-service-type"),
when => the_developer_runs_steeltoe_command("remove-service unknown-service"),
then => the_command_should_fail(),
and => the_developer_should_see_the_error("No such service 'unknown-service'")
@ -85,7 +85,7 @@ namespace Steeltoe.Tooling.DotnetCli.Feature.Service
Runner.RunScenario(
given => a_dotnet_project("remove_known_service"),
and => a_target("keep-this-target"),
and => a_service("known-service"),
and => a_service("known-service", "known-service-type"),
when => the_developer_runs_steeltoe_command("remove-service known-service"),
then => the_command_should_succeed(),
and => the_developer_should_see("Removed service 'known-service'"),

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

@ -20,6 +20,7 @@ namespace Steeltoe.Tooling.DotnetCli
[Subcommand("add-service", typeof(Service.AddServiceCommand))]
[Subcommand("remove-service", typeof(Service.RemoveServiceCommand))]
[Subcommand("list-services", typeof(Service.ListServicesCommand))]
[Subcommand("list-service-types", typeof(Service.ListServiceTypesCommand))]
[Subcommand("start-service", typeof(Service.StartServiceCommand))]
[Subcommand("stop-service", typeof(Service.StopServiceCommand))]
[Subcommand("check-service", typeof(Service.CheckServiceCommand))]

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

@ -0,0 +1,30 @@
// 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;
// ReSharper disable UnassignedGetOnlyAutoProperty
// ReSharper disable InconsistentNaming
namespace Steeltoe.Tooling.DotnetCli.Service
{
[Command(Description = "List available service types.")]
public class ListServiceTypesCommand : DotnetCliCommand
{
protected override void OnCommandExecute(CommandLineApplication app)
{
app.Out.WriteLine("cloud-foundry-config-server");
}
}
}

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

@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
using System.IO;
using McMaster.Extensions.CommandLineUtils;
// ReSharper disable UnassignedGetOnlyAutoProperty
@ -19,12 +20,23 @@ using McMaster.Extensions.CommandLineUtils;
namespace Steeltoe.Tooling.DotnetCli.Service
{
[Command(Description = "List available service types.")]
[Command(Description = "List available services.")]
public class ListServicesCommand : DotnetCliCommand
{
protected override void OnCommandExecute(CommandLineApplication app)
{
app.Out.WriteLine("cloud-foundry-config-server");
try
{
var cfg = ToolingConfiguration.Load(".");
foreach (var entry in cfg.services)
{
app.Out.WriteLine($"{entry.Key} ({entry.Value.type})");
}
}
catch (FileNotFoundException)
{
// pass
}
}
}
}

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

@ -12,7 +12,7 @@ namespace Steeltoe.Tooling.DotnetCli
public string target { get; set; }
public Dictionary<string, Service> services { get; set; } = new Dictionary<string, Service>();
public SortedDictionary<string, Service> services { get; set; } = new SortedDictionary<string, Service>();
public static ToolingConfiguration Load(string path)
{