github.com/qri-io/qri@v0.10.1-0.20220104210721-c771715036cb/lib/file_test.go (about) 1 package lib 2 3 import ( 4 "testing" 5 6 "github.com/qri-io/dataset" 7 "github.com/qri-io/dataset/dstest" 8 ) 9 10 func TestReadDatasetFiles(t *testing.T) { 11 cases := []struct { 12 description string 13 paths []string 14 ds *dataset.Dataset 15 }{ 16 {".star file to transform script", 17 []string{ 18 "testdata/tf/transform.star", 19 }, 20 &dataset.Dataset{ 21 Transform: &dataset.Transform{ 22 ScriptPath: "testdata/tf/transform.star", 23 }, 24 }, 25 }, 26 27 {".html file to viz script", 28 []string{ 29 "testdata/viz/visualization.html", 30 }, 31 &dataset.Dataset{ 32 Viz: &dataset.Viz{ 33 Format: "html", 34 ScriptPath: "testdata/viz/visualization.html", 35 }, 36 }, 37 }, 38 39 {"meta.json has no component key", 40 []string{ 41 "testdata/detect/meta.json", 42 }, 43 &dataset.Dataset{ 44 Meta: &dataset.Meta{ 45 Title: "This is dataset title", 46 }, 47 }, 48 }, 49 50 {"structure.json, meta.json component files", 51 []string{ 52 "testdata/component_files/structure.json", 53 "testdata/component_files/meta.json", 54 }, 55 &dataset.Dataset{ 56 Meta: &dataset.Meta{ 57 Qri: "md", 58 Title: "build a dataset with component files", 59 }, 60 Structure: &dataset.Structure{ 61 Qri: "st", 62 Format: "json", 63 Schema: map[string]interface{}{ 64 "type": "array", 65 "items": map[string]interface{}{ 66 "type": "array", 67 "items": []interface{}{ 68 map[string]interface{}{"type": "string", "name": "field_1"}, 69 }, 70 }, 71 }, 72 }, 73 }, 74 }, 75 76 {"structure.yaml, meta.yaml component files", 77 []string{ 78 "testdata/component_files/structure.yaml", 79 "testdata/component_files/meta.yaml", 80 }, 81 &dataset.Dataset{ 82 Meta: &dataset.Meta{ 83 Qri: "md", 84 Title: "build a dataset with component files", 85 }, 86 Structure: &dataset.Structure{ 87 Qri: "st", 88 Format: "json", 89 Schema: map[string]interface{}{ 90 "type": "array", 91 "items": map[string]interface{}{ 92 "type": "array", 93 "items": []interface{}{ 94 map[string]interface{}{"type": "string", "name": "field_1"}, 95 }, 96 }, 97 }, 98 }, 99 }, 100 }, 101 102 {"structure.json, meta.yaml, commit.yaml component files", 103 []string{ 104 "testdata/component_files/commit.yaml", 105 "testdata/component_files/structure.json", 106 "testdata/component_files/meta.yaml", 107 }, 108 &dataset.Dataset{ 109 Commit: &dataset.Commit{ 110 Qri: "cm", 111 Title: "this is a commit", 112 }, 113 Meta: &dataset.Meta{ 114 Qri: "md", 115 Title: "build a dataset with component files", 116 }, 117 Structure: &dataset.Structure{ 118 Qri: "st", 119 Format: "json", 120 Schema: map[string]interface{}{ 121 "type": "array", 122 "items": map[string]interface{}{ 123 "type": "array", 124 "items": []interface{}{ 125 map[string]interface{}{"type": "string", "name": "field_1"}, 126 }, 127 }, 128 }, 129 }, 130 }, 131 }, 132 } 133 134 for i, c := range cases { 135 got, err := ReadDatasetFiles(c.paths...) 136 if err != nil { 137 t.Errorf("case %d %s unexpected error: %s", i, c.description, err.Error()) 138 continue 139 } 140 if diff := dstest.CompareDatasets(c.ds, got); diff != "" { 141 t.Errorf("case %d %s dataset mismatch (-want +got):\n%s", i, c.description, diff) 142 continue 143 } 144 } 145 }