Permalink
Browse files

add tests for readers

  • Loading branch information...
qmuntal committed Feb 5, 2019
1 parent 829e95b commit 5d121bbdd6ee495eb5d12b35c132daaaeb51398a
@@ -37,7 +37,7 @@ func ExampleWriter() {
}

func ExampleReader() {
r, err := opc.OpenReader("testdata/test.xlsx")
r, err := opc.OpenReader("testdata/component.3mf")
if err != nil {
log.Fatal(err)
}
@@ -549,3 +549,38 @@ func (ct *cTypeBuilder) withDefault(cType, ext string) *cTypeBuilder {
func (ct *cTypeBuilder) String() string {
return fmt.Sprintf(`<?xml version="1.0" encoding="UTF-8"?><Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types">%s</Types>`, ct.ctype.String())
}

func TestOpenReader(t *testing.T) {
type args struct {
name string
}
tests := []struct {
name string
args args
wantErr bool
}{
{"extensioncustom", args{"testdata/extensioncustom.3mf"}, false},
{"overridecustom", args{"testdata/overridecustom.3mf"}, false},
{"overridepositive", args{"testdata/overridepositive.3mf"}, false},
{"component", args{"testdata/component.3mf"}, false},
{"invalid", args{"testdata/invalid.txt"}, true},
{"error", args{""}, true},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := OpenReader(tt.args.name)
if (err != nil) != tt.wantErr {
t.Errorf("OpenReader() error = %v, wantErr %v", err, tt.wantErr)
return
}
if err == nil {
got.Files[0].Open()
err = got.Close()
if (err != nil) != tt.wantErr {
t.Errorf("File.Open() error = %v, wantErr %v", err, tt.wantErr)
return
}
}
})
}
}
BIN +1.62 KB testdata/component.3mf
Binary file not shown.
Binary file not shown.
No changes.
Binary file not shown.
Binary file not shown.

0 comments on commit 5d121bb

Please sign in to comment.