public void CanGetLocalCacheKeyFromRepoInfo() { List <string> repoIds = new List <string> { "df3216c6-6d33-476e-8d89-e877a6d74c79", "testId", "826847f5da3ef78114b2a9d5253ada9d95265c76" }; MockTracer tracer = new MockTracer(); MockScalarEnlistment enlistment = CreateEnlistment("mock://repoUrl"); LocalCacheResolver localCacheResolver = new LocalCacheResolver(enlistment); foreach (string repoId in repoIds) { VstsInfoData vstsInfo = new VstsInfoData(); vstsInfo.Repository = new VstsInfoData.RepositoryDetails(); vstsInfo.Repository.Id = repoId; localCacheResolver.TryGetLocalCacheKeyFromRepoInfoOrURL( tracer, vstsInfo, out string localCacheKey, out string errorMessage).ShouldBeTrue(); errorMessage.ShouldBeEmpty(); localCacheKey.ShouldEqual($"{RepoIdKeyPrefix}{repoId}"); } }
private bool TryDetermineLocalCacheAndInitializePaths(string localCacheRoot, out string errorMessage) { errorMessage = null; LocalCacheResolver localCacheResolver = new LocalCacheResolver(this.enlistment); VstsInfoData vstsInfo = this.QueryVstsInfo(this.tracer, this.enlistment, this.retryConfig); string error; string localCacheKey; if (!localCacheResolver.TryGetLocalCacheKeyFromRepoInfoOrURL( this.tracer, vstsInfo, localCacheKey: out localCacheKey, errorMessage: out error)) { errorMessage = "Error determining local cache key: " + error; return(false); } EventMetadata metadata = this.CreateEventMetadata(); metadata.Add("localCacheRoot", localCacheRoot); metadata.Add("localCacheKey", localCacheKey); metadata.Add(TracingConstants.MessageKey.InfoMessage, "Initializing cache paths"); this.tracer.RelatedEvent(EventLevel.Informational, "CloneVerb_TryDetermineLocalCacheAndInitializePaths", metadata); this.enlistment.InitializeCachePathsFromKey(localCacheRoot, localCacheKey); return(true); }
private static void LocalKeyShouldBeResolvedFromURL(LocalCacheResolver localCacheResolver, VstsInfoData vstsInfo, out string localCacheKey) { localCacheResolver.TryGetLocalCacheKeyFromRepoInfoOrURL( new MockTracer(), vstsInfo, out localCacheKey, out string errorMessage).ShouldBeTrue(); errorMessage.ShouldBeEmpty(); localCacheKey.Substring(0, UrlKeyPrefix.Length).ShouldEqual(UrlKeyPrefix); SHA1Util.IsValidShaFormat(localCacheKey.Substring(UrlKeyPrefix.Length)).ShouldBeTrue(); }