Skip to content

Commit

Permalink
Remove dependencies (and Glide) (#56)
Browse files Browse the repository at this point in the history
* Remove dependencies (and Glide)

* Moved remaining tests away from Testify

* Fixed up code review comments

* Put 'working_directory' back in
  • Loading branch information
thomshutt authored and stuarthicks committed Mar 7, 2019
1 parent c91430c commit 3a86f74
Show file tree
Hide file tree
Showing 12 changed files with 319 additions and 443 deletions.
16 changes: 0 additions & 16 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,4 @@ jobs:
working_directory: "/go/src/github.com/zencoder/go-dash"
steps:
- checkout
- run:
name: Install Glide
command: |
set -eux
curl -sSLfO https://github.com/Masterminds/glide/releases/download/v0.12.3/glide-v0.12.3-linux-amd64.tar.gz
mkdir -p /go/bin glide
tar -xzf glide-v0.12.3-linux-amd64.tar.gz -C ./glide
cp ./glide/linux-amd64/glide /go/bin/glide
rm -rf glide glide-v0.12.3-linux-amd64.tar.gz
- restore_cache:
key: glide-{{ checksum "glide.lock" }}
- run: /go/bin/glide install
- save_cache:
key: glide-{{ checksum "glide.lock" }}
paths:
- vendor
- run: make test
12 changes: 4 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,18 @@ endif
.PHONY: all
all: test

vendor:
glide install

.PHONY: test
test: vendor
test:
go test $(V) ./... -race

.PHONY: generate
generate: vendor
GENERATE_FIXTURES=true $(MAKE) test
generate: export GENERATE_FIXTURES=true
generate: test

.PHONY: fmt
fmt:
find . -not -path "./vendor/*" -name '*.go' -type f | sed 's#\(.*\)/.*#\1#' | sort -u | xargs -n1 -I {} bash -c "cd {} && goimports -w *.go && gofmt -w -s -l *.go"
go fmt $(X) ./...

.PHONY: clean
clean:
rm -rf vendor/
go clean -i $(X) -cache -testcache
17 changes: 0 additions & 17 deletions glide.lock

This file was deleted.

6 changes: 0 additions & 6 deletions glide.yaml

This file was deleted.

189 changes: 189 additions & 0 deletions helpers/require/require.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
package require

import (
"reflect"
"testing"
)

func NoError(t *testing.T, err error, msgs ...string) {
if err != nil {
t.Errorf("Expected no error, but got: %s", err)
for _, msg := range msgs {
t.Errorf("\n" + msg)
}
t.FailNow()
}
}

func NotNil(t *testing.T, object interface{}, msgs ...string) {
if isNil(object) {
t.Errorf("Expected nil, but got an object")
for _, msg := range msgs {
t.Errorf("\n" + msg)
}
t.FailNow()
}
}

func Nil(t *testing.T, object interface{}, msgs ...string) {
if !isNil(object) {
t.Errorf("Expected an object, but got nil")
for _, msg := range msgs {
t.Errorf("\n" + msg)
}
t.FailNow()
}
}

func isNil(object interface{}) bool {
if object == nil {
return true
}

value := reflect.ValueOf(object)
kind := value.Kind()
if kind >= reflect.Chan && kind <= reflect.Slice && value.IsNil() {
return true
}

return false
}

func EqualError(t *testing.T, theError error, errString string, msgs ...string) {
if theError == nil {
t.Errorf("Expected an error but got nil")
for _, msg := range msgs {
t.Errorf("\n" + msg)
}
t.FailNow()
return
}

if theError.Error() != errString {
t.Errorf("Expected an error with message:\n%qbut got \n%q", errString, theError)
for _, msg := range msgs {
t.Errorf("\n" + msg)
}
t.FailNow()
}
}

func EqualFloat64(t *testing.T, expected, actual float64, msgs ...string) {
if expected != actual {
t.Errorf("Expected %f but got %f", expected, actual)
for _, msg := range msgs {
t.Errorf("\n" + msg)
}
t.FailNow()
}
}

func EqualStringPtr(t *testing.T, expected, actual *string, msgs ...string) {
if expected == nil && actual == nil {
return
}
if expected != nil && actual != nil {
EqualString(t, *expected, *actual, msgs...)
return
}

t.Errorf("Expected %v but got %v", expected, actual)
for _, msg := range msgs {
t.Errorf("\n" + msg)
}
t.FailNow()
}

func EqualString(t *testing.T, expected, actual string, msgs ...string) {
if expected != actual {
t.Errorf("Expected %s but got %s", expected, actual)
for _, msg := range msgs {
t.Errorf("\n" + msg)
}
t.FailNow()
}
}

func EqualUInt32(t *testing.T, expected, actual uint32, msgs ...string) {
if expected != actual {
t.Errorf("Expected %d but got %d", expected, actual)
for _, msg := range msgs {
t.Errorf("\n" + msg)
}
t.FailNow()
}
}

func EqualUInt64Ptr(t *testing.T, expected, actual *uint64, msgs ...string) {
if expected == nil && actual == nil {
return
}
if expected != nil && actual != nil {
EqualUInt64(t, *expected, *actual, msgs...)
return
}

t.Errorf("Expected %v but got %v", expected, actual)
for _, msg := range msgs {
t.Errorf("\n" + msg)
}
t.FailNow()
}

func EqualUInt64(t *testing.T, expected, actual uint64, msgs ...string) {
if expected != actual {
t.Errorf("Expected %d but got %d", expected, actual)
for _, msg := range msgs {
t.Errorf("\n" + msg)
}
t.FailNow()
}
}

func EqualIntPtr(t *testing.T, expected, actual *int, msgs ...string) {
if expected == nil && actual == nil {
return
}
if expected != nil && actual != nil {
EqualInt(t, *expected, *actual, msgs...)
return
}

t.Errorf("Expected %v but got %v", expected, actual)
for _, msg := range msgs {
t.Errorf("\n" + msg)
}
t.FailNow()
}

func EqualInt(t *testing.T, expected, actual int, msgs ...string) {
if expected != actual {
t.Errorf("Expected %d but got %d", expected, actual)
for _, msg := range msgs {
t.Errorf("\n" + msg)
}
t.FailNow()
}
}

func EqualErr(t *testing.T, expected, actual error, msgs ...string) {
if expected != actual {
t.Errorf("Expected %s but got %s", expected, actual)
for _, msg := range msgs {
t.Errorf("\n" + msg)
}
t.FailNow()
}
}

func Implements(t *testing.T, interfaceObject interface{}, object interface{}, msgs ...string) {
interfaceType := reflect.TypeOf(interfaceObject).Elem()

if !reflect.TypeOf(object).Implements(interfaceType) {
t.Errorf("Expected %T but got %v", object, interfaceType)
for _, msg := range msgs {
t.Errorf("\n" + msg)
}
t.FailNow()
}
}
4 changes: 2 additions & 2 deletions helpers/testfixtures/testfixtures.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"os"
"testing"

"github.com/stretchr/testify/require"
"github.com/zencoder/go-dash/helpers/require"
)

