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