• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

xoofx / dotnet-releaser / 6118666224

08 Sep 2023 06:53AM UTC coverage: 24.087%. Remained the same
6118666224

push

github

xoofx
Add better message for `Connecting To GitHub` to differentiate GitHub tokens

627 of 1511 branches covered (0.0%)

Branch coverage included in aggregate %.

7 of 7 new or added lines in 5 files covered. (100.0%)

1819 of 8644 relevant lines covered (21.04%)

39.49 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

82.21
/src/DotNetReleaser.Tests/BasicTests.cs
1
using System;
2
using System.Collections.Generic;
3
using System.IO;
4
using System.Linq;
5
using System.Runtime.InteropServices;
6
using System.Text;
7
using System.Threading.Tasks;
8
using CliWrap;
9
using DotNetReleaser.Configuration;
10
using DotNetReleaser.DevHosting;
11
using DotNetReleaser.Helpers;
12
using NuGet.Versioning;
13
using NUnit.Framework;
14

15
namespace DotNetReleaser.Tests
16
{
17
    public class BasicTests
18
    {
19
        private readonly string _helloWorldFolder = Path.GetFullPath(Path.Combine(AppContext.BaseDirectory, "..", "..", "..", "..", "..", "tests", "HelloWorld"));
1✔
20
        private readonly string _releaserExe = Path.Combine(AppContext.BaseDirectory, RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "dotnet-releaser.exe" : "dotnet-releaser");
1!
21
        private readonly string _configurationFile;
22
        private readonly string _artifactsFolder;
23

24
        public BasicTests()
25
        {
26
            _configurationFile = Path.Combine(_helloWorldFolder, "dotnet-releaser.toml");
1✔
27
            _artifactsFolder = Path.Combine(_helloWorldFolder, "artifacts-dotnet-releaser");
1✔
28
        }
1✔
29
        
30
        [Test]
31
        [Ignore("Only used locally")]
32
        public async Task CheckGitHub()
33
        {
34
            var devHosting = new GitHubDevHostingConfiguration()
×
35
            {
×
36
                User = "xoofx",
×
37
                Repo = "dotnet-releaser",
×
38
                Branches = { "main" }
×
39
            };
×
40

41
            var logger = new MockSimpleLogger();
×
42

43
            var githubHosting = new GitHubDevHosting(logger, devHosting, "TBD", "TBD");
×
44
            var branches = await githubHosting.GetBranchNamesForCommit("xoofx", "dotnet-releaser", "afe9d28493c05d24f16b5ffdac011b73f66e3c5c");
×
45
        }
×
46

47

48
        [Test]
49
        public async Task TestNew()
50
        {
51
            EnsureTestsFolder();
1✔
52
            File.Delete(_configurationFile);
1✔
53
            await CreateConfiguration();
1✔
54
            File.Delete(_configurationFile);
1✔
55
        }
1✔
56

57
        [Test]
58
        public async Task TestBuild()
59
        {
60
            EnsureTestsFolder();
1✔
61

62
            File.Delete(_configurationFile);
1✔
63

64
            await CreateConfiguration();
1✔
65

66
            var config = await File.ReadAllTextAsync(_configurationFile);
1✔
67

68
            if (Directory.Exists(_artifactsFolder))
1!
69
            {
70
                Directory.Delete(_artifactsFolder, true);
×
71
            }
72

73
            config = "profile = \"custom\"" + Environment.NewLine + config;
1✔
74
            config += @"[[pack]]
1✔
75
rid = ""win-x64""
1✔
76
kinds = [""zip""]
1✔
77
[[pack]]
1✔
78
rid = ""linux-x64""
1✔
79
kinds = [""tar"", ""deb""]
1✔
80
";
1✔
81
            config = config.Replace("\r\n", "\n").Replace("\n", Environment.NewLine);
1✔
82
            await File.WriteAllTextAsync(_configurationFile, config);
1✔
83

84
            var resultBuild = await CliWrap.Cli.Wrap(_releaserExe)
1✔
85
                .WithArguments("build --force dotnet-releaser.toml")
1✔
86
                .WithStandardOutputPipe(PipeTarget.ToDelegate(x => Console.Out.WriteLine(x)))
44✔
87
                .WithStandardErrorPipe(PipeTarget.ToDelegate(x => Console.Error.WriteLine(x)))
×
88
                .WithWorkingDirectory(_helloWorldFolder).ExecuteAsync();
1✔
89

90
            Assert.True(Directory.Exists(_artifactsFolder));
1✔
91

92
            var files = Directory.GetFiles(_artifactsFolder).Select(Path.GetFileName).OrderBy(x => x).ToList();
5✔
93

94
            var expectedFiles = new List<string>()
1✔
95
            {
1✔
96
                "HelloWorld.0.1.0.linux-x64.deb",
1✔
97
                "HelloWorld.0.1.0.linux-x64.tar.gz",
1✔
98
                "HelloWorld.0.1.0.nupkg",
1✔
99
                "HelloWorld.0.1.0.win-x64.zip",
1✔
100
            }.OrderBy(x => x).ToList();
5✔
101

102
            foreach (var file in files)
10✔
103
            {
104
                Console.WriteLine($"-> {file}");
4✔
105
            }
106

107
            Assert.AreEqual(expectedFiles, files);
1✔
108

109
            Directory.Delete(_artifactsFolder, true);
1✔
110
            File.Delete(_configurationFile);
1✔
111
        }
1✔
112

113
        [Test]
114
        public async Task TestBuildService()
115
        {
116
            EnsureTestsFolder();
1✔
117

118
            File.Delete(_configurationFile);
1✔
119

120
            await CreateConfiguration();
1✔
121

122
            var config = await File.ReadAllTextAsync(_configurationFile);
1✔
123

124
            if (Directory.Exists(_artifactsFolder))
1!
125
            {
126
                Directory.Delete(_artifactsFolder, true);
×
127
            }
128

129
            config = "profile = \"custom\"" + Environment.NewLine + config;
1✔
130
            config += @"[[pack]]
1✔
131
rid = ""linux-x64""
1✔
132
kinds = [""deb""]
1✔
133
[service]
1✔
134
publish = true
1✔
135
[service.systemd]
1✔
136
arguments = ""/etc/this/is/my/config/file.toml""
1✔
137
[service.systemd.sections.Unit]
1✔
138
After=""network.target""
1✔
139
[[deb.depends]]
1✔
140
name = ""yoyo-runtime""
1✔
141
";
1✔
142
            config = config.Replace("\r\n", "\n").Replace("\n", Environment.NewLine);
1✔
143
            await File.WriteAllTextAsync(_configurationFile, config);
1✔
144

145
            var resultBuild = await CliWrap.Cli.Wrap(_releaserExe)
1✔
146
                .WithArguments("build --force dotnet-releaser.toml")
1✔
147
                .WithStandardOutputPipe(PipeTarget.ToDelegate(x => Console.Out.WriteLine(x)))
40✔
148
                .WithStandardErrorPipe(PipeTarget.ToDelegate(x => Console.Error.WriteLine(x)))
×
149
                .WithWorkingDirectory(_helloWorldFolder).ExecuteAsync();
1✔
150

151
            Assert.True(Directory.Exists(_artifactsFolder));
1✔
152

153
            var debArchive = Path.Combine(_artifactsFolder, "HelloWorld.0.1.0.linux-x64.deb");
1✔
154
            Assert.True(File.Exists(debArchive), $"Missing debian archive {debArchive}");
1✔
155
            
156
            // Check results with dpkg from wsl
157
            if (OperatingSystem.IsWindows())
1!
158
            {
159
                var wrap = await CliWrap.Cli.Wrap("wsl")
×
160
                    .WithArguments(new string[] { "-d", "Ubuntu-20.04", "--", "dpkg", "-x", Path.GetFileName(debArchive), "./tmp" }, true)
×
161
                    .WithWorkingDirectory(_artifactsFolder)
×
162
                    .ExecuteAsync();
×
163
            }
164
            else
165
            {
166
                var wrap = await CliWrap.Cli.Wrap("dpkg")
1✔
167
                    .WithArguments(new string[] { "-x", Path.GetFileName(debArchive), "./tmp" }, true)
1✔
168
                    .WithWorkingDirectory(_artifactsFolder)
1✔
169
                    .ExecuteAsync();
1✔
170
            }
171

172
            var helloWorldService = Path.Combine(_artifactsFolder, @"tmp", "etc", "systemd", "system", "HelloWorld.service");
1✔
173

174
            Assert.True(File.Exists(helloWorldService), $"Missing service file {helloWorldService}");
1✔
175

176
            var serviceContent = Normalize(await File.ReadAllTextAsync(helloWorldService)).Trim();
1✔
177

178
            var expectedContent = Normalize(@"[Unit]
1✔
179
After = network.target
1✔
180
Description = Package Description
1✔
181
StartLimitBurst = 4
1✔
182
StartLimitIntervalSec = 60
1✔
183
[Install]
1✔
184
WantedBy = multi-user.target
1✔
185
[Service]
1✔
186
ExecStart = /usr/local/bin/HelloWorld /etc/this/is/my/config/file.toml
1✔
187
Restart = always
1✔
188
RestartSec = 1
1✔
189
Type = simple
1✔
190
".Trim());
1✔
191
            Console.WriteLine("Service file generated");
1✔
192
            Console.WriteLine("--------------------------------------------");
1✔
193
            Console.WriteLine(serviceContent);
1✔
194
            Console.WriteLine("Service file expected");
1✔
195
            Console.WriteLine("--------------------------------------------");
1✔
196
            Console.WriteLine(expectedContent);
1✔
197

198
            Assert.AreEqual(expectedContent, serviceContent);
1✔
199

200

201
            var packageInfoOutput = new StringBuilder();
1✔
202

203
            // Check Dependencies with dpkg from wsl
204
            if (OperatingSystem.IsWindows())
1!
205
            {
206
                var wrap = await CliWrap.Cli.Wrap("wsl")
×
207
                    .WithArguments(new string[] { "-d", "Ubuntu-20.04", "--", "dpkg", "--info", Path.GetFileName(debArchive)}, true)
×
208
                    .WithWorkingDirectory(_artifactsFolder)
×
209
                    .WithStandardOutputPipe(PipeTarget.ToStringBuilder(packageInfoOutput))
×
210
                    .ExecuteAsync();
×
211
            }
212
            else
213
            {
214
                var wrap = await CliWrap.Cli.Wrap("dpkg")
1✔
215
                    .WithArguments(new string[] { "--info", Path.GetFileName(debArchive)}, true)
1✔
216
                    .WithWorkingDirectory(_artifactsFolder)
1✔
217
                    .WithStandardOutputPipe(PipeTarget.ToStringBuilder(packageInfoOutput))
1✔
218
                    .ExecuteAsync();
1✔
219
            }
220

221
            var packageInfo = packageInfoOutput.ToString();
1✔
222

223
            Console.WriteLine("Package Info");
1✔
224
            Console.WriteLine("--------------------------------------------");
1✔
225
            Console.WriteLine(packageInfo);
1✔
226

227
            StringAssert.Contains("yoyo-runtime", packageInfo, "The package doesn't contain the 'yoyo-runtime' dependency");
1✔
228

229
            Directory.Delete(_artifactsFolder, true);
1✔
230
            File.Delete(_configurationFile);
1✔
231
        }
1✔
232

233
        [TestCase("grpc-curl", "GrpcCurl")]
234
        [TestCase("ThisIsFine", "ThisIsFine")]
235
        [TestCase("this_is_fine", "This_Is_Fine")]
236
        [TestCase("hello_world1", "Hello_World1")]
237
        public void TestHomebrewNaming(string appName, string expected)
238
        {
239
            var className = RubyHelper.GetRubyClassNameFromAppName(appName);
4✔
240
            Assert.AreEqual(expected, className);
4✔
241
        }
4✔
242

243
        private void EnsureTestsFolder()
244
        {
245
            Assert.True(Directory.Exists(_helloWorldFolder), $"The folder `{_helloWorldFolder}` was not found");
3✔
246
        }
3✔
247

248
        private async Task CreateConfiguration()
249
        {
250
            var resultNew = await CliWrap.Cli.Wrap(_releaserExe)
3✔
251
                .WithArguments("new --user=xoofx --repo=HelloWorld --force --project=HelloWorld.csproj dotnet-releaser.toml")
3✔
252
                .WithStandardOutputPipe(PipeTarget.ToDelegate(x => Console.Out.WriteLine(x)))
3✔
253
                .WithStandardErrorPipe(PipeTarget.ToDelegate(x => Console.Error.WriteLine(x)))
×
254
                .WithWorkingDirectory(_helloWorldFolder).ExecuteAsync();
3✔
255
        }
3✔
256

257
        private static string Normalize(string text) => text.Replace("\r\n", "\n");
2✔
258
    }
259
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc