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 setupTest(t *testing.T) *require.Assertions { | |
assert := require.New(t) | |
cleanupTestCalls() | |
setupTestSynq() | |
return assert | |
} | |
func cleanupTestCalls() { | |
db.MustExec("TRUNCATE api_calls") | |
} |
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 TestDetails(t *testing.T) { | |
assert := setupTest(t) | |
test_helper.RunSimplePost("/v1/details", "", | |
func(c *gin.Context) { | |
details(c) | |
}, | |
func(r *httptest.ResponseRecorder) { | |
assert.Equal(400, r.Code) | |
resp := test_helper.ParseJson(r.Body) | |
assert.Equal("missing 'video_id'", resp["message"]) |
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 (v Video) Value() (driver.Value, error) { | |
json, err := json.Marshal(v) | |
return json, err | |
} | |
func (v *Video) Scan(src interface{}) error { | |
source, ok := src.([]byte) | |
if !ok { | |
return errors.New("Type assertion .([]byte) failed.") | |
} |
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 setupRouter(port string) { | |
router := gin.Default() | |
v1 := router.Group("/v1") | |
{ | |
v1.POST("/details", details) | |
v1.GET("/status", status) | |
} | |
log.Println("Running server on port :", port) | |
serverStarted = time.Now() |
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 will just get the video id and call the Synq api for the details | |
func details(c *gin.Context) { | |
a := ApiCall{} | |
c.BindJSON(&a) | |
if a.VideoId == "" { | |
c.JSON(400, gin.H{ | |
"message": "missing 'video_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 (a *ApiCall) Call() error { | |
defer a.Save() | |
start := time.Now() | |
video, err := sApi.GetVideo(a.VideoId) | |
a.Taken = time.Since(start) | |
if err != nil { | |
a.Error = err.Error() | |
return err | |
} | |
a.Type = "/v1/video/details" |
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 ApiCall struct { | |
Id int64 `db:"id" json:"id"` | |
Type string `db:"type" json:"type"` | |
CreatedAt time.Time `db:"ctime" json:"-"` | |
Called time.Time `db:"called" json:"called"` | |
VideoId string `db:"video_id" json:"video_id"` | |
Taken time.Duration `db:"taken" json:"taken"` | |
Error string `db:"error" json:"error"` | |
Video synq.Video `db:"result" json:"video"` | |
} |
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
{ | |
"flyway": { | |
"password": "supersecret" | |
} | |
} |
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
- run: | |
name: Run Golang Tests | |
command: | | |
GOPATH=$GOPATH:"${SYNQ_DIR}"/"${REPO}"/vendor overalls -project=github.com/SYNQfm/"${REPO}" -covermode=atomic -debug -ignore=.git,.github,.circleci,vendor,sql,sample -- -race -v | |
if [ -z ${COVERALLS_TOKEN} ]; then | |
echo "coveralls token isn't set, skipping" | |
else | |
goveralls -coverprofile="${SYNQ_DIR}"/"${REPO}"/overalls.coverprofile -service circle-ci -repotoken "${COVERALLS_TOKEN}" | |
fi |
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
- run: | |
name: Waiting for Postgres to be ready | |
command: | | |
for i in `seq 1 10`; | |
do | |
psql -h localhost -U $PG_USER $PG_DB -c "\t" && echo DB Up && exit 0 | |
echo -n . | |
sleep 1 | |
done | |
echo Failed waiting for Postgres && exit 1 |
NewerOlder