Skip to content

Commit ff4e254

Browse files
authored
race and linter fixes (#291)
* run ci on every push * error strings should not be capitalized or end with punctuation or a newline * skip flaky dns tests locally, move in-place domain sort to main * make it easier to clean up if test bails midway * testing * ruby 3.1? * new gh action * one go only * skip * go back
1 parent 8afb0c5 commit ff4e254

File tree

14 files changed

+50
-38
lines changed

14 files changed

+50
-38
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,23 @@
11
name: ci
22

3-
on:
4-
push:
5-
branches: [master]
6-
pull_request:
7-
branches: [master]
3+
on: push
84

95
jobs:
106
test:
117
runs-on: ${{ matrix.os }}
128
strategy:
139
matrix:
1410
os: [macos-latest, macos-11.0, ubuntu-latest]
15-
go-version: [1.16.6, 1.17.2]
16-
ruby-version: [2.7]
11+
go-version: [1.17.2]
12+
ruby-version: [3.1]
1713

1814
name: ${{ matrix.os }} / go-${{ matrix.go-version }}
1915
steps:
2016
- uses: actions/setup-go@v1
2117
with:
2218
go-version: ${{ matrix.go-version }}
2319

24-
- uses: actions/setup-ruby@v1
20+
- uses: ruby/setup-ruby@v1
2521
with:
2622
ruby-version: ${{ matrix.ruby-version }}
2723

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ release:
2929
zip -v "pkg/puma-dev-$$RELEASE-darwin-$$arch.zip" puma-dev; \
3030
done
3131

32-
test:
32+
test: clean-test
3333
go test -v -race -coverprofile=coverage.out -covermode=atomic ./...
3434

3535
clean-test:
36-
rm -rf ~/.gotest-macos-puma-dev
36+
rm -rf $$HOME/.puma-dev-test_*
3737

3838
test-macos-filesystem-setup:
3939
sudo mkdir -p /etc/resolver;

cmd/puma-dev/command.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ func command() error {
1616
case "link":
1717
return link()
1818
default:
19-
return fmt.Errorf("Unknown command: %s\n", flag.Arg(0))
19+
return fmt.Errorf("unknown command: %s", flag.Arg(0))
2020
}
2121
}
2222

@@ -46,14 +46,14 @@ func link() error {
4646
stat, err := os.Stat(dir)
4747
if err != nil {
4848
if os.IsNotExist(err) {
49-
return fmt.Errorf("Invalid directory: %s", dir)
49+
return fmt.Errorf("invalid directory: %s", dir)
5050
}
5151

5252
return err
5353
}
5454

5555
if !stat.IsDir() {
56-
return fmt.Errorf("Invalid directory: %s", dir)
56+
return fmt.Errorf("invalid directory: %s", dir)
5757
}
5858
}
5959

