File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ package main
2+
3+ import (
4+ "errors"
5+ "reflect"
6+ "testing"
7+ )
8+
9+ func Test_options_parse (t * testing.T ) {
10+ type opt struct {
11+ user string
12+ host string
13+ pass string
14+ file string
15+ kind string
16+ database string
17+ loglvl string
18+ pprof string
19+ workers int
20+ factor float64
21+ usePass bool
22+ noDryRun bool
23+ showErrors bool
24+ }
25+ tests := []struct {
26+ name string
27+ opt opt
28+ want []error
29+ }{
30+ {
31+ name : "no errors" ,
32+ opt : opt {
33+ user : "foo" ,
34+ host : "bar" ,
35+ file : "myfile" ,
36+ kind : "mykind" ,
37+ database : "mydb" ,
38+ workers : 42 ,
39+ factor : 2 ,
40+ },
41+ want : nil ,
42+ },
43+ {
44+ name : "one error" ,
45+ opt : opt {
46+ user : "foo" ,
47+ host : "bar" ,
48+ file : "myfile" ,
49+ kind : "mykind" ,
50+ database : "mydb" ,
51+ // workers: 42,
52+ factor : 2 ,
53+ },
54+ want : []error {errors .New ("cannot create negative number or zero workers" )},
55+ },
56+ }
57+ for _ , tt := range tests {
58+ t .Run (tt .name , func (t * testing.T ) {
59+ o := & options {
60+ user : tt .opt .user ,
61+ host : tt .opt .host ,
62+ pass : tt .opt .pass ,
63+ file : tt .opt .file ,
64+ kind : tt .opt .kind ,
65+ database : tt .opt .database ,
66+ loglvl : tt .opt .loglvl ,
67+ pprof : tt .opt .pprof ,
68+ workers : tt .opt .workers ,
69+ factor : tt .opt .factor ,
70+ usePass : tt .opt .usePass ,
71+ noDryRun : tt .opt .noDryRun ,
72+ showErrors : tt .opt .showErrors ,
73+ }
74+ if got := o .parse (); ! reflect .DeepEqual (got , tt .want ) {
75+ t .Errorf ("options.parse() = %v, want %v" , got , tt .want )
76+ }
77+ })
78+ }
79+ }
You can’t perform that action at this time.
0 commit comments