1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
|
package modelgen
import (
"reflect"
"testing"
)
func TestWithDryRun(t *testing.T) {
tests := []struct {
name string
call bool
dryRun bool
}{
{
"call",
true,
true,
},
{
"not call",
false,
false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
opts := &options{}
if tt.call {
fn := WithDryRun()
_ = fn(opts)
}
if got := opts.dryRun; !reflect.DeepEqual(got, tt.dryRun) {
t.Errorf("WithDryRun() = %v, want %v", got, tt.dryRun)
}
})
}
}
func Test_newOptions(t *testing.T) {
type args struct {
opts []Option
}
tests := []struct {
name string
args args
want *options
wantErr bool
}{
{
"With DryRun",
args{opts: []Option{WithDryRun()}},
&options{dryRun: true},
false,
},
{
"Without DryRun",
args{opts: []Option{}},
&options{dryRun: false},
false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := newOptions(tt.args.opts...)
if (err != nil) != tt.wantErr {
t.Errorf("newOptions() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("newOptions() got = %v, want %v", got, tt.want)
}
})
}
}
|