Skip to content

Commit

Permalink
Upgrade deps
Browse files Browse the repository at this point in the history
  • Loading branch information
dissoupov committed Dec 31, 2023
1 parent e534bbc commit 8f0e3ad
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 108 deletions.
2 changes: 1 addition & 1 deletion .VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v0.1
v0.2
54 changes: 26 additions & 28 deletions .github/workflows/unittest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,7 @@ on:

jobs:
UnitTest:
strategy:
matrix:
go-version: [1.19.x]
os: [ubuntu-latest]
runs-on: ${{ matrix.os }}
runs-on: ubuntu-latest
env:
ITEST_IMAGE_TAG: rc-${{ github.event.number }}
COMMIT_SHA: ${{ github.event.pull_request.head.sha }}
Expand All @@ -23,41 +19,43 @@ jobs:
MIN_TESTCOV: 80

steps:
- name: Create code coverage status for the current commit
if: github.event_name == 'pull_request'
run: |
curl "https://${GIT_USER}:${GIT_TOKEN}@api.github.com/repos/${GITHUB_REPOSITORY}/statuses/${COMMIT_SHA}" -d "{\"state\": \"pending\",\"target_url\": \"https://github.com/${GITHUB_REPOSITORY}/pull/${PULL_NUMBER}/checks?check_run_id=${RUN_ID}\",\"description\": \"in progress — This check has started... \",\"context\": \"code cov\"}"
env:
GIT_TOKEN: ${{ secrets.BUILDER_PAT }}
GIT_USER: ${{ secrets.GIT_USER }}
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Install Go
uses: actions/setup-go@v3
uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go-version }}
go-version-file: go.mod

- name: Checkout code
uses: actions/checkout@v3
# - name: Create code coverage status for the current commit
# if: github.event_name == 'pull_request'
# run: |
# curl "https://${GIT_USER}:${GIT_TOKEN}@api.github.com/repos/${GITHUB_REPOSITORY}/statuses/${COMMIT_SHA}" -d "{\"state\": \"pending\",\"target_url\": \"https://github.com/${GITHUB_REPOSITORY}/pull/${PULL_NUMBER}/checks?check_run_id=${RUN_ID}\",\"description\": \"in progress — This check has started... \",\"context\": \"code cov\"}"
# env:
# GIT_TOKEN: ${{ secrets.BUILDER_PAT }}
# GIT_USER: ${{ secrets.GIT_USER }}

- name: Prepare
run: make vars tools generate

- name: UnitTest
run: make build covtest

- name: Generate covarege Status
if: github.event_name == 'pull_request'
run: |
set -x
PROJECT_NAME=${PROJECT_NAME}
# - name: Generate covarege Status
# if: github.event_name == 'pull_request'
# run: |
# set -x
# PROJECT_NAME=${PROJECT_NAME}

total=`go tool cover -func=coverage.out | grep total | grep -Eo '[0-9]+\.[0-9]+'`
echo "total cov: $total"
(( $(echo "$total > ${MIN_TESTCOV}" | bc -l) )) && STATE=success || STATE=failure
curl "https://${GIT_USER}:${GIT_TOKEN}@api.github.com/repos/${GITHUB_REPOSITORY}/statuses/${COMMIT_SHA}" -d "{\"state\": \"${STATE}\",\"target_url\": \"https://github.com/${GITHUB_REPOSITORY}/pull/${PULL_NUMBER}/checks?check_run_id=${RUN_ID}\",\"description\": \"${total}%\",\"context\": \"code cov\"}"
env:
GIT_TOKEN: ${{ secrets.BUILDER_PAT }}
GIT_USER: ${{ secrets.GIT_USER }}
# total=`go tool cover -func=coverage.out | grep total | grep -Eo '[0-9]+\.[0-9]+'`
# echo "total cov: $total"
# (( $(echo "$total > ${MIN_TESTCOV}" | bc -l) )) && STATE=success || STATE=failure
# curl "https://${GIT_USER}:${GIT_TOKEN}@api.github.com/repos/${GITHUB_REPOSITORY}/statuses/${COMMIT_SHA}" -d "{\"state\": \"${STATE}\",\"target_url\": \"https://github.com/${GITHUB_REPOSITORY}/pull/${PULL_NUMBER}/checks?check_run_id=${RUN_ID}\",\"description\": \"${total}%\",\"context\": \"code cov\"}"
# env:
# GIT_TOKEN: ${{ secrets.BUILDER_PAT }}
# GIT_USER: ${{ secrets.GIT_USER }}

