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
// specifically creates a closure to handle specific error class with a given error handler | |
// it rethrows all other errors | |
const specifically = (errorClass) => (errHandler) => (err) => { | |
if (err instanceof errorClass) { | |
return errHandler(err) | |
} | |
throw err | |
} |
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
#!/bin/bash | |
# Sync Homebrew installations between Macs via Dropbox | |
# | |
BREW="/usr/local/bin/brew" | |
# first get local settings | |
echo "Reading local settings ..." | |
rm -f /tmp/brew-sync.* |
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
func (r *AccountRepository) UpdateAccount(id string, data map[string]interface{}) (*Account, error) { | |
_, err := r.proxy.HMSet(id, data) | |
if err != nil { | |
return nil, err | |
} else { | |
return r.FetchAccount(id) | |
} | |
} |
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
func TestUpdateAccountUpdatesAccountWithNewData(t *testing.T) { | |
repository := createRepositoryWithData(fakeData) | |
newBalance := "200" | |
updateValue := map[string]interface{}{"Balance": newBalance} | |
account, err := repository.UpdateAccount(id, updateValue) | |
assert.Equal(t, id, account.Id) | |
assert.Equal(t, "John Doe", account.Name) |
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
func (r *AccountRepository) FetchAccount(id string) (*Account, error) { | |
data, err := r.client.HGetAll(id) | |
if err != nil { | |
return nil, err | |
} | |
return toAccount(data) | |
} | |
type Account struct { |
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
package main | |
import ( | |
"strconv" | |
"errors" | |
) | |
type AccountRepository struct { | |
client RedisProxy | |
} |
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
package main | |
import "github.com/go-redis/redis" | |
type Redis struct { | |
*redis.Client | |
} | |
func (r *Redis) HGetAll(key string) (map[string]string, error) { | |
return r.Client.HGetAll(key).Result() |
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
func TestFetchAccountWhenAccountExists(t *testing.T) { | |
repository := createRepositoryWithData(fakeData) | |
account, err := repository.FetchAccount(id) | |
assert.Equal(t, id, account.Id) | |
assert.Equal(t, "John Doe", account.Name) | |
assert.Equal(t, 100, account.Balance) | |
assert.Nil(t, err) | |
} |
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
package main | |
import ( | |
"testing" | |
"github.com/stretchr/testify/assert" | |
) | |
type stubRedis struct { | |
data map[string]string | |
err error |
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
type RedisProxy interface { | |
HGetAll(string) (map[string]string, error) | |
HMSet(string, map[string]interface{}) (string, error) | |
} |
NewerOlder