Skip to content

Instantly share code, notes, and snippets.

View plutov's full-sized avatar
🎥
https://www.youtube.com/packagemain

Alex Pliutau plutov

🎥
https://www.youtube.com/packagemain
View GitHub Profile
@plutov
plutov / testable7.go
Created May 4, 2020 19:41
testable7.go
func GetAverageStarsPerRepo(repositoriesAPI RepositoriesAPI, username string) (float64, error) {
repos, err := repositoriesAPI.GetRepos(username)
if err != nil {
return 0, err
}
// ...
}
@plutov
plutov / testable6.go
Last active May 4, 2020 19:43
testable6.go
package testable
import (
"encoding/json"
"fmt"
"net/http"
)
type Repo struct {
StargazersCount int `json:"stargazers_count"`
@plutov
plutov / testable5.go
Created May 4, 2020 19:40
testable5.go
func TestGetAverageStarsPerRepo(t *testing.T) {
var tests = []struct {
username string
want float64
}{
{"octocat", 1480.375000},
{"plutov", 15.566667},
}
for _, tt := range tests {
@plutov
plutov / testable4.go
Last active May 4, 2020 19:43
testable4.go
type Repo struct {
StargazersCount int `json:"stargazers_count"`
}
func GetAverageStarsPerRepo(username string) (float64, error) {
res, err := http.Get(fmt.Sprintf("https://api.github.com/users/%s/repos", username))
if err != nil {
return 0, err
}
@plutov
plutov / testable3.go
Created May 4, 2020 19:39
testable3.go
func TestStrInSlice(t *testing.T) {
var tests = []struct{
slice []string
find string
want bool
}{
{[]string{"a", "b"}, "c", false},
{[]string{"a", "b"}, "a", true},
}
@plutov
plutov / testable2.go
Created May 4, 2020 19:39
testable2.go
func TestStrInSlice(t *testing.T) {
got := StrInSlice([]string{"a", "b"}, "c")
if got == true {
t.Errorf("expecting false, got true")
}
}
@plutov
plutov / testable1.go
Created May 4, 2020 19:38
testable1.go
func StrInSlice(slice []string, find string) bool {
for _, v := range slice {
if v == find {
return true
}
}
return false
}
@plutov
plutov / api-client-7.go
Created April 27, 2020 10:44
api-client-7.go
// +build integration
package facest
import (
"os"
"testing"
"github.com/stretchr/testify/assert"
)
@plutov
plutov / api-client-6.go
Created April 27, 2020 10:44
api-client-6.go
func (c *Client) sendRequest(req *http.Request, v interface{}) error {
req.Header.Set("Content-Type", "application/json; charset=utf-8")
req.Header.Set("Accept", "application/json; charset=utf-8")
req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", c.apiKey))
res, err := c.HTTPClient.Do(req)
if err != nil {
return err
}
@plutov
plutov / api-client-5.go
Created April 27, 2020 10:43
api-client-5.go
func (c *Client) GetFaces(ctx context.Context, options *FacesListOptions) (*FacesList, error) {
limit := 100
page := 1
if options != nil {
limit = options.Limit
page = options.Page
}
req, err := http.NewRequest("GET", fmt.Sprintf("%s/faces?limit=%d&page=%d", c.BaseURL, limit, page), nil)
if err != nil {