Merge pull request #82 from lukaszbudnik/updating-deprecated-methods-fields
updated deprecated API
This commit is contained in:
@@ -2,7 +2,6 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"io/ioutil"
|
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
@@ -71,7 +70,7 @@ func handler(w http.ResponseWriter, req *http.Request) {
|
|||||||
response.Files = make(map[string]string)
|
response.Files = make(map[string]string)
|
||||||
files := strings.Split(showFiles, ",")
|
files := strings.Split(showFiles, ",")
|
||||||
for _, file := range files {
|
for _, file := range files {
|
||||||
bytes, err := ioutil.ReadFile(file)
|
bytes, err := os.ReadFile(file)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Could not read file %v: %v\n", file, err)
|
log.Printf("Could not read file %v: %v\n", file, err)
|
||||||
continue
|
continue
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"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)
|
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
|
var response response
|
||||||
json.Unmarshal(rr.Body.Bytes(), &response)
|
json.Unmarshal(buf.Bytes(), &response)
|
||||||
|
|
||||||
// test response
|
// test response
|
||||||
assert.Equal(t, 1, response.Counter)
|
assert.Equal(t, 1, response.Counter)
|
||||||
@@ -43,5 +48,5 @@ func TestHandler(t *testing.T) {
|
|||||||
assert.NotEmpty(t, response.Files[".gitignore"])
|
assert.NotEmpty(t, response.Files[".gitignore"])
|
||||||
|
|
||||||
// test cors
|
// test cors
|
||||||
assert.Contains(t, rr.HeaderMap["Access-Control-Allow-Origin"], "*")
|
assert.Contains(t, result.Header["Access-Control-Allow-Origin"], "*")
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user