|
package main |
|
|
|
import "testing" |
|
|
|
// go test -race ./... |
|
// go test -race -coverprofile cover.out ./... ./... |
|
// go tool cover -html cover.out -o cover.html |
|
|
|
var stackTest = []struct { |
|
name, message string |
|
}{ |
|
{"go", "error one"}, |
|
{"go", "error two"}, |
|
{"test", "error one"}, |
|
} |
|
|
|
func TestStack(t *testing.T) { |
|
s := NewStack() |
|
|
|
if got, want := s.IsEmpty(), true; got != want { |
|
t.Errorf("IsEmpty() got %v; want %v", got, want) |
|
} |
|
|
|
for _, tt := range stackTest { |
|
s.Add(WithName(tt.name, tt.message)) |
|
} |
|
|
|
if got, want := s.Count(), 3; got != want { |
|
t.Errorf("Count() got %d; want %d", got, want) |
|
} |
|
|
|
stack := s.Find(func(err Error) bool { |
|
return err.Name == "go" |
|
}) |
|
|
|
if got, want := stack.Count(), 2; got != want { |
|
t.Errorf("Count() got %d; want %d", got, want) |
|
} |
|
|
|
s.Remove(10) |
|
if got, want := s.Count(), 3; got != want { |
|
t.Errorf("Count() 10 got %d; want %d", got, want) |
|
} |
|
|
|
s.Remove(2) |
|
if got, want := s.Count(), 2; got != want { |
|
t.Errorf("Count() got %d; want %d", got, want) |
|
} |
|
|
|
s.Clear() |
|
if got, want := s.IsEmpty(), true; got != want { |
|
t.Errorf("IsEmpty() got %v; want %v", got, want) |
|
} |
|
} |