-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
1,801 additions
and
1,795 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,89 +1,89 @@ | ||
package opc | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestError_Code(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
e *Error | ||
want int | ||
}{ | ||
{"empty", new(Error), 0}, | ||
{"base", newError(1, "base"), 1}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
if got := tt.e.Code(); got != tt.want { | ||
t.Errorf("Error.Code() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestError_PartName(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
e *Error | ||
want string | ||
}{ | ||
{"empty", new(Error), ""}, | ||
{"base", &Error{partName: "base"}, "base"}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
if got := tt.e.PartName(); got != tt.want { | ||
t.Errorf("Error.PartName() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestError_Error(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
e *Error | ||
want string | ||
wantPanic bool | ||
}{ | ||
{"base", &Error{101, "/doc.xml", ""}, "opc: /doc.xml: a part name shall not be empty", false}, | ||
{"panic", &Error{0, "/doc.xml", ""}, "", true}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
defer func() { | ||
if r := recover(); r != nil { | ||
if !tt.wantPanic { | ||
t.Errorf("Error.Error() want panic") | ||
} | ||
} | ||
}() | ||
if got := tt.e.Error(); got != tt.want { | ||
t.Errorf("Error.Error() = %v, want %v", got, tt.want) | ||
return | ||
} | ||
if tt.wantPanic { | ||
t.Error("Error.Error() want error") | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestError_RelationshipID(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
e *Error | ||
want string | ||
}{ | ||
{"empty", new(Error), ""}, | ||
{"base", newErrorRelationship(101, "/doc.xml", "21211"), "21211"}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
if got := tt.e.RelationshipID(); got != tt.want { | ||
t.Errorf("Error.RelationshipID() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} | ||
package opc | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestError_Code(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
e *Error | ||
want int | ||
}{ | ||
{"empty", new(Error), 0}, | ||
{"base", newError(1, "base"), 1}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
if got := tt.e.Code(); got != tt.want { | ||
t.Errorf("Error.Code() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestError_PartName(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
e *Error | ||
want string | ||
}{ | ||
{"empty", new(Error), ""}, | ||
{"base", &Error{partName: "base"}, "base"}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
if got := tt.e.PartName(); got != tt.want { | ||
t.Errorf("Error.PartName() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestError_Error(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
e *Error | ||
want string | ||
wantPanic bool | ||
}{ | ||
{"base", &Error{101, "/doc.xml", ""}, "opc: /doc.xml: a part name shall not be empty", false}, | ||
{"panic", &Error{0, "/doc.xml", ""}, "", true}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
defer func() { | ||
if r := recover(); r != nil { | ||
if !tt.wantPanic { | ||
t.Errorf("Error.Error() want panic") | ||
} | ||
} | ||
}() | ||
if got := tt.e.Error(); got != tt.want { | ||
t.Errorf("Error.Error() = %v, want %v", got, tt.want) | ||
return | ||
} | ||
if tt.wantPanic { | ||
t.Error("Error.Error() want error") | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestError_RelationshipID(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
e *Error | ||
want string | ||
}{ | ||
{"empty", new(Error), ""}, | ||
{"base", newErrorRelationship(101, "/doc.xml", "21211"), "21211"}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
if got := tt.e.RelationshipID(); got != tt.want { | ||
t.Errorf("Error.RelationshipID() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -89,4 +89,3 @@ func ExampleNewWriterFromReader() { | |
log.Fatal(err) | ||
} | ||
} | ||
|
Oops, something went wrong.