- name: coveralls
#if: github.event_name == 'pull_request'
Expand Down
13 changes: 6 additions & 7 deletions .project/gomod-project.mk
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ GOLANG_HOST := golang.org
GIT_DIRTY := $(shell git describe --dirty --always --tags --long | grep -q -e '-dirty' && echo -$$HOSTNAME)
GIT_HASH := $(shell git rev-parse --short HEAD)
# number of commits
COMMITS_COUNT := $(shell git rev-list --count ${GIT_HASH})
COMMITS_COUNT := $(shell git rev-list --no-merges --count HEAD)
#
PROD_VERSION := $(shell cat .VERSION)
GIT_VERSION := $(shell printf %s.%d%s ${PROD_VERSION} ${COMMITS_COUNT} ${GIT_DIRTY})
Expand All @@ -77,14 +77,12 @@ export GOBIN=$(PROJ_ROOT)/bin
export VENDOR_SRC=$(PROJ_ROOT)/vendor

# tools path
export TOOLS_PATH := ${PROJ_DIR}/.tools
export TOOLS_BIN := ${TOOLS_PATH}/bin
export PATH := ${PATH}:${PROJ_BIN}:${TOOLS_BIN}
export PATH := ${PROJ_BIN}:${PATH}

# List of all .go files in the project, exluding vendor and tools
PROJ_GOFILES = $(shell find . -type f -name '*.go' -not -path "./vendor/*" -not -path "./.gopath/*" -not -path "./.tools/*")

COVERAGE_EXCLUSIONS="/rt\.go|/bindata\.go|_test.go|_mock.go|main.go"
COVERAGE_EXCLUSIONS="/rt\.go|/bindata\.go|_test.go|_mock.go"

# flags
INTEGRATION_TAG="integration"
Expand Down Expand Up @@ -197,13 +195,13 @@ fmt:
echo "Running Fmt"
gofmt -s -l -w ${GOFILES_NOVENDOR}

vet: build
vet:
echo "Running vet"
go vet ${BUILD_FLAGS} ./...

lint:
echo "Running lint"
go list ./... | grep -v /vendor/ | xargs -L1 golint -set_exit_status
golangci-lint run

test: fmt vet lint
echo "Running test"
Expand All @@ -219,6 +217,7 @@ sometests:

covtest: fmt vet lint
echo "Running covtest"
rm -rf ${COVPATH}
$(call go_test_cover,${PROJ_DIR},${BUILD_FLAGS},${TEST_RACEFLAG},${TEST_GORACEOPTIONS},.,${COVERAGE_EXCLUSIONS})

# Runs integration tests as well
Expand Down
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ clean:
${PROJ_BIN}

tools:
go install github.com/go-phorce/cov-report/cmd/cov-report
go install golang.org/x/lint/golint
go install github.com/mattn/goveralls
go install github.com/go-phorce/cov-report/cmd/cov-report@latest
go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.54
go install github.com/mattn/goveralls@latest

build:
echo "nothing to build yet"
Expand Down
13 changes: 2 additions & 11 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,22 +1,13 @@
module github.com/effective-security/servefiles

go 1.18
go 1.21

