add common unit test
This commit is contained in:
		
							parent
							
								
									9b9edf08d8
								
							
						
					
					
						commit
						ed4ee637ab
					
				
							
								
								
									
										12
									
								
								Dockerfile
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								Dockerfile
									
									
									
									
									
										Normal file
									
								
							@ -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"]
 | 
			
		||||
							
								
								
									
										11
									
								
								Makefile
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								Makefile
									
									
									
									
									
										Normal file
									
								
							@ -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 ./...
 | 
			
		||||
							
								
								
									
										1
									
								
								go.sum
									
									
									
									
									
								
							
							
						
						
									
										1
									
								
								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=
 | 
			
		||||
 | 
			
		||||
@ -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)
 | 
			
		||||
			}
 | 
			
		||||
		})
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user