Debian Codegraph @

pkg/generators/basic/basic_test.go

raw
1 package basic
2
3 import (
4 "bufio"
5 "errors"
6 "fmt"
7 "net/url"
8 "os"
9 "reflect"
10 "strconv"
11 "strings"
12 "testing"
13 "text/template"
14 "time"
15
16 "github.com/nicholas-fedor/shoutrrr/pkg/format"
17 "github.com/nicholas-fedor/shoutrrr/pkg/types"
18 )
19
20 // mockConfig implements types.ServiceConfig.
21 type mockConfig struct {
22 Host string `default:"localhost" key:"host"`
23 Port int `default:"8080" key:"port" required:"true"`
24 url *url.URL
25 }
26
27 // mockServiceConfig is a test implementation of Service.
28 type mockServiceConfig struct {
29 Config *mockConfig
30 }
31
32 // mockServiceNilConfig is a test service with nil Config field (simulating uninitialized service).
33 type mockServiceNilConfig struct {
34 Config *mockConfig // nil by default
35 }
36
37 // mockServiceWithoutConfig is a test service without a Config field.
38 type mockServiceWithoutConfig struct{}
39
40 func (m *mockConfig) Enums() map[string]types.EnumFormatter {
41 return nil
42 }
43
44 // ConfigQueryResolver methods.
45 func (m *mockConfig) Get(key string) (string, error) {
46 switch strings.ToLower(key) {
47 case "host":
48 return m.Host, nil
49 case "port":
50 return strconv.Itoa(m.Port), nil
51 default:
52 return "", fmt.Errorf("unknown key: %s", key)
53 }
54 }
55
56 func (m *mockConfig) GetPropValue() (string, error) {
57 // Minimal implementation for testing
58 return fmt.Sprintf("%s:%d", m.Host, m.Port), nil
59 }
60
61 func (m *mockConfig) GetURL() *url.URL {
62 if m.url == nil {
63 u, _ := url.Parse("mock://url")
64 m.url = u
65 }
66
67 return m.url
68 }
69
70 func (m *mockConfig) QueryFields() []string {
71 return []string{"host", "port"}
72 }
73
74 func (m *mockConfig) Set(key, value string) error {
75 switch strings.ToLower(key) {
76 case "host":
77 m.Host = value
78
79 return nil
80 case "port":
81 port, err := strconv.Atoi(value)
82 if err != nil {
83 return err
84 }
85
86 m.Port = port
87
88 return nil
89 default:
90 return fmt.Errorf("unknown key: %s", key)
91 }
92 }
93
94 // ConfigProp methods.
95 func (m *mockConfig) SetFromProp(propValue string) error {
96 // Minimal implementation for testing; typically parses propValue
97 parts := strings.SplitN(propValue, ":", 2)
98 if len(parts) == 2 {
99 m.Host = parts[0]
100
101 port, err := strconv.Atoi(parts[1])
102 if err != nil {
103 return err
104 }
105
106 m.Port = port
107 }
108
109 return nil
110 }
111
112 func (m *mockConfig) SetLogger(_ types.StdLogger) {
113 // Minimal implementation, no-op
114 }
115
116 func (m *mockConfig) SetTemplateFile(_, _ string) error {
117 return nil
118 }
119
120 func (m *mockConfig) SetTemplateString(_, _ string) error {
121 return nil
122 }
123
124 func (m *mockConfig) SetURL(u *url.URL) error {
125 m.url = u
126
127 return nil
128 }
129
130 func (m *mockServiceConfig) GetID() string {
131 return "mockID"
132 }
133
134 func (m *mockServiceConfig) GetTemplate(_ string) (*template.Template, bool) {
135 return nil, false
136 }
137
138 func (m *mockServiceConfig) Initialize(_ *url.URL, _ types.StdLogger) error {
139 return nil
140 }
141
142 func (m *mockServiceConfig) Send(_ string, _ *types.Params) error {
143 return nil
144 }
145
146 func (m *mockServiceConfig) SetLogger(_ types.StdLogger) {}
147
148 func (m *mockServiceConfig) SetTemplateFile(_, _ string) error {
149 return nil
150 }
151
152 func (m *mockServiceConfig) SetTemplateString(_, _ string) error {
153 return nil
154 }
155
156 func (m *mockServiceNilConfig) GetID() string {
157 return "mockNilConfig"
158 }
159
160 func (m *mockServiceNilConfig) GetTemplate(_ string) (*template.Template, bool) {
161 return nil, false
162 }
163
164 func (m *mockServiceNilConfig) Initialize(_ *url.URL, _ types.StdLogger) error {
165 return nil
166 }
167
168 func (m *mockServiceNilConfig) Send(_ string, _ *types.Params) error {
169 return nil
170 }
171
172 func (m *mockServiceNilConfig) SetLogger(_ types.StdLogger) {}
173
174 func (m *mockServiceNilConfig) SetTemplateFile(_, _ string) error {
175 return nil
176 }
177
178 func (m *mockServiceNilConfig) SetTemplateString(_, _ string) error {
179 return nil
180 }
181
182 func (m *mockServiceWithoutConfig) GetID() string {
183 return "mockNoConfig"
184 }
185
186 func (m *mockServiceWithoutConfig) GetTemplate(_ string) (*template.Template, bool) {
187 return nil, false
188 }
189
190 func (m *mockServiceWithoutConfig) Initialize(_ *url.URL, _ types.StdLogger) error {
191 return nil
192 }
193
194 func (m *mockServiceWithoutConfig) Send(_ string, _ *types.Params) error {
195 return nil
196 }
197
198 func (m *mockServiceWithoutConfig) SetLogger(_ types.StdLogger) {}
199
200 func (m *mockServiceWithoutConfig) SetTemplateFile(_, _ string) error {
201 return nil
202 }
203
204 func (m *mockServiceWithoutConfig) SetTemplateString(_, _ string) error {
205 return nil
206 }
207
208 func TestGenerator_Generate(t *testing.T) {
209 t.Parallel()
210
211 tests := []struct {
212 name string
213 props map[string]string
214 input string
215 want types.ServiceConfig
216 wantErr bool
217 }{
218 {
219 name: "successful generation with defaults",
220 props: map[string]string{},
221 input: "\n8080\n",
222 want: &mockConfig{
223 Host: "localhost",
224 Port: 8080,
225 },
226 wantErr: false,
227 },
228 {
229 name: "successful generation with props",
230 props: map[string]string{"host": "example.com", "port": "9090"},
231 input: "",
232 want: &mockConfig{
233 Host: "example.com",
234 Port: 9090,
235 },
236 wantErr: false,
237 },
238 {
239 name: "error_on_invalid_port",
240 props: map[string]string{},
241 input: "\ninvalid\n",
242 want: nil,
243 wantErr: true,
244 },
245 }
246
247 for _, tt := range tests {
248 t.Run(tt.name, func(t *testing.T) {
249 t.Parallel()
250
251 // Set up pipe for stdin simulation
252 r, w, err := os.Pipe()
253 if err != nil {
254 t.Fatal(err)
255 }
256
257 // Use dependency injection instead of global os.Stdin manipulation
258 g := &Generator{Input: r}
259
260 defer func() {
261 _ = w.Close()
262 _ = r.Close()
263 }()
264
265 // Write input to the pipe
266 _, err = w.WriteString(tt.input)
267 if err != nil {
268 t.Fatal(err)
269 }
270
271 _ = w.Close()
272
273 service := newMockServiceConfig()
274
275 got, err := g.Generate(service, tt.props, nil)
276 if (err != nil) != tt.wantErr {
277 t.Errorf("Generate() error = %v, wantErr %v", err, tt.wantErr)
278
279 return
280 }
281
282 if !tt.wantErr && !reflect.DeepEqual(got, tt.want) {
283 t.Errorf("Generate() = %+v, want %+v", got, tt.want)
284 }
285 })
286 }
287 }
288
289 func TestGenerator_promptUserForFields(t *testing.T) {
290 t.Parallel()
291
292 tests := []struct {
293 name string
294 config reflect.Value
295 props map[string]string
296 input string
297 wantErr bool
298 }{
299 {
300 name: "valid input with defaults",
301 config: reflect.ValueOf(newMockServiceConfig().Config), // Pass *mockConfig
302 props: map[string]string{},
303 input: "\n8080\n",
304 wantErr: false,
305 },
306 {
307 name: "valid props",
308 config: reflect.ValueOf(newMockServiceConfig().Config), // Pass *mockConfig
309 props: map[string]string{"host": "test.com", "port": "1234"},
310 input: "",
311 wantErr: false,
312 },
313 {
314 name: "invalid config type",
315 config: reflect.ValueOf("not a config"),
316 props: map[string]string{},
317 input: "",
318 wantErr: true,
319 },
320 }
321
322 for _, tt := range tests {
323 t.Run(tt.name, func(t *testing.T) {
324 t.Parallel()
325
326 g := &Generator{}
327 scanner := bufio.NewScanner(strings.NewReader(tt.input))
328
329 err := g.promptUserForFields(tt.config, tt.props, scanner)
330 if (err != nil) != tt.wantErr {
331 t.Errorf("promptUserForFields() error = %v, wantErr %v", err, tt.wantErr)
332 }
333
334 if err == nil && tt.config.Kind() == reflect.Pointer &&
335 tt.config.Type().Elem().Kind() == reflect.Struct {
336 got := tt.config.Interface().(*mockConfig)
337 if tt.props["host"] != "" && got.Host != tt.props["host"] {
338 t.Errorf("promptUserForFields() host = %v, want %v", got.Host, tt.props["host"])
339 }
340
341 if tt.props["port"] != "" {
342 wantPort := atoiOrZero(tt.props["port"])
343 if got.Port != wantPort {
344 t.Errorf("promptUserForFields() port = %v, want %v", got.Port, wantPort)
345 }
346 }
347 }
348 })
349 }
350 }
351
352 func TestGenerator_getInputValue(t *testing.T) {
353 t.Parallel()
354
355 tests := []struct {
356 name string
357 field *format.FieldInfo
358 propKey string
359 props map[string]string
360 input string
361 want string
362 wantErr bool
363 }{
364 {
365 name: "from props",
366 field: &format.FieldInfo{Name: "Host"},
367 propKey: "host",
368 props: map[string]string{"host": "example.com"},
369 input: "",
370 want: "example.com",
371 wantErr: false,
372 },
373 {
374 name: "from user input",
375 field: &format.FieldInfo{Name: "Port", Type: reflect.TypeFor[int]()}, // Add Type
376 propKey: "port",
377 props: map[string]string{},
378 input: "8080\n",
379 want: "8080",
380 wantErr: false,
381 },
382 {
383 name: "default value",
384 field: &format.FieldInfo{Name: "Host", DefaultValue: "localhost"},
385 propKey: "host",
386 props: map[string]string{},
387 input: "\n",
388 want: "localhost",
389 wantErr: false,
390 },
391 {
392 name: "duration from user input",
393 field: &format.FieldInfo{Name: "Timeout", Type: reflect.TypeFor[time.Duration]()},
394 propKey: "timeout",
395 props: map[string]string{},
396 input: "30s\n",
397 want: "30s",
398 wantErr: false,
399 },
400 {
401 name: "duration rejects a value without a unit",
402 field: &format.FieldInfo{Name: "Timeout", Type: reflect.TypeFor[time.Duration]()},
403 propKey: "timeout",
404 props: map[string]string{},
405 input: "30\n",
406 want: "",
407 wantErr: true,
408 },
409 }
410
411 for _, tt := range tests {
412 t.Run(tt.name, func(t *testing.T) {
413 t.Parallel()
414
415 g := &Generator{}
416 scanner := bufio.NewScanner(strings.NewReader(tt.input))
417 consumed := make(map[string]struct{})
418
419 got, err := g.getInputValue(tt.field, tt.propKey, tt.props, consumed, scanner)
420 if (err != nil) != tt.wantErr {
421 t.Errorf("getInputValue() error = %v, wantErr %v", err, tt.wantErr)
422
423 return
424 }
425
426 if got != tt.want {
427 t.Errorf("getInputValue() = %v, want %v", got, tt.want)
428 }
429
430 // Verify that props from input are marked as consumed
431 if _, wasConsumed := consumed[tt.propKey]; tt.props[tt.propKey] != "" && !wasConsumed {
432 t.Errorf("getInputValue() did not mark prop as consumed")
433 }
434 })
435 }
436 }
437
438 func TestGenerator_formatPrompt(t *testing.T) {
439 t.Parallel()
440
441 tests := []struct {
442 name string
443 field *format.FieldInfo
444 want string
445 }{
446 {
447 name: "field with default",
448 field: &format.FieldInfo{Name: "Host", DefaultValue: "localhost"},
449 want: "Host[localhost]: ",
450 },
451 {
452 name: "field without default",
453 field: &format.FieldInfo{Name: "Port"},
454 want: "Port: ",
455 },
456 }
457
458 for _, tt := range tests {
459 t.Run(tt.name, func(t *testing.T) {
460 t.Parallel()
461
462 g := &Generator{}
463
464 got := g.formatPrompt(tt.field)
465 if got != tt.want {
466 t.Errorf("formatPrompt() = %q, want %q", got, tt.want)
467 }
468 })
469 }
470 }
471
472 func TestGenerator_setFieldValue(t *testing.T) {
473 t.Parallel()
474
475 tests := []struct {
476 name string
477 config reflect.Value
478 field *format.FieldInfo
479 inputValue string
480 want bool
481 wantErr bool
482 }{
483 {
484 name: "valid value",
485 config: reflect.ValueOf(newMockServiceConfig().Config).Elem(),
486 field: &format.FieldInfo{Name: "Port", Type: reflect.TypeFor[int](), Required: true},
487 inputValue: "8080",
488 want: true,
489 wantErr: false,
490 },
491 {
492 name: "required field empty",
493 config: reflect.ValueOf(newMockServiceConfig().Config).Elem(),
494 field: &format.FieldInfo{Name: "Port", Type: reflect.TypeFor[int](), Required: true},
495 inputValue: "",
496 want: false,
497 wantErr: false,
498 },
499 {
500 name: "invalid value",
501 config: reflect.ValueOf(newMockServiceConfig().Config).Elem(),
502 field: &format.FieldInfo{Name: "Port", Type: reflect.TypeFor[int]()},
503 inputValue: "invalid",
504 want: false,
505 wantErr: true,
506 },
507 }
508
509 for _, tt := range tests {
510 t.Run(tt.name, func(t *testing.T) {
511 t.Parallel()
512
513 g := &Generator{}
514
515 got, err := g.setFieldValue(tt.config, tt.field, tt.inputValue)
516 if (err != nil) != tt.wantErr {
517 t.Errorf("setFieldValue() error = %v, wantErr %v", err, tt.wantErr)
518
519 return
520 }
521
522 if got != tt.want {
523 t.Errorf("setFieldValue() = %v, want %v", got, tt.want)
524 }
525
526 if got && !tt.wantErr {
527 if tt.field.Name == "Port" {
528 wantPort := atoiOrZero(tt.inputValue)
529 if gotPort := tt.config.FieldByName("Port").Int(); int(gotPort) != wantPort {
530 t.Errorf("setFieldValue() set Port = %v, want %v", gotPort, wantPort)
531 }
532 }
533 }
534 })
535 }
536 }
537
538 func TestGenerator_printError(t *testing.T) {
539 t.Parallel()
540
541 tests := []struct {
542 name string
543 fieldName string
544 errorMsg string
545 }{
546 {
547 name: "basic error",
548 fieldName: "Port",
549 errorMsg: "invalid format",
550 },
551 }
552
553 for _, tt := range tests {
554 t.Run(tt.name, func(t *testing.T) {
555 t.Parallel()
556
557 g := &Generator{}
558
559 g.printError(tt.fieldName, tt.errorMsg)
560 })
561 }
562 }
563
564 func TestGenerator_printInvalidType(t *testing.T) {
565 t.Parallel()
566
567 tests := []struct {
568 name string
569 fieldName string
570 typeName string
571 }{
572 {
573 name: "invalid type",
574 fieldName: "Port",
575 typeName: "int",
576 },
577 }
578
579 for _, tt := range tests {
580 t.Run(tt.name, func(t *testing.T) {
581 t.Parallel()
582
583 g := &Generator{}
584
585 g.printInvalidType(tt.fieldName, tt.typeName)
586 })
587 }
588 }
589
590 // atoiOrZero converts a string to an int, returning 0 on error.
591 func atoiOrZero(s string) int {
592 i, _ := strconv.Atoi(s)
593
594 return i
595 }
596
597 // newMockServiceConfig creates a new mockServiceConfig with an initialized Config.
598 func newMockServiceConfig() *mockServiceConfig {
599 return &mockServiceConfig{
600 Config: &mockConfig{},
601 }
602 }
603
604 // TestGenerator_NilConfigInitialization tests that a service with nil Config gets properly initialized.
605 // This is a regression test for the nil config fix in basic.go:45-53.
606 func TestGenerator_NilConfigInitialization(t *testing.T) {
607 t.Parallel()
608
609 testCases := []struct {
610 name string
611 service types.Service
612 props map[string]string
613 input string
614 want *mockConfig
615 wantErr bool
616 }{
617 {
618 name: "nil config gets initialized with defaults",
619 service: &mockServiceNilConfig{Config: nil},
620 props: map[string]string{},
621 input: "\n8080\n",
622 want: &mockConfig{
623 Host: "localhost",
624 Port: 8080,
625 },
626 wantErr: false,
627 },
628 {
629 name: "nil config gets initialized with provided props",
630 service: &mockServiceNilConfig{Config: nil},
631 props: map[string]string{"host": "example.com", "port": "9090"},
632 input: "",
633 want: &mockConfig{
634 Host: "example.com",
635 Port: 9090,
636 },
637 wantErr: false,
638 },
639 {
640 name: "nil config error on invalid input",
641 service: &mockServiceNilConfig{Config: nil},
642 props: map[string]string{},
643 input: "\ninvalid\n",
644 want: nil,
645 wantErr: true,
646 },
647 }
648
649 for _, tt := range testCases {
650 t.Run(tt.name, func(t *testing.T) {
651 t.Parallel()
652
653 // Set up pipe for stdin simulation
654 r, w, err := os.Pipe()
655 if err != nil {
656 t.Fatal(err)
657 }
658
659 g := &Generator{Input: r}
660
661 defer func() {
662 _ = w.Close()
663 _ = r.Close()
664 }()
665
666 // Write input to the pipe
667 _, err = w.WriteString(tt.input)
668 if err != nil {
669 t.Fatal(err)
670 }
671
672 _ = w.Close()
673
674 got, err := g.Generate(tt.service, tt.props, nil)
675 if (err != nil) != tt.wantErr {
676 t.Errorf("Generate() error = %v, wantErr %v", err, tt.wantErr)
677
678 return
679 }
680
681 if !tt.wantErr {
682 gotConfig, ok := got.(*mockConfig)
683 if !ok {
684 t.Errorf("Generate() returned type %T, want *mockConfig", got)
685
686 return
687 }
688
689 // Verify the config was initialized (not nil)
690 if gotConfig == nil {
691 t.Error("Generate() returned nil config, expected initialized config")
692
693 return
694 }
695
696 if gotConfig.Host != tt.want.Host {
697 t.Errorf("Generate() host = %v, want %v", gotConfig.Host, tt.want.Host)
698 }
699
700 if gotConfig.Port != tt.want.Port {
701 t.Errorf("Generate() port = %v, want %v", gotConfig.Port, tt.want.Port)
702 }
703
704 // Also verify that the service's internal Config field was initialized
705 if mockSvc, ok := tt.service.(*mockServiceNilConfig); ok {
706 if mockSvc.Config == nil {
707 t.Error("Generate() left service.Config nil, expected initialized config")
708 }
709
710 // Optionally verify Host/Port match
711 if mockSvc.Config != nil && mockSvc.Config.Host != tt.want.Host {
712 t.Errorf("service.Config.Host = %v, want %v", mockSvc.Config.Host, tt.want.Host)
713 }
714
715 if mockSvc.Config != nil && mockSvc.Config.Port != tt.want.Port {
716 t.Errorf("service.Config.Port = %v, want %v", mockSvc.Config.Port, tt.want.Port)
717 }
718 }
719 }
720 })
721 }
722 }
723
724 // TestGenerator_DefaultsAndPropsOverrideExistingConfig tests that provided props
725 // override the default values in an existing config.
726 func TestGenerator_DefaultsAndPropsOverrideExistingConfig(t *testing.T) {
727 t.Parallel()
728
729 testCases := []struct {
730 name string
731 service *mockServiceConfig
732 props map[string]string
733 input string
734 want *mockConfig
735 wantErr bool
736 }{
737 {
738 name: "props override defaults",
739 service: &mockServiceConfig{Config: &mockConfig{Host: "existing.com", Port: 3000}},
740 props: map[string]string{"port": "9000"},
741 input: "",
742 want: &mockConfig{
743 Host: "localhost", // defaults are used when not in props
744 Port: 9000,
745 },
746 wantErr: false,
747 },
748 {
749 name: "user input overrides defaults",
750 service: &mockServiceConfig{Config: &mockConfig{Host: "original.com", Port: 4000}},
751 props: map[string]string{},
752 input: "\n5000\n",
753 want: &mockConfig{
754 Host: "localhost", // defaults are used when not in props
755 Port: 5000,
756 },
757 wantErr: false,
758 },
759 }
760
761 for _, tt := range testCases {
762 t.Run(tt.name, func(t *testing.T) {
763 t.Parallel()
764
765 // Set up pipe for stdin simulation
766 r, w, err := os.Pipe()
767 if err != nil {
768 t.Fatal(err)
769 }
770
771 g := &Generator{Input: r}
772
773 defer func() {
774 _ = w.Close()
775 _ = r.Close()
776 }()
777
778 // Write input to the pipe
779 _, err = w.WriteString(tt.input)
780 if err != nil {
781 t.Fatal(err)
782 }
783
784 _ = w.Close()
785
786 got, err := g.Generate(tt.service, tt.props, nil)
787 if (err != nil) != tt.wantErr {
788 t.Errorf("Generate() error = %v, wantErr %v", err, tt.wantErr)
789
790 return
791 }
792
793 if !tt.wantErr {
794 gotConfig, ok := got.(*mockConfig)
795 if !ok {
796 t.Errorf("Generate() returned type %T, want *mockConfig", got)
797
798 return
799 }
800
801 if gotConfig.Host != tt.want.Host {
802 t.Errorf("Generate() host = %v, want %v", gotConfig.Host, tt.want.Host)
803 }
804
805 if gotConfig.Port != tt.want.Port {
806 t.Errorf("Generate() port = %v, want %v", gotConfig.Port, tt.want.Port)
807 }
808 }
809 })
810 }
811 }
812
813 // TestGenerator_ServiceWithoutConfigField tests that services without a Config field
814 // return ErrInvalidConfigField.
815 func TestGenerator_ServiceWithoutConfigField(t *testing.T) {
816 t.Parallel()
817
818 // Set up pipe for stdin simulation
819 r, w, err := os.Pipe()
820 if err != nil {
821 t.Fatal(err)
822 }
823
824 g := &Generator{Input: r}
825
826 defer func() {
827 _ = w.Close()
828 _ = r.Close()
829 }()
830
831 // Write empty input to the pipe
832 _, err = w.WriteString("")
833 if err != nil {
834 t.Fatal(err)
835 }
836
837 _ = w.Close()
838
839 // Service without Config field should return ErrInvalidConfigField
840 _, err = g.Generate(&mockServiceWithoutConfig{}, map[string]string{}, nil)
841 if err == nil {
842 t.Error("Generate() expected error for service without Config field")
843
844 return
845 }
846
847 if !errors.Is(err, ErrInvalidConfigField) {
848 t.Errorf("Generate() error = %v, want ErrInvalidConfigField", err)
849 }
850 }
851
852 // TestGenerator_IgnoresInvalidFieldNames tests that invalid/unknown field names
853 // in props are silently ignored and do not cause errors.
854 func TestGenerator_IgnoresInvalidFieldNames(t *testing.T) {
855 t.Parallel()
856
857 // Set up pipe for stdin simulation
858 r, w, err := os.Pipe()
859 if err != nil {
860 t.Fatal(err)
861 }
862
863 g := &Generator{Input: r}
864
865 defer func() {
866 _ = w.Close()
867 _ = r.Close()
868 }()
869
870 // Write input to the pipe
871 _, err = w.WriteString("\n8080\n")
872 if err != nil {
873 t.Fatal(err)
874 }
875
876 _ = w.Close()
877
878 // Props with invalid field name should not cause an error,
879 // it should just be ignored (unknown props are silently ignored)
880 service := newMockServiceConfig()
881
882 got, err := g.Generate(service, map[string]string{"invalid_field": "value"}, nil)
883 if err != nil {
884 t.Errorf("Generate() error = %v, wantErr false", err)
885
886 return
887 }
888
889 // Verify that the config was still generated with defaults
890 gotConfig, ok := got.(*mockConfig)
891 if !ok {
892 t.Errorf("Generate() returned type %T, want *mockConfig", got)
893
894 return
895 }
896
897 if gotConfig.Host != "localhost" {
898 t.Errorf("Generate() host = %v, want localhost (default)", gotConfig.Host)
899 }
900
901 if gotConfig.Port != 8080 {
902 t.Errorf("Generate() port = %v, want 8080", gotConfig.Port)
903 }
904 }