diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..d6ef6d6 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,12 @@ +FROM golang:1-alpine as builder +WORKDIR /data +COPY . . +RUN apk add --no-cache build-base make && \ + make test && \ + make + +FROM alpine:latest +WORKDIR /data +COPY ./config/config.yml . +COPY --from=builder /data/tcp-proxy /usr/bin/tcp-proxy +CMD ["/usr/bin/tcp-proxy"] diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..ef4a538 --- /dev/null +++ b/Makefile @@ -0,0 +1,11 @@ +.PHONY: all +all: clean build + +build: + go build -o tcp-proxy -ldflags "-w -s" . + +clean: + go clean && rm -rf tcp-proxy + +test: + go test -v ./... diff --git a/go.sum b/go.sum index e61e2ad..5c33063 100644 --- a/go.sum +++ b/go.sum @@ -12,6 +12,7 @@ github.com/otakukaze/envconfig v1.0.0 h1:VGu7NoDFbReFO72m5Z15h5PH5gVk5fVLZ6iHF58 github.com/otakukaze/envconfig v1.0.0/go.mod h1:v2dNv5NX1Lakw3FTAkbxYURyaiOy68M8QpMTZz+ogfs= golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223 h1:DH4skfRX4EBpamg7iV4ZlCpblAHI6s6TDM39bFZumv8= golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v2 v2.2.7 h1:VUgggvou5XRW9mHwD/yXxIYSMtY0zoKQf/v226p2nyo= gopkg.in/yaml.v2 v2.2.7/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= diff --git a/pkg/common/common_test.go b/pkg/common/common_test.go index a5750d1..fe88fe6 100644 --- a/pkg/common/common_test.go +++ b/pkg/common/common_test.go @@ -1,8 +1,11 @@ package common -import "testing" +import ( + "testing" +) func TestCheckRemoteSSH(t *testing.T) { + type args struct { host string port int @@ -14,10 +17,10 @@ func TestCheckRemoteSSH(t *testing.T) { want error }{ { - name: "test check localhost ssh port", + name: "test check google web port", args: args{ - host: "localhost", - port: 22, + host: "google.com", + port: 80, timeout: 5, }, want: nil, @@ -31,3 +34,27 @@ func TestCheckRemoteSSH(t *testing.T) { }) } } + +func TestCheckDomain(t *testing.T) { + type args struct { + name string + } + tests := []struct { + name string + args args + wantErr bool + }{ + { + name: "test domain check", + args: args{name: "trj.tw"}, + wantErr: false, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if err := CheckDomain(tt.args.name); (err != nil) != tt.wantErr { + t.Errorf("CheckDomain() error = %v, wantErr %v", err, tt.wantErr) + } + }) + } +}