Permalink
Browse files

add new method: Change() (#36)

  • Loading branch information...
enkiprobo authored and Fs02 committed Dec 17, 2018
1 parent 0a1586a commit e8378496d26db4ed845804132d669041bfe211db
Showing with 44 additions and 0 deletions.
  1. +10 −0 changeset/change.go
  2. +34 −0 changeset/change_test.go
@@ -0,0 +1,10 @@
package changeset

// Change make a new changeset without changes and build from given schema. Returns new Changeset.
func Change(schema interface{}) *Changeset {
ch := &Changeset{}
ch.changes = make(map[string]interface{})
ch.values, ch.types = mapSchema(schema)

return ch
}
@@ -0,0 +1,34 @@
package changeset

import (
"reflect"
"testing"

"github.com/stretchr/testify/assert"
)

func TestChange(t *testing.T) {
var data struct {
FIELD1 int `db:"field1"`
Field2 string
Field3 bool
}

expectedValues := map[string]interface{}{
"field1": 0,
"field2": "",
"field3": false,
}

expectedTypes := map[string]reflect.Type{
"field1": reflect.TypeOf(0),
"field2": reflect.TypeOf(""),
"field3": reflect.TypeOf(false),
}

ch := Change(data)
assert.Nil(t, ch.Errors())
assert.Equal(t, expectedValues, ch.Values())
assert.Equal(t, expectedTypes, ch.Types())
assert.Equal(t, 0, len(ch.Changes()))
}

0 comments on commit e837849

Please sign in to comment.