forked from steger/pr3-ws202627
49 lines
1.1 KiB
Go
49 lines
1.1 KiB
Go
package patterns
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
func TestNoodleMaker(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
build func() (Noodle, error)
|
|
want Noodle
|
|
wantErr bool
|
|
}{
|
|
{
|
|
name: "Defaults",
|
|
build: func() (Noodle, error) { return newNoodleMaker().Build() },
|
|
want: Noodle{Type: "Röhre", Name: "Fusilli", Length: 10, Girth: 5},
|
|
},
|
|
{
|
|
name: "New Noodle",
|
|
build: func() (Noodle, error) {
|
|
return newNoodleMaker().Name("Spaghetti").Type("Lang").Length(25).Girth(2).Build()
|
|
},
|
|
want: Noodle{Type: "Lang", Name: "Spaghetti", Length: 25, Girth: 2},
|
|
},
|
|
{
|
|
name: "Length 0",
|
|
build: func() (Noodle, error) { return newNoodleMaker().Length(0).Build() },
|
|
wantErr: true,
|
|
},
|
|
{
|
|
name: "Girth -1",
|
|
build: func() (Noodle, error) { return newNoodleMaker().Girth(-1).Build() },
|
|
wantErr: true,
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
got, err := tt.build()
|
|
if (err != nil) != tt.wantErr {
|
|
t.Fatalf("error = %v, wantErr %v", err, tt.wantErr)
|
|
}
|
|
if !tt.wantErr && got != tt.want {
|
|
t.Errorf("got %+v, want %+v", got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|