-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
302 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
/*.csv | ||
/.idea/ | ||
/*.iml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,5 +3,5 @@ package main | |
import "testing" | ||
|
||
func TestMain(m *testing.M) { | ||
// TODO | ||
// TODO add tests | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,21 @@ | ||
module air-pollution-service | ||
|
||
go 1.22 | ||
go 1.22.0 | ||
|
||
toolchain go1.22.5 | ||
|
||
require ( | ||
github.com/go-chi/chi/v5 v5.1.0 | ||
github.com/go-chi/render v1.0.3 | ||
github.com/gocarina/gocsv v0.0.0-20240520201108-78e41c74b4b1 | ||
github.com/joeshaw/envdecode v0.0.0-20200121155833-099f1fc765bd | ||
github.com/montanaflynn/stats v0.7.1 | ||
github.com/stretchr/testify v1.9.0 | ||
) | ||
|
||
require github.com/ajg/form v1.5.1 // indirect | ||
require ( | ||
github.com/ajg/form v1.5.1 // indirect | ||
github.com/davecgh/go-spew v1.1.1 // indirect | ||
github.com/pmezard/go-difflib v1.0.0 // indirect | ||
gopkg.in/yaml.v3 v3.0.1 // indirect | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
github.com/ajg/form v1.5.1 h1:t9c7v8JUKu/XxOGBU0yjNpaMloxGEJhUkqFRq0ibGeU= | ||
github.com/ajg/form v1.5.1/go.mod h1:uL1WgH+h2mgNtvBq0339dVnzXdBETtL2LeUXaIv25UY= | ||
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-chi/chi/v5 v5.1.0 h1:acVI1TYaD+hhedDJ3r54HyA6sExp3HfXq7QWEEY/xMw= | ||
github.com/go-chi/chi/v5 v5.1.0/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8= | ||
github.com/go-chi/render v1.0.3 h1:AsXqd2a1/INaIfUSKq3G5uA8weYx20FOsM7uSoCyyt4= | ||
github.com/go-chi/render v1.0.3/go.mod h1:/gr3hVkmYR0YlEy3LxCuVRFzEu9Ruok+gFqbIofjao0= | ||
github.com/gocarina/gocsv v0.0.0-20240520201108-78e41c74b4b1 h1:FWNFq4fM1wPfcK40yHE5UO3RUdSNPaBC+j3PokzA6OQ= | ||
github.com/gocarina/gocsv v0.0.0-20240520201108-78e41c74b4b1/go.mod h1:5YoVOkjYAQumqlV356Hj3xeYh4BdZuLE0/nRkf2NKkI= | ||
github.com/joeshaw/envdecode v0.0.0-20200121155833-099f1fc765bd h1:nIzoSW6OhhppWLm4yqBwZsKJlAayUu5FGozhrF3ETSM= | ||
github.com/joeshaw/envdecode v0.0.0-20200121155833-099f1fc765bd/go.mod h1:MEQrHur0g8VplbLOv5vXmDzacSaH9Z7XhcgsSh1xciU= | ||
github.com/montanaflynn/stats v0.7.1 h1:etflOAAHORrCC44V+aR6Ftzort912ZU+YLiSTuV8eaE= | ||
github.com/montanaflynn/stats v0.7.1/go.mod h1:etXPPgVO6n31NxCd9KQUMvCM+ve0ruNzt6R8Bnaayow= | ||
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/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= | ||
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= | ||
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.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= | ||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,5 +3,5 @@ package csv | |
import "testing" | ||
|
||
func TestCSV(t *testing.T) { | ||
// TODO | ||
// TODO add tests | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,81 @@ | ||
package resource | ||
|
||
import "testing" | ||
import ( | ||
"air-pollution-service/internal/model" | ||
"context" | ||
"encoding/json" | ||
"github.com/go-chi/chi/v5" | ||
"github.com/stretchr/testify/assert" | ||
"io/ioutil" | ||
"net/http" | ||
"net/http/httptest" | ||
"testing" | ||
) | ||
|
||
func TestCountries(t *testing.T) { | ||
// TODO | ||
type fakeCountryStorage struct { | ||
countries []*model.Country | ||
} | ||
|
||
func (s fakeCountryStorage) FindAllByYears() map[int][]*model.Emissions { | ||
return nil | ||
} | ||
|
||
func (s fakeCountryStorage) FindAllByCountries() map[string][]*model.Emissions { | ||
return nil | ||
} | ||
|
||
func (s fakeCountryStorage) FindAllByCountry(name string) map[int]*model.Emissions { | ||
return nil | ||
} | ||
|
||
func (s fakeCountryStorage) GetCountry(name string) *model.Country { | ||
if len(s.countries) == 0 { | ||
return nil | ||
} | ||
return s.countries[0] | ||
} | ||
|
||
func (s fakeCountryStorage) GetCountries() []*model.Country { | ||
return s.countries | ||
} | ||
|
||
func TestCountriesGetNonExisting(t *testing.T) { | ||
w := httptest.NewRecorder() | ||
req := httptest.NewRequest(http.MethodGet, "/", nil) | ||
ctx := chi.NewRouteContext() | ||
req = req.WithContext(context.WithValue(req.Context(), chi.RouteCtxKey, ctx)) | ||
ctx.URLParams.Add("name", "Schlaraffenland") | ||
countryHandler := CountryResource{Storage: fakeCountryStorage{[]*model.Country{}}} | ||
|
||
countryHandler.Get(w, req) | ||
res := w.Result() | ||
defer res.Body.Close() | ||
_, err := ioutil.ReadAll(res.Body) | ||
assert.Nil(t, err) | ||
assert.Equal(t, 404, res.StatusCode) | ||
} | ||
|
||
func TestCountriesGetExisting(t *testing.T) { | ||
w := httptest.NewRecorder() | ||
req := httptest.NewRequest(http.MethodGet, "/", nil) | ||
ctx := chi.NewRouteContext() | ||
req = req.WithContext(context.WithValue(req.Context(), chi.RouteCtxKey, ctx)) | ||
ctx.URLParams.Add("name", "Schlaraffenland") | ||
countryHandler := CountryResource{Storage: fakeCountryStorage{[]*model.Country{{ | ||
Name: "Schlaraffenland", | ||
Code: "SCH", | ||
}}}} | ||
|
||
countryHandler.Get(w, req) | ||
res := w.Result() | ||
defer res.Body.Close() | ||
data, err := ioutil.ReadAll(res.Body) | ||
assert.Nil(t, err) | ||
assert.Equal(t, 200, res.StatusCode) | ||
|
||
country := countryResponse{} | ||
err = json.Unmarshal(data, &country) | ||
assert.Nil(t, err) | ||
assert.Equal(t, "Schlaraffenland", country.Name) | ||
assert.Equal(t, "SCH", country.Code) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.