-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathCloudProjectFixtureBase.cs
More file actions
60 lines (55 loc) Β· 2.38 KB
/
CloudProjectFixtureBase.cs
File metadata and controls
60 lines (55 loc) Β· 2.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
ο»Ώ// Copyright 2020 Google LLC
//
// 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 Xunit;
using Xunit.Sdk;
namespace Google.Cloud.EntityFrameworkCore.Spanner.IntegrationTests
{
/// <summary>
/// Base class for fixtures in integration and snippet tests which rely on Google Cloud projects.
/// </summary>
public abstract class CloudProjectFixtureBase
{
// We don't care about the value beyond whether it's absent/empty or non-empty.
private static readonly bool s_allowedToSkip = string.IsNullOrEmpty(Environment.GetEnvironmentVariable("MUST_NOT_SKIP_TESTS"));
/// <summary>
/// The Google Cloud Project ID to use for tests.
/// </summary>
public string ProjectId { get; }
protected CloudProjectFixtureBase(string testProjectEnvironmentVariable = TestEnvironment.TestProjectEnvironmentVariable)
{
ProjectId = TestEnvironment.GetTestProjectId(testProjectEnvironmentVariable);
}
/// <summary>
/// Like <see cref="Skip.If"/>, but first checks whether or not we're *allowed* to skip tests
/// based on environment variables. The intention is that tests which require elaborate set-up
/// may be skipped for local dev environments if developers aren't working on those features,
/// but should always run in continuous integration - if the environemnt isn't set up appropriately,
/// we should fail.
/// </summary>
/// <param name="condition">The condition under which the test is skipped.</param>
public void SkipIf(bool condition)
{
if (!condition)
{
return;
}
if (!s_allowedToSkip)
{
throw new XunitException("Test is not allowed to be skipped in this environment.");
}
Skip.If(true);
}
}
}