Skip to content

Commit

Permalink
Merge pull request #492 from DefangLabs/lio-fix-windows-build
Browse files Browse the repository at this point in the history
Fix windows build
  • Loading branch information
lionello authored Jun 24, 2024
2 parents 1813f70 + d9c00fe commit afa830b
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 8 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ jobs:
run: go test -test.short -v ./...
working-directory: src

- name: Build MacOS binary
run: GOOS=darwin go build ./cmd/cli
working-directory: src

- name: Build Windows binary
run: GOOS=windows go build ./cmd/cli
working-directory: src

- name: Verify Go modules
working-directory: src
run: |
Expand Down
12 changes: 12 additions & 0 deletions src/pkg/cli/cert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ type dnsRequest struct {
var notFound = errors.New("not found")

func TestGetCNAMEInSync(t *testing.T) {
t.Cleanup(func() {
dns.ResolverAt = dns.DirectResolverAt
})

notFoundResolver := dns.MockResolver{Records: map[dns.DNSRequest]dns.DNSResponse{
{Type: "NS", Domain: "web.test.com"}: {Records: []string{"ns1.example.com", "ns2.example.com"}, Error: nil},
{Type: "CNAME", Domain: "web.test.com"}: {Records: nil, Error: notFound},
Expand Down Expand Up @@ -70,6 +74,10 @@ func TestGetCNAMEInSync(t *testing.T) {
}

func TestGetIPInSync(t *testing.T) {
t.Cleanup(func() {
dns.ResolverAt = dns.DirectResolverAt
})

notFoundResolver := dns.MockResolver{Records: map[dns.DNSRequest]dns.DNSResponse{
{Type: "NS", Domain: "test.com"}: {Records: []string{"ns1.example.com", "ns2.example.com"}, Error: nil},
{Type: "A", Domain: "test.com"}: {Records: nil, Error: notFound},
Expand Down Expand Up @@ -156,6 +164,10 @@ func TestCheckDomainDNSReady(t *testing.T) {
}}
resolver = hasARecordResolver

t.Cleanup(func() {
dns.ResolverAt = dns.DirectResolverAt
})

t.Run("CNAME and A records not found", func(t *testing.T) {
dns.ResolverAt = func(_ string) dns.Resolver { return emptyResolver }
if checkDomainDNSReady(context.Background(), "api.test.com", []string{"some-alb.domain.com"}) != false {
Expand Down
4 changes: 3 additions & 1 deletion src/pkg/dns/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,12 @@ func FindNSServers(ctx context.Context, domain string) ([]*net.NS, error) {
}
}

var ResolverAt = func(nsServer string) Resolver {
func DirectResolverAt(nsServer string) Resolver {
return DirectResolver{NSServer: nsServer}
}

var ResolverAt = DirectResolverAt

var ErrNoSuchHost = &net.DNSError{Err: "no such host", IsNotFound: true}

type DirectResolver struct {
Expand Down
10 changes: 4 additions & 6 deletions src/pkg/dns/resolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ import (
)

func TestFindNSServer(t *testing.T) {
t.Cleanup(func() {
ResolverAt = DirectResolverAt
})

t.Run("NS server not exist on domain", func(t *testing.T) {
ResolverAt = func(nsServer string) Resolver {
if strings.Contains(nsServer, "root-servers.net") {
Expand Down Expand Up @@ -78,9 +82,6 @@ func TestFindNSServer(t *testing.T) {
func TestRootResolver(t *testing.T) {
t.Run("LookupIPAddr on google return both IPv4 and IPv6", func(t *testing.T) {
r := RootResolver{}
ResolverAt = func(nsServer string) Resolver {
return DirectResolver{NSServer: nsServer}
}
ips, err := r.LookupIPAddr(context.Background(), "www.google.com")
if err != nil {
t.Errorf("Expected no error, got %v", err)
Expand All @@ -104,9 +105,6 @@ func TestRootResolver(t *testing.T) {

t.Run("LookupIPAddr on defang.io return same set of IPs", func(t *testing.T) {
r := RootResolver{}
ResolverAt = func(nsServer string) Resolver {
return DirectResolver{NSServer: nsServer}
}
ips, err := r.LookupIPAddr(context.Background(), "fabric-prod1.defang.dev")
if err != nil {
t.Errorf("Expected no error, got %v", err)
Expand Down
2 changes: 1 addition & 1 deletion src/pkg/term/colorizer_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ func EnableANSI() func() {
}
}

func isTerminal() bool {
func hasTermInEnv() bool {
return true
}

0 comments on commit afa830b

Please sign in to comment.