@@ -3,7 +3,6 @@ package opc
33import (
44 "archive/zip"
55 "bytes"
6- "math/rand"
76 "testing"
87)
98
@@ -24,10 +23,6 @@ func TestWriter_Flush(t *testing.T) {
2423 }
2524}
2625
27- func fakeRand () * rand.Rand {
28- return rand .New (rand .NewSource (42 ))
29- }
30-
3126func TestWriter_Close (t * testing.T ) {
3227 p := newPackage ()
3328 p .contentTypes .add ("/a.xml" , "a/b" )
@@ -44,17 +39,17 @@ func TestWriter_Close(t *testing.T) {
4439 wantErr bool
4540 }{
4641 {"base" , NewWriter (& bytes.Buffer {}), false },
47- {"invalidContentType" , & Writer {p : pC , w : zip .NewWriter (& bytes.Buffer {}), rnd : fakeRand () }, true },
48- {"withCt" , & Writer {p : p , w : zip .NewWriter (& bytes.Buffer {}), rnd : fakeRand () }, false },
49- {"invalidPartRel" , & Writer {p : newPackage (), w : zip .NewWriter (& bytes.Buffer {}), last : & Part {Name : "/b.xml" , Relationships : []* Relationship {{}}}, rnd : fakeRand () }, true },
50- {"invalidOwnRel" , & Writer {p : newPackage (), w : zip .NewWriter (& bytes.Buffer {}), Relationships : []* Relationship {{}}, rnd : fakeRand () }, true },
51- {"withDuplicatedCoreProps" , & Writer {p : pCore , w : zip .NewWriter (& bytes.Buffer {}), Properties : CoreProperties {Title : "Song" }, rnd : fakeRand () }, true },
52- {"withDuplicatedRels" , & Writer {p : pRel , w : zip .NewWriter (& bytes.Buffer {}), Properties : CoreProperties {Title : "Song" }, rnd : fakeRand () }, true },
53- {"withCoreProps" , & Writer {p : newPackage (), w : zip .NewWriter (& bytes.Buffer {}), Properties : CoreProperties {Title : "Song" }, rnd : fakeRand () }, false },
42+ {"invalidContentType" , & Writer {p : pC , w : zip .NewWriter (& bytes.Buffer {})}, true },
43+ {"withCt" , & Writer {p : p , w : zip .NewWriter (& bytes.Buffer {})}, false },
44+ {"invalidPartRel" , & Writer {p : newPackage (), w : zip .NewWriter (& bytes.Buffer {}), last : & Part {Name : "/b.xml" , Relationships : []* Relationship {{}}}}, true },
45+ {"invalidOwnRel" , & Writer {p : newPackage (), w : zip .NewWriter (& bytes.Buffer {}), Relationships : []* Relationship {{}}}, true },
46+ {"withDuplicatedCoreProps" , & Writer {p : pCore , w : zip .NewWriter (& bytes.Buffer {}), Properties : CoreProperties {Title : "Song" }}, true },
47+ {"withDuplicatedRels" , & Writer {p : pRel , w : zip .NewWriter (& bytes.Buffer {}), Properties : CoreProperties {Title : "Song" }}, true },
48+ {"withCoreProps" , & Writer {p : newPackage (), w : zip .NewWriter (& bytes.Buffer {}), Properties : CoreProperties {Title : "Song" }}, false },
5449 {"withCorePropsWithName" , & Writer {p : newPackage (), w : zip .NewWriter (& bytes.Buffer {}), Relationships : []* Relationship {
5550 {TargetURI : "props.xml" , Type : corePropsRel },
56- }, Properties : CoreProperties {Title : "Song" , PartName : "props.xml" }, rnd : fakeRand () }, false },
57- {"withCorePropsWithNameAndId" , & Writer {p : newPackage (), w : zip .NewWriter (& bytes.Buffer {}), Properties : CoreProperties {Title : "Song" , PartName : "/docProps/props.xml" , RelationshipID : "rId1" }, rnd : fakeRand () }, false },
51+ }, Properties : CoreProperties {Title : "Song" , PartName : "props.xml" }}, false },
52+ {"withCorePropsWithNameAndId" , & Writer {p : newPackage (), w : zip .NewWriter (& bytes.Buffer {}), Properties : CoreProperties {Title : "Song" , PartName : "/docProps/props.xml" , RelationshipID : "rId1" }}, false },
5853 }
5954 for _ , tt := range tests {
6055 t .Run (tt .name , func (t * testing.T ) {
@@ -154,8 +149,8 @@ func TestWriter_CreatePart(t *testing.T) {
154149 }{
155150 {"fhErr" , NewWriter (& bytes.Buffer {}), args {& Part {"/a.xml" , "a/b" , nil }, - 3 }, true },
156151 {"nameErr" , NewWriter (& bytes.Buffer {}), args {& Part {"a.xml" , "a/b" , nil }, CompressionNone }, true },
157- {"failRel" , & Writer {w : zip .NewWriter (nil ), last : & Part {Name : "/b.xml" , Relationships : []* Relationship {{}}}, rnd : fakeRand () }, args {& Part {"/a.xml" , "a/b" , nil }, CompressionNone }, true },
158- {"failRel2" , & Writer {p : pRel , w : zip .NewWriter (nil ), last : & Part {Name : "/a.xml" , Relationships : []* Relationship {rel }}, rnd : fakeRand () }, args {& Part {"/b.xml" , "a/b" , nil }, CompressionNone }, true },
152+ {"failRel" , & Writer {w : zip .NewWriter (nil ), last : & Part {Name : "/b.xml" , Relationships : []* Relationship {{}}}}, args {& Part {"/a.xml" , "a/b" , nil }, CompressionNone }, true },
153+ {"failRel2" , & Writer {p : pRel , w : zip .NewWriter (nil ), last : & Part {Name : "/a.xml" , Relationships : []* Relationship {rel }}}, args {& Part {"/b.xml" , "a/b" , nil }, CompressionNone }, true },
159154 {"base" , w , args {& Part {"/a.xml" , "a/b" , nil }, CompressionNone }, false },
160155 {"multipleDiffName" , w , args {& Part {"/b.xml" , "a/b" , nil }, CompressionNone }, false },
161156 {"multipleDiffContentType" , w , args {& Part {"/c.xml" , "c/d" , nil }, CompressionNone }, false },
@@ -184,11 +179,11 @@ func TestWriter_createLastPartRelationships(t *testing.T) {
184179 w * Writer
185180 wantErr bool
186181 }{
187- {"base" , & Writer {p : newPackage (), w : zip .NewWriter (nil ), last : & Part {Name : "/a.xml" , Relationships : []* Relationship {rel }}, rnd : fakeRand () }, false },
188- {"base2" , & Writer {p : newPackage (), w : zip .NewWriter (nil ), last : & Part {Name : "/b/a.xml" , Relationships : []* Relationship {rel }}, rnd : fakeRand () }, false },
182+ {"base" , & Writer {p : newPackage (), w : zip .NewWriter (nil ), last : & Part {Name : "/a.xml" , Relationships : []* Relationship {rel }}}, false },
183+ {"base2" , & Writer {p : newPackage (), w : zip .NewWriter (nil ), last : & Part {Name : "/b/a.xml" , Relationships : []* Relationship {rel }}}, false },
189184 {"hasSome" , w , false },
190- {"duplicated" , & Writer {w : zip .NewWriter (nil ), last : & Part {Name : "/a.xml" , Relationships : []* Relationship {rel , rel }}, rnd : fakeRand () }, true },
191- {"invalidRelation" , & Writer {w : zip .NewWriter (nil ), last : & Part {Name : "/a.xml" , Relationships : []* Relationship {{}}}, rnd : fakeRand () }, true },
185+ {"duplicated" , & Writer {w : zip .NewWriter (nil ), last : & Part {Name : "/a.xml" , Relationships : []* Relationship {rel , rel }}}, true },
186+ {"invalidRelation" , & Writer {w : zip .NewWriter (nil ), last : & Part {Name : "/a.xml" , Relationships : []* Relationship {{}}}}, true },
192187 {"empty" , NewWriter (& bytes.Buffer {}), false },
193188 }
194189 for _ , tt := range tests {
0 commit comments