Skip to content

Commit

Permalink
Address review: Use the universe domain to build service endpoints.
Browse files Browse the repository at this point in the history
  • Loading branch information
amanda-tarafa committed Jan 30, 2024
1 parent 8ad3b05 commit a762790
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,82 +10,81 @@
using System.Threading.Tasks;
using Xunit;

namespace Google.Api.Gax.Grpc.Tests
namespace Google.Api.Gax.Grpc.Tests;

public partial class ClientBuilderBaseTest
{
public partial class ClientBuilderBaseTest
public class GetEffectiveEndpointTest
{
public class GetEffectiveEndpointTest
{
private const string DefaultUniverseDomain = "googleapis.com";
private const string CustomUniverseDomain = "custom.domain.com";
private const string DefaultEndpointAtDefaultDomain = "service1.googleapis.com";
private const string DefaultEndpointNotAtDefaultDomain = "service1";
private const string EffectiveEndpointAtCustomUniverseDomain = "service1.custom.domain.com";

public static TheoryData<string, string, string> EffectiveEndpointWillHaveValue =>
new TheoryData<string, string, string>
{
// default endpoint, universe domain, expected effective endpoint
{ DefaultEndpointAtDefaultDomain, null, DefaultEndpointAtDefaultDomain},
{ DefaultEndpointAtDefaultDomain, DefaultUniverseDomain, DefaultEndpointAtDefaultDomain},
{ DefaultEndpointAtDefaultDomain, DefaultUniverseDomain, DefaultEndpointAtDefaultDomain},
{ DefaultEndpointAtDefaultDomain, CustomUniverseDomain, EffectiveEndpointAtCustomUniverseDomain},
{ DefaultEndpointNotAtDefaultDomain, null, DefaultEndpointNotAtDefaultDomain},
{ DefaultEndpointNotAtDefaultDomain, DefaultUniverseDomain, DefaultEndpointNotAtDefaultDomain},
};
private const string DefaultUniverseDomain = "googleapis.com";
private const string CustomUniverseDomain = "custom.domain.com";
private const string DefaultEndpointAtDefaultDomain = "service1.googleapis.com";
private const string DefaultEndpointNotAtDefaultDomain = "service1";
private const string EffectiveEndpointAtCustomUniverseDomain = "service1.custom.domain.com";

public static TheoryData<string, string> EffectiveEndpointWillBeNull =>
new TheoryData<string, string>
{
// default endpoint, universe domain
{ null, null},
{ null, DefaultUniverseDomain },
{ null, CustomUniverseDomain },
{ DefaultEndpointNotAtDefaultDomain, CustomUniverseDomain }
};
public static TheoryData<string, string, string> EffectiveEndpointWillHaveValue =>
new TheoryData<string, string, string>
{
// Default endpoint, universe domain, expected effective endpoint
{ DefaultEndpointAtDefaultDomain, null, DefaultEndpointAtDefaultDomain},
{ DefaultEndpointAtDefaultDomain, DefaultUniverseDomain, DefaultEndpointAtDefaultDomain},
{ DefaultEndpointAtDefaultDomain, DefaultUniverseDomain, DefaultEndpointAtDefaultDomain},
{ DefaultEndpointAtDefaultDomain, CustomUniverseDomain, EffectiveEndpointAtCustomUniverseDomain},
{ DefaultEndpointNotAtDefaultDomain, null, DefaultEndpointNotAtDefaultDomain},
{ DefaultEndpointNotAtDefaultDomain, DefaultUniverseDomain, DefaultEndpointNotAtDefaultDomain},
};

[Theory]
[MemberData(nameof(EffectiveEndpointWillHaveValue))]
public void EffectiveEndpoint_HasValue(string defaultEndpoint, string universeDomain, string expectedEffectiveEndpoint)
public static TheoryData<string, string> EffectiveEndpointWillBeNull =>
new TheoryData<string, string>
{
FakeClientBuilder clientBuilder = new FakeClientBuilder(TestServiceMetadata.TestService.WithDefaultEndpoint(defaultEndpoint))
{
UniverseDomain = universeDomain,
};
Assert.Equal(expectedEffectiveEndpoint, clientBuilder.GetEffectiveEndpoint());
clientBuilder.Validate();
}
// Default endpoint, universe domain
{ null, null},
{ null, DefaultUniverseDomain },
{ null, CustomUniverseDomain },
{ DefaultEndpointNotAtDefaultDomain, CustomUniverseDomain }
};

[Theory]
[MemberData(nameof(EffectiveEndpointWillBeNull))]
public void EffectiveEndpoint_IsNull(string defaultEndpoint, string universeDomain)
[Theory]
[MemberData(nameof(EffectiveEndpointWillHaveValue))]
public void EffectiveEndpoint_HasValue(string defaultEndpoint, string universeDomain, string expectedEffectiveEndpoint)
{
FakeClientBuilder clientBuilder = new FakeClientBuilder(TestServiceMetadata.TestService.WithDefaultEndpoint(defaultEndpoint))
{
FakeClientBuilder clientBuilder = new FakeClientBuilder(TestServiceMetadata.TestService.WithDefaultEndpoint(defaultEndpoint))
{
UniverseDomain = universeDomain,
};
Assert.Null(clientBuilder.GetEffectiveEndpoint());
clientBuilder.Validate();
}
UniverseDomain = universeDomain,
};
Assert.Equal(expectedEffectiveEndpoint, clientBuilder.GetEffectiveEndpoint());
clientBuilder.Validate();
}

public class FakeClientBuilder : ClientBuilderBase<string>
[Theory]
[MemberData(nameof(EffectiveEndpointWillBeNull))]
public void EffectiveEndpoint_IsNull(string defaultEndpoint, string universeDomain)
{
FakeClientBuilder clientBuilder = new FakeClientBuilder(TestServiceMetadata.TestService.WithDefaultEndpoint(defaultEndpoint))
{
public FakeClientBuilder(ServiceMetadata serviceMetadata) : base(serviceMetadata)
{ }
UniverseDomain = universeDomain,
};
Assert.Null(clientBuilder.GetEffectiveEndpoint());
clientBuilder.Validate();
}

public class FakeClientBuilder : ClientBuilderBase<string>
{
public FakeClientBuilder(ServiceMetadata serviceMetadata) : base(serviceMetadata)
{ }

public override string Build() =>
throw new NotImplementedException();
public override string Build() =>
throw new NotImplementedException();

public override Task<string> BuildAsync(CancellationToken cancellationToken = default) =>
throw new NotImplementedException();
public override Task<string> BuildAsync(CancellationToken cancellationToken = default) =>
throw new NotImplementedException();

protected override ChannelPool GetChannelPool() =>
throw new NotImplementedException();
protected override ChannelPool GetChannelPool() =>
throw new NotImplementedException();

public new void Validate() => base.Validate();
public new void Validate() => base.Validate();

public new string GetEffectiveEndpoint() => base.GetEffectiveEndpoint();
}
public new string GetEffectiveEndpoint() => base.GetEffectiveEndpoint();
}
}
}
5 changes: 3 additions & 2 deletions Google.Api.Gax.Grpc/ServiceMetadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ public sealed class ServiceMetadata
public string DefaultEndpoint { get; }

/// <summary>
/// The template to build and endpoint for the service taking into account a custom universe domain.
/// May be null, in which case no universe domain dependant endpoint may be built for the service.
/// The template to build and endpoint for the service taking into account a custom universe domain,
/// for instance "storage.{0}".
/// May be null, in which case no universe domain dependent endpoint may be built for the service.
/// </summary>
public string EndpointTemplate { get; }

Expand Down

0 comments on commit a762790

Please sign in to comment.