diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index 6a3630e..7c9cbd2 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -7,7 +7,7 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3.5.1 + - uses: actions/checkout@v4.1.1 - name: Build the Docker image run: docker build . --file Dockerfile --tag yosoy-local:latest - name: Run simple integration test diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml index 9f6b565..4e25dc2 100644 --- a/.github/workflows/docker-publish.yml +++ b/.github/workflows/docker-publish.yml @@ -15,16 +15,16 @@ jobs: contents: read steps: - name: Check out the repo - uses: actions/checkout@v3.5.1 + uses: actions/checkout@v4.1.1 - name: Log in to Docker Hub - uses: docker/login-action@v2 + uses: docker/login-action@v3 with: username: ${{ secrets.DOCKER_HUB_USERNAME }} password: ${{ secrets.DOCKER_HUB_TOKEN }} - name: Log in to the Container registry - uses: docker/login-action@v2 + uses: docker/login-action@v3 with: registry: ghcr.io username: ${{ github.actor }} @@ -32,7 +32,7 @@ jobs: - name: Extract metadata (tags, labels) for Docker id: meta - uses: docker/metadata-action@v4 + uses: docker/metadata-action@v5 with: images: | lukasz/yosoy @@ -44,7 +44,7 @@ jobs: type=semver,pattern={{major}} - name: Build and push Docker images - uses: docker/build-push-action@v4 + uses: docker/build-push-action@v5 with: context: . push: true diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 08b0cdf..aa0e9b0 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -6,7 +6,7 @@ jobs: build: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3.5.1 + - uses: actions/checkout@v4.1.1 - name: Set up Go uses: actions/setup-go@v4 diff --git a/go.mod b/go.mod index 18acce7..cc242b3 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/lukaszbudnik/yosoy go 1.16 require ( - github.com/gorilla/handlers v1.5.1 - github.com/gorilla/mux v1.8.0 - github.com/stretchr/testify v1.8.2 + github.com/gorilla/handlers v1.5.2 + github.com/gorilla/mux v1.8.1 + github.com/stretchr/testify v1.8.4 ) diff --git a/go.sum b/go.sum index a0b775b..4554164 100644 --- a/go.sum +++ b/go.sum @@ -1,12 +1,12 @@ 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/felixge/httpsnoop v1.0.1 h1:lvB5Jl89CsZtGIWuTcDM1E/vkVs49/Ml7JJe07l8SPQ= -github.com/felixge/httpsnoop v1.0.1/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U= -github.com/gorilla/handlers v1.5.1 h1:9lRY6j8DEeeBT10CvO9hGW0gmky0BprnvDI5vfhUHH4= -github.com/gorilla/handlers v1.5.1/go.mod h1:t8XrUpc4KVXb7HGyJ4/cEnwQiaxrX/hz1Zv/4g96P1Q= -github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI= -github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So= +github.com/felixge/httpsnoop v1.0.3 h1:s/nj+GCswXYzN5v2DpNMuMQYe+0DDwt5WVCU6CWBdXk= +github.com/felixge/httpsnoop v1.0.3/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U= +github.com/gorilla/handlers v1.5.2 h1:cLTUSsNkgcwhgRqvCNmdbRWG0A3N4F+M2nWKdScwyEE= +github.com/gorilla/handlers v1.5.2/go.mod h1:dX+xVpaxdSw+q0Qek8SSsl3dfMk3jNddUkMzo0GtH0w= +github.com/gorilla/mux v1.8.1 h1:TuBL49tXwgrFYWhqrNgrUNEY92u81SPhu7sTdzQEiWY= +github.com/gorilla/mux v1.8.1/go.mod h1:AKf9I4AEqPTmMytcMc0KkNouC66V3BtZ4qD5fmWSiMQ= 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/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= @@ -14,8 +14,8 @@ github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSS github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= -github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8= -github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= +github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= +github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= 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.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/server.go b/server.go index 8f03098..7a271b3 100644 --- a/server.go +++ b/server.go @@ -2,7 +2,6 @@ package main import ( "encoding/json" - "io/ioutil" "log" "net/http" "os" @@ -71,7 +70,7 @@ func handler(w http.ResponseWriter, req *http.Request) { response.Files = make(map[string]string) files := strings.Split(showFiles, ",") for _, file := range files { - bytes, err := ioutil.ReadFile(file) + bytes, err := os.ReadFile(file) if err != nil { log.Printf("Could not read file %v: %v\n", file, err) continue diff --git a/server_test.go b/server_test.go index 7a0e7b0..b2493e2 100644 --- a/server_test.go +++ b/server_test.go @@ -1,6 +1,7 @@ package main import ( + "bytes" "encoding/json" "net/http" "net/http/httptest" @@ -29,8 +30,12 @@ func TestHandler(t *testing.T) { t.Errorf("handler returned wrong status code: got %v want %v", status, http.StatusOK) } + result := rr.Result() + buf := new(bytes.Buffer) + buf.ReadFrom(result.Body) + var response response - json.Unmarshal(rr.Body.Bytes(), &response) + json.Unmarshal(buf.Bytes(), &response) // test response assert.Equal(t, 1, response.Counter) @@ -43,5 +48,5 @@ func TestHandler(t *testing.T) { assert.NotEmpty(t, response.Files[".gitignore"]) // test cors - assert.Contains(t, rr.HeaderMap["Access-Control-Allow-Origin"], "*") + assert.Contains(t, result.Header["Access-Control-Allow-Origin"], "*") }