Skip to content

Commit

Permalink
change if in test to assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
aldor007 committed Sep 29, 2017
1 parent b735a4a commit 0e2aaf2
Show file tree
Hide file tree
Showing 3 changed files with 149 additions and 3 deletions.
2 changes: 1 addition & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func GetInstance() *Config {
return instance
}

func (self *Config) Init(filePath string) {
func (self *Config) Load(filePath string) {
data, err := ioutil.ReadFile(filePath)
if err != nil {
panic(err)
Expand Down
134 changes: 134 additions & 0 deletions object/file_object_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
package object

import (
"testing"

"github.com/stretchr/testify/assert"

"mort/config"
)

func TestNewFileObjectWhenUnknowBucket(t *testing.T) {
mortConfig := config.GetInstance()
_, err := NewFileObject("/bucket/path", mortConfig)

assert.NotNil(t, err)
}

func TestNewFileObjectNoTransform(t *testing.T) {
mortConfig := config.GetInstance()
mortConfig.Load("testdata/bucket-no-transform.yml")
obj, err := NewFileObject("/bucket/path", mortConfig)

assert.Nil(t, err)

assert.NotNil(t, obj)

if obj.HasParent() {
t.Errorf("Obj shouldn't have parent")
}

if obj.Storage.Kind != "local" {
t.Errorf("obj should have storage with kind of local")
}

}

func TestNewFileObjectTransform(t *testing.T) {
mortConfig := config.GetInstance()
mortConfig.Load("testdata/bucket-transform.yml")
obj, err := NewFileObject("/bucket/blog_small/bucket/parent.jpg", mortConfig)

if err != nil {
t.Errorf("Unexpected to have error when parsing path")
}

if obj == nil {
t.Errorf("Obj shouldn't be nil")
}

if !obj.HasParent() {
t.Errorf("Obj should have parent")
t.FailNow()
}

parent := obj.Parent
if parent.Key != "/parent.jpg" {
t.Errorf("Invalid parent key %s", parent.Key)

}

if parent.HasParent() {
t.Errorf("Parent shouldn't have parent")
}

if !obj.HasTransform() {
t.Errorf("Object should have transformss")
}

transCfg := obj.Transforms.BimgOptions()

if transCfg.Width != 100 {
t.Errorf("Transform should have 100 px on witdh but has %s", transCfg.Width)
}

if transCfg.Height != 100 {
t.Errorf("Transform should have 100 px on witdh but has %s", transCfg.Width)
}

}

func TestNewFileObjectTransformOnlyWitdh(t *testing.T) {
mortConfig := config.GetInstance()
mortConfig.Load("testdata/bucket-transform.yml")
obj, err := NewFileObject("/bucket/width/bucket/parent.jpg", mortConfig)

if err != nil {
t.Errorf("Unexpected to have error when parsing path")
}

if obj == nil {
t.Errorf("Obj shouldn't be nil")
}

transCfg := obj.Transforms.BimgOptions()

if transCfg.Width != 100 {
t.Errorf("Transform should have 100 px on witdh but has %s", transCfg.Width)
}

if transCfg.Height != 0 {
t.Errorf("Transform should have 100 px on witdh but has %s", transCfg.Width)
}

}

func TestNewFileObjecWithNestedParent(t *testing.T) {
mortConfig := config.GetInstance()
mortConfig.Load("testdata/bucket-transform.yml")
obj, err := NewFileObject("/bucket/width/bucket/height/parent.jpg", mortConfig)

if err != nil {
t.Errorf("Unexpected to have error when parsing path")
}

if obj == nil {
t.Errorf("Obj shouldn't be nil")
}

if !obj.HasParent() {
t.Errorf("Obj should have parent")
t.FailNow()
}

parent := obj.Parent

if !parent.HasParent() {
t.Errorf("Parent shouldn't have parent")
}

if parent.Parent.Key != "/parent.jpg" {
t.Errorf("Parent should have parent /parent.jpg %s", parent.Parent.Key)
}

}
16 changes: 14 additions & 2 deletions object/testdata/bucket-transform.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
buckets:
bucket:
transform:
path: "\\/+(?:[a-z)+\\/([a-z0-9_]+)\\/(.*)"
path: "\\/([a-z0-9_]+)\\/(.*)"
kind: "presets"
order:
presetName: 0
Expand All @@ -10,7 +10,19 @@ buckets:
blog_small:
quality: 75
filters:
thumbnail: { size: [100, 70], mode: outbound }
thumbnail: { size: [100, 100], mode: outbound }
interlace:
mode: line
width:
quality: 75
filters:
thumbnail: { size: [100], mode: outbound }
interlace:
mode: line
height:
quality: 75
filters:
thumbnail: { size: [0, 100], mode: outbound }
interlace:
mode: line
storages:
Expand Down

0 comments on commit 0e2aaf2

Please sign in to comment.