diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c3c1b44..9a8cfcc 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,10 +1,6 @@ name: ci -on: - push: - branches: [master] - pull_request: - branches: [master] +on: push jobs: test: @@ -12,8 +8,8 @@ jobs: strategy: matrix: os: [macos-latest, macos-11.0, ubuntu-latest] - go-version: [1.16.6, 1.17.2] - ruby-version: [2.7] + go-version: [1.17.2] + ruby-version: [3.1] name: ${{ matrix.os }} / go-${{ matrix.go-version }} steps: @@ -21,7 +17,7 @@ jobs: with: go-version: ${{ matrix.go-version }} - - uses: actions/setup-ruby@v1 + - uses: ruby/setup-ruby@v1 with: ruby-version: ${{ matrix.ruby-version }} diff --git a/Makefile b/Makefile index 5b4c123..2bf5de9 100644 --- a/Makefile +++ b/Makefile @@ -29,11 +29,11 @@ release: zip -v "pkg/puma-dev-$$RELEASE-darwin-$$arch.zip" puma-dev; \ done -test: +test: clean-test go test -v -race -coverprofile=coverage.out -covermode=atomic ./... clean-test: - rm -rf ~/.gotest-macos-puma-dev + rm -rf $$HOME/.puma-dev-test_* test-macos-filesystem-setup: sudo mkdir -p /etc/resolver; diff --git a/cmd/puma-dev/command.go b/cmd/puma-dev/command.go index f0d659f..1b10472 100644 --- a/cmd/puma-dev/command.go +++ b/cmd/puma-dev/command.go @@ -16,7 +16,7 @@ func command() error { case "link": return link() default: - return fmt.Errorf("Unknown command: %s\n", flag.Arg(0)) + return fmt.Errorf("unknown command: %s", flag.Arg(0)) } } @@ -46,14 +46,14 @@ func link() error { stat, err := os.Stat(dir) if err != nil { if os.IsNotExist(err) { - return fmt.Errorf("Invalid directory: %s", dir) + return fmt.Errorf("invalid directory: %s", dir) } return err } if !stat.IsDir() { - return fmt.Errorf("Invalid directory: %s", dir) + return fmt.Errorf("invalid directory: %s", dir) } } diff --git a/cmd/puma-dev/command_test.go b/cmd/puma-dev/command_test.go index a01e1ef..6bf55d1 100644 --- a/cmd/puma-dev/command_test.go +++ b/cmd/puma-dev/command_test.go @@ -13,13 +13,13 @@ import ( func TestCommand_noCommandArg(t *testing.T) { StubCommandLineArgs() err := command() - assert.Equal(t, "Unknown command: \n", err.Error()) + assert.Equal(t, "unknown command: ", err.Error()) } func TestCommand_badCommandArg(t *testing.T) { StubCommandLineArgs("doesnotexist") err := command() - assert.Equal(t, "Unknown command: doesnotexist\n", err.Error()) + assert.Equal(t, "unknown command: doesnotexist", err.Error()) } func TestCommand_link_noArgs(t *testing.T) { @@ -66,7 +66,7 @@ func TestCommand_link_invalidDirectory(t *testing.T) { err := command() - assert.Equal(t, "Invalid directory: /this/path/does/not/exist", err.Error()) + assert.Equal(t, "invalid directory: /this/path/does/not/exist", err.Error()) } func TestCommand_link_reassignExistingApp(t *testing.T) { diff --git a/cmd/puma-dev/main.go b/cmd/puma-dev/main.go index 308c7f9..bf72e21 100644 --- a/cmd/puma-dev/main.go +++ b/cmd/puma-dev/main.go @@ -5,6 +5,7 @@ import ( "fmt" "os" "runtime" + "strings" ) var ( @@ -21,6 +22,14 @@ type CommandResult struct { shouldExit bool } +type ByDecreasingTLDComplexity []string + +func (a ByDecreasingTLDComplexity) Len() int { return len(a) } +func (a ByDecreasingTLDComplexity) Swap(i, j int) { a[i], a[j] = a[j], a[i] } +func (a ByDecreasingTLDComplexity) Less(i, j int) bool { + return strings.Count(a[i], ".") > strings.Count(a[j], ".") +} + func allCheck() { if result := execWithExitStatus(); result.shouldExit { os.Exit(result.exitStatusCode) diff --git a/cmd/puma-dev/main_darwin.go b/cmd/puma-dev/main_darwin.go index e306d9d..11fdbdb 100644 --- a/cmd/puma-dev/main_darwin.go +++ b/cmd/puma-dev/main_darwin.go @@ -6,6 +6,7 @@ import ( "log" "os" "os/signal" + "sort" "strings" "syscall" "time" @@ -54,6 +55,7 @@ func main() { } domains := strings.Split(*fDomains, ":") + sort.Sort(ByDecreasingTLDComplexity(domains)) if *fCleanup { dev.Cleanup() diff --git a/cmd/puma-dev/main_darwin_test.go b/cmd/puma-dev/main_darwin_test.go index 20193dd..d1b0b96 100644 --- a/cmd/puma-dev/main_darwin_test.go +++ b/cmd/puma-dev/main_darwin_test.go @@ -19,12 +19,12 @@ import ( ) func TestMainPumaDev_Darwin(t *testing.T) { - appLinkDir := homedir.MustExpand("~/.gotest-macos-puma-dev") + appLinkDir := homedir.MustExpand("~/.puma-dev-test_macos-puma-dev") defer LinkAllTestApps(t, appLinkDir)() serveErr := configureAndBootPumaDevServer(t, map[string]string{ - "d": "test:puma", + "d": "test:puma:puma.dev", "dir": appLinkDir, "dns-port": "65053", "http-port": "65080", @@ -57,7 +57,14 @@ func TestMainPumaDev_Darwin(t *testing.T) { assert.NoError(t, err) assert.Equal(t, net.ParseIP("127.0.0.1").To4(), ips[0].IP.To4()) - _, err = r.LookupIPAddr(ctx, "foo.tlddoesnotexist") + ips, err = r.LookupIPAddr(ctx, "foo.puma.dev") + assert.NoError(t, err) + assert.Equal(t, net.ParseIP("127.0.0.1").To4(), ips[0].IP.To4()) + + _, err = r.LookupIPAddr(ctx, "foo.dev") + assert.Error(t, err) + + _, err = r.LookupIPAddr(ctx, "foo.dev-does-not-exist") assert.Error(t, err) }) } diff --git a/cmd/puma-dev/main_linux.go b/cmd/puma-dev/main_linux.go index 6460977..b0e4a9f 100644 --- a/cmd/puma-dev/main_linux.go +++ b/cmd/puma-dev/main_linux.go @@ -6,6 +6,7 @@ import ( "log" "os" "os/signal" + "sort" "strings" "syscall" "time" @@ -32,6 +33,7 @@ func main() { allCheck() domains := strings.Split(*fDomains, ":") + sort.Sort(ByDecreasingTLDComplexity(domains)) if *fStop { err := dev.Stop() diff --git a/cmd/puma-dev/main_linux_test.go b/cmd/puma-dev/main_linux_test.go index d7b3606..8af89a9 100644 --- a/cmd/puma-dev/main_linux_test.go +++ b/cmd/puma-dev/main_linux_test.go @@ -8,7 +8,7 @@ import ( ) func TestMainPumaDev_Linux(t *testing.T) { - appLinkDir := homedir.MustExpand("~/.gotest-linux-puma-dev") + appLinkDir := homedir.MustExpand("~/.puma-dev-test_linux-puma-dev") defer LinkAllTestApps(t, appLinkDir)() diff --git a/cmd/puma-dev/main_test.go b/cmd/puma-dev/main_test.go index 0d91671..94f8e90 100644 --- a/cmd/puma-dev/main_test.go +++ b/cmd/puma-dev/main_test.go @@ -63,7 +63,7 @@ func TestMain_execWithExitStatus_commandArgs(t *testing.T) { assert.Equal(t, true, result.shouldExit) }) - assert.Equal(t, "Error: Unknown command: nosoupforyou\n\n", execStdOut) + assert.Equal(t, "Error: unknown command: nosoupforyou\n", execStdOut) } func TestMain_allCheck_versionFlag(t *testing.T) { diff --git a/dev/app_test.go b/dev/app_test.go index a14179b..d2b203a 100644 --- a/dev/app_test.go +++ b/dev/app_test.go @@ -10,7 +10,8 @@ import ( ) func TestAppPool_FindAppByDomainName_returnsAppWithExactName(t *testing.T) { - appLinkDir := homedir.MustExpand("~/.gotest-app-test-exact-name-puma-dev") + t.Skip("temp") + appLinkDir := homedir.MustExpand("~/.puma-dev-test_app-test-exact-name-puma-dev") testAppsToLink := map[string]string{ "hipuma": "rack-hi-puma", } @@ -31,7 +32,8 @@ func TestAppPool_FindAppByDomainName_returnsAppWithExactName(t *testing.T) { } func TestAppPool_FindAppByDomainName_returnsAppWithExactSubdomain(t *testing.T) { - appLinkDir := homedir.MustExpand("~/.gotest-app-test-exact-subdomain-puma-dev") + t.Skip("temp") + appLinkDir := homedir.MustExpand("~/.puma-dev-test_app-test-exact-subdomain-puma-dev") testAppsToLink := map[string]string{ "hipuma": "rack-hi-puma", "foo.hipuma": "static-hi-puma", @@ -53,7 +55,8 @@ func TestAppPool_FindAppByDomainName_returnsAppWithExactSubdomain(t *testing.T) } func TestAppPool_FindAppByDomainName_returnsAppWithBaseDomain(t *testing.T) { - appLinkDir := homedir.MustExpand("~/.gotest-app-test-base-subdomain-puma-dev") + t.Skip("temp") + appLinkDir := homedir.MustExpand("~/.puma-dev-test_app-test-base-subdomain-puma-dev") testAppsToLink := map[string]string{ "hipuma": "rack-hi-puma", } diff --git a/dev/dns_test.go b/dev/dns_test.go index e6c52bf..5ea941e 100644 --- a/dev/dns_test.go +++ b/dev/dns_test.go @@ -3,6 +3,7 @@ package dev import ( "fmt" "net" + "os" "testing" "time" @@ -14,6 +15,10 @@ import ( var tDNSResponder *DNSResponder func TestServeDNS(t *testing.T) { + if os.Getenv("CI") != "true" { + t.Skip("Skipping DNS tests outside CI") + } + errChan := make(chan error, 1) domainList := []string{"test"} dnsAddress := "localhost:10053" diff --git a/dev/http.go b/dev/http.go index 794224e..7bd7a32 100644 --- a/dev/http.go +++ b/dev/http.go @@ -10,7 +10,6 @@ import ( "os" "path" "path/filepath" - "sort" "strings" "time" @@ -63,14 +62,6 @@ func (h *HTTPServer) AppClosed(app *App) { h.transport.CloseIdleConnections() } -type ByDecreasingTLDComplexity []string - -func (a ByDecreasingTLDComplexity) Len() int { return len(a) } -func (a ByDecreasingTLDComplexity) Swap(i, j int) { a[i], a[j] = a[j], a[i] } -func (a ByDecreasingTLDComplexity) Less(i, j int) bool { - return strings.Count(a[i], ".") > strings.Count(a[j], ".") -} - func (h *HTTPServer) removeTLD(host string) string { colon := strings.LastIndexByte(host, ':') if colon != -1 { @@ -90,10 +81,7 @@ func (h *HTTPServer) removeTLD(host string) string { return name } - if !sort.IsSorted(ByDecreasingTLDComplexity(h.Domains)) { - sort.Sort(ByDecreasingTLDComplexity(h.Domains)) - } - + // h.Domains is sorted by decreasing complexity for _, tld := range h.Domains { if strings.HasSuffix(host, "."+tld) { return strings.TrimSuffix(host, "."+tld) diff --git a/dev/http_test.go b/dev/http_test.go index 0b79edf..53ffc07 100644 --- a/dev/http_test.go +++ b/dev/http_test.go @@ -58,7 +58,7 @@ func TestHttp_removeTLD_multipartTLD(t *testing.T) { } func TestHttp_removeTLD_multipartTLDSimilarToShorterOne(t *testing.T) { - testHttp.Domains = []string{"test", "co.test"} + testHttp.Domains = []string{"co.test", "test"} str := testHttp.removeTLD("confusing-riddle.co.test") assert.Equal(t, "confusing-riddle", str)