示例#1
0
        public void DetectPdfDocument()
        {
            var           _pdfFileName = "HodgeConj.pdf";
            var           outputPrefix = "";
            var           localPath    = Path.Combine("data", _pdfFileName);
            var           gcsSourceURI = $"gs://{_bucketName}/{_pdfFileName}";
            ConsoleOutput output;

            string[] cmdArgs = { "ocr", gcsSourceURI, _bucketName, outputPrefix };

            using (var collector = new BucketCollector(_bucketName))
            {
                collector.CopyToBucket(localPath, _pdfFileName);
                output = _detect.Run(cmdArgs);

                Assert.Equal(0, output.ExitCode);
                Assert.Contains("Full text:", output.Stdout);
                Assert.Contains("Hodge conjecture", output.Stdout);
            }

            // Clean up output files.
            var storageClient = StorageClient.Create();
            var blobList      = storageClient.ListObjects(_bucketName, "");

            foreach (var outputFile in blobList.Where(x => x.Name.Contains(".json")).Select(x => x.Name))
            {
                storageClient.DeleteObject(_bucketName, outputFile);
            }
        }
        public void TestTriggerList()
        {
            var infoTypes = new InfoType[] { new InfoType {
                                                 Name = "PERSON_NAME"
                                             } };
            var triggerId     = $"my-csharp-test-trigger-{Guid.NewGuid()}";
            var fullTriggerId = $"projects/{Fixture.ProjectId}/jobTriggers/{triggerId}";
            var displayName   = $"My trigger display name {Guid.NewGuid()}";
            var description   = $"My trigger description {Guid.NewGuid()}";

            using var randomBucketFixture = new RandomBucketFixture();
            using var bucketCollector     = new BucketCollector(randomBucketFixture.BucketName);
            var bucketName = randomBucketFixture.BucketName;
            var fileName   = Guid.NewGuid().ToString();
            var objectName = $"gs://{bucketName}/{fileName}";

            bucketCollector.CopyToBucket(Path.Combine(Fixture.ResourcePath, "dates-input.csv"), fileName);
            var trigger = TriggersCreate.Create(Fixture.ProjectId, bucketName, Likelihood.Unlikely, 1, true, 1, infoTypes, triggerId, displayName, description);

            try
            {
                var triggers = TriggersList.List(Fixture.ProjectId);
                Assert.Contains(triggers, t => t.Name == trigger.Name);
            }
            finally
            {
                TriggersDelete.Delete(trigger.Name);
            }
        }
示例#3
0
        string Upload(string localPath)
        {
            string objectName = Path.GetFileName(localPath);
            string gsPath     = $"gs://{_bucketName}/{objectName}";

            _bucketCollector.CopyToBucket(localPath, objectName);
            return(gsPath);
        }
示例#4
0
 protected override ConsoleOutput Run(params string[] args)
 {
     string objectName = "VisionTest/" + Path.GetFileName(args[1]);
     string[] cmdArgs = { args[0], $"gs://{_bucketName}/{objectName}" };
     using (var collector = new BucketCollector(_bucketName))
     {
         collector.CopyToBucket(args[1], objectName);
         return _detect.Run(cmdArgs);
     }
 }
        public void TestDeleteJob()
        {
            using var randomBucketFixture = new RandomBucketFixture();
            using var bucketCollector     = new BucketCollector(randomBucketFixture.BucketName);
            var bucketName = randomBucketFixture.BucketName;
            var fileName   = Guid.NewGuid().ToString();
            var objectName = $"gs://{bucketName}/{fileName}";

            bucketCollector.CopyToBucket(Path.Combine(Fixture.ResourcePath, "dates-input.csv"), fileName);
            var job = JobsCreate.CreateJob(Fixture.ProjectId, objectName);

            JobsDelete.DeleteJob(job.Name);
            var activeJobs = JobsList.ListDlpJobs(Fixture.ProjectId, "state = RUNNING", DlpJobType.InspectJob);

            Assert.DoesNotContain(activeJobs, j => j.Name == job.Name);
        }
示例#6
0
        public void TestCreateDlpJob()
        {
            using var randomBucketFixture = new RandomBucketFixture();
            using var bucketCollector     = new BucketCollector(randomBucketFixture.BucketName);
            var bucketName = randomBucketFixture.BucketName;
            var fileName   = Guid.NewGuid().ToString();
            var objectName = $"gs://{bucketName}/{fileName}";

            bucketCollector.CopyToBucket(Path.Combine(Fixture.ResourcePath, "dates-input.csv"), fileName);
            var job = JobsCreate.CreateJob(Fixture.ProjectId, objectName);

            TestRetryRobot.ShouldRetry = ex => true;
            TestRetryRobot.Eventually(() =>
            {
                var response = JobsList.ListDlpJobs(Fixture.ProjectId, "state=DONE", "InspectJob");

                Assert.True(response.Any());
            });
        }