Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ go:
- 1.x
- tip
install:
- export GOCACHE=$GOPATH/pkg/cache
- make testdeps
script:
- export GOCACHE=$GOPATH/pkg/cache
- make coverage
- go build -o video-transcoding-api
after_success:
Expand Down
15 changes: 13 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,22 @@ all: test

testdeps:
GO111MODULE=off go get github.com/go-swagger/go-swagger/cmd/swagger
go get github.com/golangci/golangci-lint/cmd/golangci-lint@master
GO111MODULE=off go get github.com/golangci/golangci-lint/cmd/golangci-lint
go mod download

lint: testdeps
golangci-lint run --fast -D errcheck -E megacheck --deadline 5m ./...
golangci-lint run \
--enable-all \
-D errcheck \
-D lll \
-D gochecknoglobals \
-D goconst \
-D gocyclo \
-D dupl \
-D gocritic \
-D gochecknoinits \
-D unparam \
--deadline 5m ./...

gotest: testdeps
go test ./...
Expand Down
2 changes: 1 addition & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package config
import (
"github.com/NYTimes/gizmo/server"
"github.com/NYTimes/video-transcoding-api/db/redis/storage"
"github.com/fsouza/gizmo-stackdriver-logging"
logging "github.com/fsouza/gizmo-stackdriver-logging"
"github.com/kelseyhightower/envconfig"
)

Expand Down
2 changes: 1 addition & 1 deletion config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

"github.com/NYTimes/gizmo/server"
"github.com/NYTimes/video-transcoding-api/db/redis/storage"
"github.com/fsouza/gizmo-stackdriver-logging"
logging "github.com/fsouza/gizmo-stackdriver-logging"
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
)
Expand Down
5 changes: 5 additions & 0 deletions db/redis/job_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ func TestListJobs(t *testing.T) {
}
expectedJobs := make([]db.Job, len(jobs))
for i, job := range jobs {
job := job
err = repo.CreateJob(&job)
if err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -297,6 +298,7 @@ func TestListJobsLimit(t *testing.T) {
limit := 2
expectedJobs := make([]db.Job, limit)
for i, job := range jobs {
job := job
err = repo.CreateJob(&job)
if err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -352,6 +354,7 @@ func TestListJobsInconsistency(t *testing.T) {
redisRepo.storage.RedisClient().ZAddNX("some-weird-id2", redis.Z{Member: jobs[1], Score: math.Inf(0)})
expectedJobs := make([]db.Job, len(jobs))
for i, job := range jobs {
job := job
err = repo.CreateJob(&job)
if err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -409,6 +412,7 @@ func TestListJobsFiltering(t *testing.T) {
since := now.Add(-59 * time.Minute)
redisRepo := repo.(*redisRepository)
for _, job := range jobs {
job := job
err = redisRepo.saveJob(&job)
if err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -469,6 +473,7 @@ func TestListJobsFilteringAndLimit(t *testing.T) {
since := now.Add(-59 * time.Minute)
redisRepo := repo.(*redisRepository)
for _, job := range jobs {
job := job
err = redisRepo.saveJob(&job)
if err != nil {
t.Fatal(err)
Expand Down
32 changes: 15 additions & 17 deletions db/redis/storage/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,24 +160,22 @@ func (s *Storage) structToFieldList(value reflect.Value, prefixes ...string) (ma
default:
return nil, errors.New("can only expand structs and maps")
}
} else {
if parts[0] != "" {
key := strings.Join(append(prefixes, parts[0]), "_")
var strValue string
iface := fieldValue.Interface()
switch v := iface.(type) {
case time.Time:
strValue = v.Format(time.RFC3339Nano)
case []string:
strValue = strings.Join(v, "%%%")
default:
strValue = fmt.Sprintf("%v", v)
}
if parts[len(parts)-1] == "omitempty" && strValue == "" {
continue
}
fields[key] = strValue
} else if parts[0] != "" {
key := strings.Join(append(prefixes, parts[0]), "_")
var strValue string
iface := fieldValue.Interface()
switch v := iface.(type) {
case time.Time:
strValue = v.Format(time.RFC3339Nano)
case []string:
strValue = strings.Join(v, "%%%")
default:
strValue = fmt.Sprintf("%v", v)
}
if parts[len(parts)-1] == "omitempty" && strValue == "" {
continue
}
fields[key] = strValue
}
}
return fields, nil
Expand Down
Loading