-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for recorded tests. #18836
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using System; | ||
using System.Net; | ||
using Azure.Core.TestFramework; | ||
using NUnit.Framework; | ||
|
||
namespace Azure.Iot.ModelsRepository.Tests | ||
{ | ||
public class ModelRepoRecordedTestBase : RecordedTestBase<ModelRepoTestEnvironment> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is only one set of tests that need recording and they are in ResolverIntegrationTests
azabbasi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
protected const string TestModeEnvVariable = "AZURE_TEST_MODE"; | ||
|
||
protected static RecordedTestMode TestMode => (RecordedTestMode)Enum.Parse( | ||
typeof(RecordedTestMode), | ||
Environment.GetEnvironmentVariable(TestModeEnvVariable)); | ||
|
||
public ModelRepoRecordedTestBase(bool isAsync) : base(isAsync, TestMode) | ||
{ | ||
} | ||
|
||
[SetUp] | ||
public virtual void SetupE2eTestBase() | ||
{ | ||
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; | ||
} | ||
|
||
protected ResolverClient GetClient(ModelRepoTestBase.ClientType clientType, ResolverClientOptions options = null) | ||
{ | ||
if (options == null) | ||
{ | ||
options = new ResolverClientOptions(); | ||
} | ||
|
||
return | ||
clientType == ModelRepoTestBase.ClientType.Local | ||
? InstrumentClient( | ||
new ResolverClient( | ||
new Uri(ModelRepoTestBase.TestLocalModelRepository), | ||
InstrumentClientOptions(options))) | ||
: InstrumentClient( | ||
new ResolverClient( | ||
new Uri(ModelRepoTestBase.TestRemoteModelRepository), | ||
InstrumentClientOptions(options))); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,14 +8,13 @@ | |
|
||
namespace Azure.Iot.ModelsRepository.Tests | ||
{ | ||
public class TestHelpers | ||
/// <summary> | ||
/// This class will initialize all the settings and create and instance of the ResolverClient client. | ||
/// </summary> | ||
public abstract class ModelRepoTestBase | ||
{ | ||
private static readonly string s_fallbackTestRemoteRepo = "https://devicemodels.azure.com/"; | ||
|
||
public enum ClientType | ||
public ModelRepoTestBase() | ||
{ | ||
Local, | ||
Remote | ||
} | ||
|
||
public static string ParseRootDtmiFromJson(string json) | ||
|
@@ -33,30 +32,18 @@ public static string ParseRootDtmiFromJson(string json) | |
return dtmi; | ||
} | ||
|
||
public static ResolverClient GetTestClient(ClientType clientType, ResolverClientOptions clientOptions = null) | ||
{ | ||
if (clientOptions == null) | ||
{ | ||
clientOptions = new ResolverClientOptions(); | ||
} | ||
|
||
if (clientType == ClientType.Local) | ||
{ | ||
return new ResolverClient(TestLocalModelRepository, clientOptions); | ||
} | ||
|
||
if (clientType == ClientType.Remote) | ||
{ | ||
return new ResolverClient(TestRemoteModelRepository, clientOptions); | ||
} | ||
|
||
throw new ArgumentException(); | ||
} | ||
public static readonly string FallbackTestRemoteRepo = ModelRepositoryConstants.DefaultModelsRepository; | ||
|
||
public static string TestDirectoryPath => Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); | ||
|
||
public static string TestLocalModelRepository => Path.Combine(TestDirectoryPath, "TestModelRepo"); | ||
|
||
public static string TestRemoteModelRepository => Environment.GetEnvironmentVariable("PNP_TEST_REMOTE_REPO") ?? s_fallbackTestRemoteRepo; | ||
public static string TestRemoteModelRepository => Environment.GetEnvironmentVariable("PNP_TEST_REMOTE_REPO") ?? FallbackTestRemoteRepo; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since there is no resources to be deployed, I would like to change this value to be straight up the FallbackTestRemoteRepo, unless anyone sees value in having a repo stored in an environment variable. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FallbackTestRemoteRepo is actually the default repo so we can even get rid of that. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The historical purpose of the env var was to support running remote tests on non prod model repos, for example testing against a forked repo or a test endpoint https://devicemodeltest.azureedge.net/ |
||
|
||
public enum ClientType | ||
{ | ||
Local, | ||
Remote | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using Azure.Core.TestFramework; | ||
|
||
namespace Azure.Iot.ModelsRepository.Tests | ||
{ | ||
public class ModelRepoTestEnvironment : TestEnvironment | ||
{ | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since there is no resource provider for the SDK, I used the same namespace as the project. I will verify that with SDK team