Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: updated to include checks for additional dataset fields #3

Merged
merged 5 commits into from
Jan 25, 2018
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
55 changes: 55 additions & 0 deletions datasetDiffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ func (diffList DiffList) String() string {
return ""
}

func (diffList DiffList) List() []Diff {
return diffList.diffs
}

func diffStructure(a, b *dataset.Dataset) (*DiffList, error) {
diffList := &DiffList{}
diffDescription := Diff("")
Expand All @@ -43,6 +47,41 @@ func diffStructure(a, b *dataset.Dataset) (*DiffList, error) {
return diffList, nil
}

func diffTransform(a, b *dataset.Dataset) (*DiffList, error) {
diffList := &DiffList{}
diffDescription := Diff("")
if a.Transform != nil && b.Transform != nil {
if len(a.Transform.Path().String()) > 1 && len(b.Transform.Path().String()) > 1 {
if a.Transform.Path() != b.Transform.Path() {
diffDescription = Diff("Transform Changed.")
diffList.diffs = append(diffList.diffs, diffDescription)
}
}
// else {
// ...
// }
}

return diffList, nil
}

func diffVisConfig(a, b *dataset.Dataset) (*DiffList, error) {
diffList := &DiffList{}
diffDescription := Diff("")
if a.VisConfig != nil && b.VisConfig != nil {
if len(a.VisConfig.Path().String()) > 1 && len(b.VisConfig.Path().String()) > 1 {
if a.VisConfig.Path() != b.VisConfig.Path() {
diffDescription = Diff("VisConfig Changed.")
diffList.diffs = append(diffList.diffs, diffDescription)
}
}
// else {
// ...
// }x
}
return diffList, nil
}

//TODO: make work
func diffData(a, b *dataset.Dataset) (*DiffList, error) {
temporarilyBlindToData := true // <-- REMOVE this
Expand Down Expand Up @@ -116,5 +155,21 @@ func DiffDatasets(a, b *dataset.Dataset) (*DiffList, error) {
if len(metaDiffList.diffs) > 0 {
diffList.diffs = append(diffList.diffs, metaDiffList.diffs...)
}
// Compare Transform
transformDiffList, err := diffTransform(a, b)
if err != nil {
return nil, err
}
if len(transformDiffList.diffs) > 0 {
diffList.diffs = append(diffList.diffs, transformDiffList.diffs...)
}
// Compare VisConfig
visConfigDiffList, err := diffVisConfig(a, b)
if err != nil {
return nil, err
}
if len(visConfigDiffList.diffs) > 0 {
diffList.diffs = append(diffList.diffs, visConfigDiffList.diffs...)
}
return diffList, nil
}
22 changes: 13 additions & 9 deletions datasetDiffer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,19 @@ func TestDiffDataset(t *testing.T) {
expected string
err string
}{
{"testdata/exampleData_orig.json", "testdata/exampleData_orig.json", "", ""},
{"testdata/exampleData_orig.json", "testdata/exampleData_newData.json", "Data Changed.", ""},
{"testdata/exampleData_orig.json", "testdata/exampleData_newStructure.json", "Structure Changed.", ""},
{"testdata/exampleData_oldChecksum.json", "testdata/exampleData_newChecksum.json", "Structure Changed.", ""},
{"testdata/exampleData_orig.json", "testdata/exampleData_newDataAndStructure.json", "Structure Changed.", ""},
{"testdata/exampleData_orig.json", "testdata/exampleData_blankStructure.json", "", "error: structure path cannot be empty string"},
{"testdata/exampleData_orig.json", "testdata/exampleData_blankData.json", "", "error: data path cannot be empty string"},
{"testdata/exampleData_orig_with_meta.json", "testdata/exampleData_newTitle.json", "Title Changed.", ""},
{"testdata/exampleData_orig_with_meta.json", "testdata/exampleData_newDescription.json", "Description Changed.", ""},
{"testdata/orig.json", "testdata/orig.json", "", ""},
{"testdata/orig.json", "testdata/newData.json", "Data Changed.", ""},
{"testdata/orig.json", "testdata/newStructure.json", "Structure Changed.", ""},
{"testdata/oldChecksum.json", "testdata/newChecksum.json", "Structure Changed.", ""},
{"testdata/orig.json", "testdata/newDataAndStructure.json", "Structure Changed.", ""},
{"testdata/orig.json", "testdata/blankStructure.json", "", "error: structure path cannot be empty string"},
{"testdata/orig.json", "testdata/blankData.json", "", "error: data path cannot be empty string"},
{"testdata/orig_with_meta.json", "testdata/newTitle.json", "Title Changed.", ""},
{"testdata/orig_with_meta.json", "testdata/newDescription.json", "Description Changed.", ""},
//TODO: test transform change (need path)
// {"orig_with_vis_config_and_transform.json", "orig_with_vis_config_and_transform.json", "Transform Changed.", ""}
//TODO: test visconfig change (need path)
// {"orig_with_vis_config_and_transform.json", "orig_with_vis_config_and_transform.json", "VisConfig Changed.", ""}
}
// load files and execute tests
for i, c := range cases {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
12 changes: 12 additions & 0 deletions testdata/orig_with_vis_config_and_transform.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"kind": "qri:ds:0",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

keep in mind kind is now spelled qri, with no qri: prefix on the value 😉

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added issue #4 to update this

"DataPath": "abc",
"path": "123",
"structure": "abc",
"meta": {
"title": "abc",
"description": "I am a dataset"
},
"visConfig": "hash1",
"transform": "hash2"
}