// Load test fixture from path relative to fixtures directory
Expand All @@ -25,5 +25,5 @@ func CompareFixture(t *testing.T, fixturePath string, actualContent string) {
fmt.Println("Wrote fixture: " + fixturePath)
return
}
require.Equal(t, expectedContent, actualContent)
require.EqualString(t, expectedContent, actualContent)
}
11 changes: 6 additions & 5 deletions mpd/duration_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package mpd

import (
"fmt"
"testing"
"time"

"github.com/stretchr/testify/require"
"github.com/zencoder/go-dash/helpers/require"
)

func TestDuration(t *testing.T) {
Expand All @@ -15,9 +16,9 @@ func TestDuration(t *testing.T) {
}
for ins, ex := range in {
timeDur, err := time.ParseDuration(ins)
require.Equal(t, nil, err)
require.NoError(t, err)
dur := Duration(timeDur)
require.Equal(t, ex, dur.String())
require.EqualString(t, ex, dur.String())
}
}

Expand All @@ -37,7 +38,7 @@ func TestParseDuration(t *testing.T) {
for ins, ex := range in {
act, err := parseDuration(ins)
require.NoError(t, err, ins)
require.Equal(t, ex, act.Seconds(), ins)
require.EqualFloat64(t, ex, act.Seconds(), ins)
}
}

Expand All @@ -54,6 +55,6 @@ func TestParseBadDurations(t *testing.T) {
}
for ins, msg := range in {
_, err := parseDuration(ins)
require.EqualError(t, err, msg, "Expected an error for: %s", ins)
require.EqualError(t, err, msg, fmt.Sprintf("Expected an error for: %s", ins))
}
}
Loading

0 comments on commit 3a86f74

Please sign in to comment.