require (
github.com/go-phorce/cov-report v1.1.1-0.20200622030546-3fb510c4b1ba
github.com/mattn/goveralls v0.0.11
github.com/stretchr/testify v1.8.0
golang.org/x/lint v0.0.0-20210508222113-6edffad5e616
)
require github.com/stretchr/testify v1.8.0

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
golang.org/x/mod v0.5.1 // indirect
golang.org/x/sys v0.0.0-20220317061510-51cd9980dadf // indirect
golang.org/x/tools v0.1.9 // indirect
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
37 changes: 0 additions & 37 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,60 +2,23 @@ github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ3
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/go-phorce/cov-report v1.1.1-0.20200622030546-3fb510c4b1ba h1:I45RdP92/rYpHoHrHBGRKl1Sp1xw5VFNUQJWHX2Tz/c=
github.com/go-phorce/cov-report v1.1.1-0.20200622030546-3fb510c4b1ba/go.mod h1:UZQo6+h5O8HW6TPt7HaXd4Nc234FYx5aFvw9RKL2IUk=
github.com/jteeuwen/go-bindata v3.0.7+incompatible/go.mod h1:JVvhzYOiGBnFSYRyV00iY8q7/0PThjIYav1p9h5dmKs=
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/mattn/goveralls v0.0.6/go.mod h1:h8b4ow6FxSPMQHF6o2ve3qsclnffZjYTNEKmLesRwqw=
github.com/mattn/goveralls v0.0.11 h1:eJXea6R6IFlL1QMKNMzDvvHv/hwGrnvyig4N+0+XiMM=
github.com/mattn/goveralls v0.0.11/go.mod h1:gU8SyhNswsJKchEV93xRQxX6X3Ei4PJdQk/6ZHvrvRk=
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8=
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/lint v0.0.0-20200302205851-738671d3881b/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY=
golang.org/x/lint v0.0.0-20210508222113-6edffad5e616 h1:VLliZ0d+/avPrXXH+OakdXhpJuEoBZuwh1m2j7U6Iug=
golang.org/x/lint v0.0.0-20210508222113-6edffad5e616/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY=
golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.5.1 h1:OJxoQ/rynoF0dcCdI7cLPktw/hR2cueqYfjm43oqK38=
golang.org/x/mod v0.5.1/go.mod h1:5OXOZSfqPIIbmVBIIKWRFfZjPR0E5r58TLhUjH0a2Ro=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20220317061510-51cd9980dadf h1:Fm4IcnUL803i92qDlmB0obyHmosDrxZWxJL3gIeNqOw=
golang.org/x/sys v0.0.0-20220317061510-51cd9980dadf/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
golang.org/x/tools v0.0.0-20200522201501-cb1345f3a375/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
golang.org/x/tools v0.1.9 h1:j9KsMiaP1c3B0OTQGth0/k+miLGTgLsAFUCrF2vLcF8=
golang.org/x/tools v0.1.9/go.mod h1:nABZi5QlRsZVlzPpHl034qft6wpY4eDcsTt5AaioBiU=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
Expand Down
13 changes: 6 additions & 7 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"net/http"
"net/http/httptest"
"net/url"
Expand Down Expand Up @@ -98,7 +97,7 @@ func (s *Server) SetBaseDirs(newBaseDirs ...string) {
require.True(s.t, stat.IsDir(), "Supplied baseDir %s should be a directory", d)
}
var reqMap map[string]requestSettings
bytes, err := ioutil.ReadFile(filepath.Join(newBaseDirs[0], "requests.json"))
bytes, err := os.ReadFile(filepath.Join(newBaseDirs[0], "requests.json"))
require.NoError(s.t, err)
require.NoError(s.t, json.Unmarshal(bytes, &reqMap))
s.lock.Lock()
Expand Down Expand Up @@ -207,7 +206,7 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
var err error
hasBody := false
if r.Method == http.MethodPost || r.Method == http.MethodPut {
reqBody, err = ioutil.ReadAll(r.Body)
reqBody, err = io.ReadAll(r.Body)
assert.NoError(s.t, err, "unable to read request body for request to %s", requestURI)
hasBody = true
}
Expand Down Expand Up @@ -279,7 +278,7 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
return
}
}
io.Copy(w, f)
_, _ = io.Copy(w, f)
}

// handleAuthFixup is special handling for the token auth response which contains
Expand All @@ -289,7 +288,7 @@ func handleAuthFixup(serverURL string, w io.Writer, f io.Reader) {
var auth map[string]interface{}
dec := json.NewDecoder(f)
dec.UseNumber()
dec.Decode(&auth)
_ = dec.Decode(&auth)
auth["instance_url"] = serverURL
if id, exists := auth["id"]; exists {
idURL, err1 := url.Parse(id.(string))
Expand All @@ -300,7 +299,7 @@ func handleAuthFixup(serverURL string, w io.Writer, f io.Reader) {
auth["id"] = idURL.String()
}
}
json.NewEncoder(w).Encode(&auth)
_ = json.NewEncoder(w).Encode(&auth)
}

func jsonEqual(v1 interface{}, v2 interface{}) bool {
Expand All @@ -313,7 +312,7 @@ func (s *Server) notFound(w http.ResponseWriter, r *http.Request) {
s.t.Logf("no response file exists for %s, returning a 404 response", r.URL.Path)
notFound := `{"code": "NOT_FOUND", "message": "the requested resource does not exist"}`
w.WriteHeader(http.StatusNotFound)
io.WriteString(w, notFound)
_, _ = io.WriteString(w, notFound)
}

const (
Expand Down
3 changes: 1 addition & 2 deletions server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"net/http"
"net/http/httptest"
"testing"
Expand Down Expand Up @@ -41,7 +40,7 @@ func (s *serverTestSuite) doHTTPCall(method, path string, body io.Reader, expSta
res, err := http.DefaultClient.Do(req)
s.Require().NoError(err)
defer res.Body.Close()
resBody, err := ioutil.ReadAll(res.Body)
resBody, err := io.ReadAll(res.Body)
s.Require().NoError(err)
s.Require().Equal(expStatusCode, res.StatusCode)
return resBody, res.Header
Expand Down
12 changes: 0 additions & 12 deletions tools.go

This file was deleted.

0 comments on commit 8f0e3ad

Please sign in to comment.