This file contains hidden or 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
var runner runner | |
r := defaultRunner{url} | |
if dryRun { | |
runner = &dryRunner{&r} | |
} else { | |
runner = &fileRunner{&r, "output.txt"} | |
} |
This file contains hidden or 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
package cmd | |
import ( | |
"log" | |
"os" | |
"github.com/RicardoLinck/decorators/cache" | |
"github.com/RicardoLinck/decorators/service" | |
) |
This file contains hidden or 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
package fetch | |
import ( | |
"context" | |
"time" | |
) | |
type PartnerFetcher struct { | |
partners map[string]int | |
} |
This file contains hidden or 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
package fetch | |
import ( | |
"context" | |
"encoding/json" | |
"errors" | |
"fmt" | |
"net/http" | |
) |
This file contains hidden or 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
package fetch | |
import ( | |
"context" | |
"log" | |
) | |
// Result represents the result of a fetcher | |
type Result struct { | |
Key string |
This file contains hidden or 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
package main | |
import ( | |
"context" | |
"fmt" | |
"log" | |
"time" | |
"github.com/RicardoLinck/scatter-gather/fetch" | |
"github.com/RicardoLinck/scatter-gather/nameservice" |
This file contains hidden or 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
func Test_FetchData(t *testing.T) { | |
router := http.NewServeMux() | |
router.HandleFunc("/api/v1/some-data", func(w http.ResponseWriter, r *http.Request) { | |
if r.Method != "GET" { | |
w.WriteHeader(http.StatusBadRequest) | |
return | |
} | |
w.Write([]byte(`{"user_name":"test_user", | |
"dob":"1999-05-23T18:25:43.511Z", | |
"fav_sports":[{"name":"football","order":2},{"name":"hockey", "order":1}]}`)) |
This file contains hidden or 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
// Configuration contain parameters to call the api | |
type Configuration struct { | |
baseURL string | |
apiVersion int | |
} | |
// FetchData fetches the data from the api using the configuration | |
func (c Configuration) FetchData() (Person, error) { | |
person := Person{} | |
endpoint, decoderFunc, err := getEndpointAndDecodeFunc(c.apiVersion) |
This file contains hidden or 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
func TestConfiguration_FetchData(t *testing.T) { | |
t.Run("errors when invalid api version", func(t *testing.T) { | |
c := Configuration{ | |
baseURL: "", | |
apiVersion: 3, | |
fetcher: nil, | |
} | |
_, err := c.FetchData() | |
assert.Error(t, ErrInvalidAPIVersion, err) | |
}) |
This file contains hidden or 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
func TestConfiguration_FetchData(t *testing.T) { | |
errFromFetcher := errors.New("mock error") | |
type fields struct { | |
baseURL string | |
apiVersion int | |
fetcherFunc func(string) (io.ReadCloser, error) | |
} | |
tests := []struct { | |
name string | |
fields fields |
NewerOlder