public void WhenLicenseHasNoByolSuffix_ThenIsWindowsByolLicenseReturnsFalse() { var locator = LicenseLocator.FromString( "projects/windows-cloud/global/licenses/windows-2016"); Assert.IsFalse(locator.IsWindowsByolLicense()); }
public void WhenLicenseHasByolSuffix_ThenIsWindowsByolLicenseReturnsTrue() { var locator = LicenseLocator.FromString( "https://www.googleapis.com/compute/v1/projects/windows-cloud/global/licenses/windows-10-enterprise-byol"); Assert.IsTrue(locator.IsWindowsByolLicense()); }
public void WhenLicenseIsNotFromWindowsCloud_ThenIsWindowsLicenseReturnsFalse() { var locator = LicenseLocator.FromString( "projects/my-project/global/licenses/windows-10-enterprise-byol"); Assert.IsFalse(locator.IsWindowsLicense()); }
public void WhenCreatedFromPath_ThenToStringReturnsPath() { var path = "projects/project-1/global/licenses/windows-10-enterprise-byol"; Assert.AreEqual( path, LicenseLocator.FromString(path).ToString()); }
public void WhenPathInvalid_FromStringThrowsArgumentException() { Assert.Throws <ArgumentException>(() => LicenseLocator.FromString( "projects/project-1/notglobal/licenses/windows-10-enterprise-byol")); Assert.Throws <ArgumentException>(() => LicenseLocator.FromString( "/project-1/global/licenses/windows-10-enterprise-byol")); Assert.Throws <ArgumentException>(() => LicenseLocator.FromString( "/")); }
public void WhenQualifiedByGoogleapisHost_FromStringReturnsObject() { var ref1 = LicenseLocator.FromString( "https://www.googleapis.com/compute/v1/projects/windows-cloud/global/licenses/windows-10-enterprise-byol"); Assert.AreEqual("licenses", ref1.ResourceType); Assert.AreEqual("windows-10-enterprise-byol", ref1.Name); Assert.AreEqual("windows-cloud", ref1.ProjectId); }
public void WhenPathIsValid_FromStringReturnsObject() { var ref1 = LicenseLocator.FromString( "projects/project-1/global/licenses/windows-10-enterprise-byol"); Assert.AreEqual("licenses", ref1.ResourceType); Assert.AreEqual("windows-10-enterprise-byol", ref1.Name); Assert.AreEqual("project-1", ref1.ProjectId); }
public void WhenCreatedFromUrl_ThenToStringReturnsPath() { var path = "projects/project-1/global/licenses/windows-10-enterprise-byol"; Assert.AreEqual( path, LicenseLocator.FromString( "https://www.googleapis.com/compute/v1/" + path).ToString()); }
private static bool IsWindowsInstanceByLicense(Instance instance) { // For an instance to be a valid Windows instance, at least one of the disks // has to have an associated Windows license. This is also true for // BYOL'ed instances. return(instance.Disks .EnsureNotNull() .Where(d => d.Licenses != null) .SelectMany(d => d.Licenses) .EnsureNotNull() .Any(l => LicenseLocator.FromString(l).IsWindowsLicense())); }
private static LicenseLocator TryGetRelevantLicenseFromImage(Image imageInfo) { var locators = imageInfo.Licenses .EnsureNotNull() .Select(license => LicenseLocator.FromString(license)); // Images can contain more than one license, and liceses like // "/compute/v1/projects/compute-image-tools/global/licenses/virtual-disk-import" // are not helpful here. So do some filtering. if (locators.FirstOrDefault(l => l.IsWindowsByolLicense()) is LicenseLocator byolLocator) { return(byolLocator); } else if (locators.FirstOrDefault(l => l.IsWindowsLicense()) is LicenseLocator winLocator) { return(winLocator); } else { return(locators.FirstOrDefault()); } }