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 / 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 / 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 / testable9.go
Created May 4, 2020 19:42
testable9.go
package testable_test
import (
"testing"
"github.com/plutov/packagemain/19-testable-go-code/testable"
)
// ...
@plutov
plutov / testable8.go
Created May 4, 2020 19:42
testable8.go
// ...
mock := new(Mock)
got, err := GetAverageStarsPerRepo(mock, tt.username)
// ...
@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 / 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 / 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"
)