cmd/puma-dev/command_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ import (
1313
func TestCommand_noCommandArg(t *testing.T) {
1414
StubCommandLineArgs()
1515
err := command()
16-
assert.Equal(t, "Unknown command: \n", err.Error())
16+
assert.Equal(t, "unknown command: ", err.Error())
1717
}
1818

1919
func TestCommand_badCommandArg(t *testing.T) {
2020
StubCommandLineArgs("doesnotexist")
2121
err := command()
22-
assert.Equal(t, "Unknown command: doesnotexist\n", err.Error())
22+
assert.Equal(t, "unknown command: doesnotexist", err.Error())
2323
}
2424

2525
func TestCommand_link_noArgs(t *testing.T) {
@@ -66,7 +66,7 @@ func TestCommand_link_invalidDirectory(t *testing.T) {
6666

6767
err := command()
6868

69-
assert.Equal(t, "Invalid directory: /this/path/does/not/exist", err.Error())
69+
assert.Equal(t, "invalid directory: /this/path/does/not/exist", err.Error())
7070
}
7171

7272
func TestCommand_link_reassignExistingApp(t *testing.T) {

cmd/puma-dev/main.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"fmt"
66
"os"
77
"runtime"
8+
"strings"
89
)
910

1011
var (
@@ -21,6 +22,14 @@ type CommandResult struct {
2122
shouldExit bool
2223
}
2324

25+
type ByDecreasingTLDComplexity []string
26+
27+
func (a ByDecreasingTLDComplexity) Len() int { return len(a) }
28+
func (a ByDecreasingTLDComplexity) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
29+
func (a ByDecreasingTLDComplexity) Less(i, j int) bool {
30+
return strings.Count(a[i], ".") > strings.Count(a[j], ".")
31+
}
32+
2433
func allCheck() {
2534
if result := execWithExitStatus(); result.shouldExit {
2635
os.Exit(result.exitStatusCode)

cmd/puma-dev/main_darwin.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"log"
77
"os"
88
"os/signal"
9+
"sort"
910
"strings"
1011
"syscall"
1112
"time"
@@ -54,6 +55,7 @@ func main() {
5455
}
5556

5657
domains := strings.Split(*fDomains, ":")
58+
sort.Sort(ByDecreasingTLDComplexity(domains))
5759

5860
if *fCleanup {
5961
dev.Cleanup()

cmd/puma-dev/main_darwin_test.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ import (
1919
)
2020

2121
func TestMainPumaDev_Darwin(t *testing.T) {
22-
appLinkDir := homedir.MustExpand("~/.gotest-macos-puma-dev")
22+
appLinkDir := homedir.MustExpand("~/.puma-dev-test_macos-puma-dev")
2323

2424
defer LinkAllTestApps(t, appLinkDir)()
2525

2626
serveErr := configureAndBootPumaDevServer(t, map[string]string{
27-
"d": "test:puma",
27+
"d": "test:puma:puma.dev",
2828
"dir": appLinkDir,
2929
"dns-port": "65053",
3030
"http-port": "65080",
@@ -57,7 +57,14 @@ func TestMainPumaDev_Darwin(t *testing.T) {
5757
assert.NoError(t, err)
5858
assert.Equal(t, net.ParseIP("127.0.0.1").To4(), ips[0].IP.To4())
5959

60-
_, err = r.LookupIPAddr(ctx, "foo.tlddoesnotexist")
60+
ips, err = r.LookupIPAddr(ctx, "foo.puma.dev")
61+
assert.NoError(t, err)
62+
assert.Equal(t, net.ParseIP("127.0.0.1").To4(), ips[0].IP.To4())
63+
64+
_, err = r.LookupIPAddr(ctx, "foo.dev")
65+
assert.Error(t, err)
66+
67+
_, err = r.LookupIPAddr(ctx, "foo.dev-does-not-exist")
6168
assert.Error(t, err)
6269
})
6370
}

cmd/puma-dev/main_linux.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"log"
77
"os"
88
"os/signal"
9+
"sort"
910
"strings"
1011
"syscall"
1112
"time"
@@ -32,6 +33,7 @@ func main() {
3233
allCheck()
3334

3435
domains := strings.Split(*fDomains, ":")
36+
sort.Sort(ByDecreasingTLDComplexity(domains))
3537

3638
if *fStop {
3739
err := dev.Stop()

cmd/puma-dev/main_linux_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
)
99

1010
func TestMainPumaDev_Linux(t *testing.T) {
11-
appLinkDir := homedir.MustExpand("~/.gotest-linux-puma-dev")
11+
appLinkDir := homedir.MustExpand("~/.puma-dev-test_linux-puma-dev")
1212

1313
defer LinkAllTestApps(t, appLinkDir)()
1414

cmd/puma-dev/main_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ func TestMain_execWithExitStatus_commandArgs(t *testing.T) {
6363
assert.Equal(t, true, result.shouldExit)
6464
})
6565

66-
assert.Equal(t, "Error: Unknown command: nosoupforyou\n\n", execStdOut)
66+
assert.Equal(t, "Error: unknown command: nosoupforyou\n", execStdOut)
6767
}
6868

6969
func TestMain_allCheck_versionFlag(t *testing.T) {

0 commit comments

Comments
 (0)