fix(subpath) & test:

1. resolve package-path contains subdir path
2. add test
3. adjust build
pull/49/head
hxzhao527 2019-01-21 15:18:13 +08:00 committed by kun
parent ffdf9f23eb
commit cc1208f526
8 changed files with 53 additions and 20 deletions

View File

@ -5,10 +5,23 @@ version: 2
jobs:
build:
docker:
# specify the version
- image: circleci/golang:1.11
working_directory: /go/src/github.com/goproxyio/goproxy/
steps:
- checkout
# specify any bash command here prefixed with `run: `
- run: bash circle-test.sh
- run:
name: install deps
command: make generate
- run:
name: test self
command: make test
- run:
name: build bin
command: make build
- run:
name: run proxy backgroud to test real
command: bin/goproxy
background: true
- run:
name: run real test
command: bash test/get_test.sh

View File

@ -3,17 +3,15 @@ FROM golang:alpine AS build
RUN apk add --no-cache -U make
COPY . /src/goproxy
WORKDIR /src/goproxy
ENV CGO_ENABLED=0
RUN make
RUN cd /src/goproxy &&\
export CGO_ENABLED=0 &&\
make
FROM alpine:latest
RUN apk add --no-cache -U git mercurial subversion bzr fossil
COPY --from=build /src/goproxy/goproxy /goproxy
COPY --from=build /src/goproxy/bin/goproxy /goproxy
VOLUME /go

View File

@ -1,15 +1,21 @@
.PHONY: build generate image clean
.PHONY: build generate image clean test
export GO111MODULE=on
all: build
build: generate
@go build -tags "netgo static_build" -installsuffix netgo -ldflags -w .
@go build -o bin/goproxy -ldflags "-s -w" .
generate:
@go generate
@go mod tidy
image:
@docker build -t goproxy/goproxy .
test: generate
@go test -v `(go list ./... | grep "pkg/proxy")`
clean:
@git clean -f -d -X

View File

@ -1,9 +0,0 @@
#!/bin/bash
export GO111MODULE=on
go generate
go mod tidy
go test -v `(go list ./... | grep "pkg/proxy")`
# build
go build -o bin/goproxy

View File

@ -58,6 +58,11 @@ func NewProxy(cache string) http.Handler {
ReturnBadRequest(w, err)
return
}
if realMod.Path != info.Version.Path {
log.Printf("goproxy: mod %s@%s may have subpath, just return to make client recurse", info.Path, info.Version.Version)
ReturnSuccess(w, nil)
return
}
switch suf {
case ".info":
{

View File

@ -156,6 +156,12 @@ var _modInfoTests = []struct {
"x.go",
},
},
{
path: "github.com/micro/go-api/resolver",
query: "v0.5.0",
version: "v0.5.0",
gomod: "module github.com/micro/go-api\n",
},
}
var _modListTests = []struct {

10
test/get_test.sh Executable file
View File

@ -0,0 +1,10 @@
#!/usr/bin/env bash
export GO111MODULE=on
export GOPROXY='http://127.0.0.1:8081'
datafile='test/testdata/get.txt'
while read -r line; do
go get -v ${line}
done < "${datafile}"

4
test/testdata/get.txt vendored Normal file
View File

@ -0,0 +1,4 @@
golang.org/x/net@latest
github.com/oiooj/agent@v0.2.2
github.com/micro/go-api/resolver@v0.5.0
cloud.google.com/go