Skip to content

Commit

Permalink
Merge pull request #82 from lukaszbudnik/updating-deprecated-methods-…
Browse files Browse the repository at this point in the history
…fields

updated deprecated API
  • Loading branch information
lukaszbudnik committed Nov 14, 2023
2 parents ac599cd + 2a3c680 commit 0245cda
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
3 changes: 1 addition & 2 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package main

import (
"encoding/json"
"io/ioutil"
"log"
"net/http"
"os"
Expand Down Expand Up @@ -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
Expand Down
9 changes: 7 additions & 2 deletions server_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"bytes"
"encoding/json"
"net/http"
"net/http/httptest"
Expand Down Expand Up @@ -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)
Expand All @@ -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"], "*")
}

0 comments on commit 0245cda

Please sign in to comment.