public void GetData_ReturnsCorrectDataBasedOnEnvironment()
        {
            Environment.SetEnvironmentVariable("COVERALLS_REPO_TOKEN", "1234abcd");
            Environment.SetEnvironmentVariable("JENKINS_HOME", "True");
            Environment.SetEnvironmentVariable("BUILD_NUMBER", "23");

            var opts      = Substitute.For <ICommandOptions>();
            var coveralls = new CoverallsBootstrap(opts);

            coveralls.FileSystem = Stub.LocalFileSystem();

            var data = coveralls.GetData();

            data.ServiceName.Should().Be("jenkins");
            data.ServiceJobId.Should().Be("23");
            data.RepoToken.Should().Be("1234abcd");
        }
示例#2
0
        internal static void Run(CommandLineOptions options)
        {
            if (options.DebugMode)
            {
                Console.WriteLine(Resources.RepoTokenDebug, Environment.GetEnvironmentVariable("COVERALLS_REPO_TOKEN"));
            }

            using (var coveralls = new CoverallsBootstrap(options))
            {
                coveralls.FileSystem = new LocalFileSystem();

                if (!coveralls.CoverageFiles.Any())
                {
                    Console.WriteLine(Resources.NoCoverageFilesErrorMessage);
                    return;
                }

                if (coveralls.RepoToken.IsBlank())
                {
                    Console.WriteLine(Resources.BlankTokenErrorMessage);

                    if (coveralls.ServiceName == "appveyor")
                    {
                        Console.Write(Resources.AppVeyorBlankToken);
                    }
                    return;
                }

                foreach (var file in coveralls.CoverageFiles)
                {
                    file.Path = file.Path.ToRelativePath(Directory.GetCurrentDirectory());
                }

                var coverallsData = coveralls.GetData();
                var json = JsonConvert.SerializeObject(coverallsData);
                SendToCoveralls(json);

                if (options.DebugMode)
                {
                    Console.WriteLine(Resources.CoverallsJsonHeader, JsonPrettyPrint(json));
                }
            }
        }
示例#3
0
        internal static void Run(CommandLineOptions options)
        {
            if (options.DebugMode)
            {
                Console.WriteLine(Resources.RepoTokenDebug, Environment.GetEnvironmentVariable("COVERALLS_REPO_TOKEN"));
            }

            using (var coveralls = new CoverallsBootstrap(options))
            {
                coveralls.FileSystem = new LocalFileSystem();

                if (!coveralls.CoverageFiles.Any())
                {
                    Console.WriteLine(Resources.NoCoverageFilesErrorMessage);
                    return;
                }

                if (coveralls.RepoToken.IsBlank())
                {
                    Console.WriteLine(Resources.BlankTokenErrorMessage);

                    if (coveralls.ServiceName == "appveyor")
                    {
                        Console.Write(Resources.AppVeyorBlankToken);
                    }
                    return;
                }

                foreach (var file in coveralls.CoverageFiles)
                {
                    file.Path = file.Path.ToRelativePath(Directory.GetCurrentDirectory());
                }

                var coverallsData = coveralls.GetData();
                var json          = JsonConvert.SerializeObject(coverallsData);
                SendToCoveralls(json);

                if (options.DebugMode)
                {
                    Console.WriteLine(Resources.CoverallsJsonHeader, JsonPrettyPrint(json));
                }
            }
        }