Debian Codegraph @

pkg/generators/router_test.go

raw symbols SCIP
1 package generatorsscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/generators`/
2
3 import (
4 "ioscip-go gomod github.com/golang/go/src . io/"
5 "stringsscip-go gomod github.com/golang/go/src . strings/"
6 "testingscip-go gomod github.com/golang/go/src . testing/"
7
8 "github.com/stretchr/testify/assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/"
9 "github.com/stretchr/testify/requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/"
10
11 "github.com/nicholas-fedor/shoutrrr/pkg/generators/basicscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/generators/basic`/"
12 "github.com/nicholas-fedor/shoutrrr/pkg/generators/xoauth2scip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/generators/xoauth2`/"
13 "github.com/nicholas-fedor/shoutrrr/pkg/services/chat/telegramscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/telegram`/"
14 "github.com/nicholas-fedor/shoutrrr/pkg/typesscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/types`/"
15 )
16
17 // TestWithInput tests the WithInput option function to ensure it properly
18 // sets the input reader in generatorConfig.
19 func TestWithInputscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/generators`/TestWithInput().(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#) {
20 t.Parallelscip-go gomod github.com/golang/go/src . testing/T#Parallel().()
21
22 type args struct {
23 reader ioscip-go gomod github.com/golang/go/src . io/.Readerscip-go gomod github.com/golang/go/src . io/Reader#
24 }
25
26 tests := []struct {
27 name string
28 args args
29 verify func(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#, config *generatorConfigscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/generators`/generatorConfig#)
30 }{
31 {
32 name: "sets input reader correctly",
33 args: args{
34 reader: stringsscip-go gomod github.com/golang/go/src . strings/.NewReaderscip-go gomod github.com/golang/go/src . strings/NewReader().("test input"),
35 },
36 verify: func(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#, config *generatorConfigscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/generators`/generatorConfig#) {
37 t.Helperscip-go gomod github.com/golang/go/src . testing/common#Helper().()
38 assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.NotNilscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/NotNil().(t, config.inputscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/generators`/generatorConfig#input., "input should be set")
39
40 // Verify the reader works by reading from it
41 buf := make([]byte, 10)
42 n, err := config.inputscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/generators`/generatorConfig#input..Readscip-go gomod github.com/golang/go/src . io/Reader#Read().(buf)
43 requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.NoErrorscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/NoError().(t, err, "should be able to read from input")
44 assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/Equal().(t, 10, n, "should read all bytes")
45 assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/Equal().(t, "test input", string(buf), "content should match")
46 },
47 },
48 {
49 name: "sets nil reader",
50 args: args{
51 reader: nil,
52 },
53 verify: func(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#, config *generatorConfigscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/generators`/generatorConfig#) {
54 t.Helperscip-go gomod github.com/golang/go/src . testing/common#Helper().()
55 assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.Nilscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/Nil().(t, config.inputscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/generators`/generatorConfig#input., "input should be nil")
56 },
57 },
58 }
59
60 for _, tt := range tests {
61 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#) {
62 t.Parallelscip-go gomod github.com/golang/go/src . testing/T#Parallel().()
63
64 // Create a config and apply the option
65 config := &generatorConfigscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/generators`/generatorConfig#{}
66 option := WithInputscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/generators`/WithInput().(tt.args.reader)
67 option(config)
68
69 // Verify the config
70 tt.verify(t, config)
71 })
72 }
73 }
74
75 // TestListGenerators tests that ListGenerators returns the expected list
76 // of available generators.
77 func TestListGeneratorsscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/generators`/TestListGenerators().(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#) {
78 t.Parallelscip-go gomod github.com/golang/go/src . testing/T#Parallel().()
79
80 tests := []struct {
81 name string
82 wantContain []string
83 wantLen int
84 }{
85 {
86 name: "returns non-empty list with expected generators",
87 wantContain: []string{"basic", "oauth2", "telegram"},
88 wantLen: 3,
89 },
90 }
91
92 for _, tt := range tests {
93 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#) {
94 t.Parallelscip-go gomod github.com/golang/go/src . testing/T#Parallel().()
95
96 got := ListGeneratorsscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/generators`/ListGenerators().()
97
98 // Verify the list is not empty and has expected length
99 requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.NotEmptyscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/NotEmpty().(t, got, "ListGenerators() should return non-empty list")
100 assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.Lenscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/Len().(t, got, tt.wantLen, "ListGenerators() should return %d generators", tt.wantLen)
101
102 // Verify it contains expected generators
103 for _, want := range tt.wantContain {
104 assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.Containsscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/Contains().(t, got, want, "ListGenerators() should contain %q", want)
105 }
106 })
107 }
108 }
109
110 // TestNewGenerator tests the NewGenerator function with various scenarios
111 // including success cases and error cases.
112 func TestNewGeneratorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/generators`/TestNewGenerator().(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#) {
113 t.Parallelscip-go gomod github.com/golang/go/src . testing/T#Parallel().()
114
115 type args struct {
116 identifier string
117 opts []GeneratorOptionscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/generators`/GeneratorOption#
118 }
119
120 tests := []struct {
121 name string
122 args args
123 wantErr bool
124 wantErrIs error
125 verifyType func(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#, g typesscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/types`/.Generatorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/types`/Generator#)
126 verifyInputSet bool
127 }{
128 {
129 name: "successful creation of basic generator without options",
130 args: args{
131 identifier: "basic",
132 opts: nil,
133 },
134 wantErr: false,
135 verifyType: func(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#, g typesscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/types`/.Generatorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/types`/Generator#) {
136 t.Helperscip-go gomod github.com/golang/go/src . testing/common#Helper().()
137
138 bg, ok := g.(*basicscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/generators/basic`/.Generatorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/generators/basic`/Generator#)
139 requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.Truescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/True().(t, ok, "generator should be *basic.Generator")
140 assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.Nilscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/Nil().(t, bg.Inputscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/generators/basic`/Generator#Input., "Input should be nil when no WithInput option")
141 },
142 },
143 {
144 name: "successful creation of basic generator with WithInput option",
145 args: args{
146 identifier: "basic",
147 opts: []GeneratorOptionscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/generators`/GeneratorOption#{
148 WithInputscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/generators`/WithInput().(stringsscip-go gomod github.com/golang/go/src . strings/.NewReaderscip-go gomod github.com/golang/go/src . strings/NewReader().("test data")),
149 },
150 },
151 wantErr: false,
152 verifyInputSet: true,
153 verifyType: func(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#, g typesscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/types`/.Generatorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/types`/Generator#) {
154 t.Helperscip-go gomod github.com/golang/go/src . testing/common#Helper().()
155
156 bg, ok := g.(*basicscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/generators/basic`/.Generatorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/generators/basic`/Generator#)
157 requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.Truescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/True().(t, ok, "generator should be *basic.Generator")
158 assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.NotNilscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/NotNil().(t, bg.Inputscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/generators/basic`/Generator#Input., "Input should be set")
159 },
160 },
161 {
162 name: "successful creation of oauth2 generator",
163 args: args{
164 identifier: "oauth2",
165 opts: nil,
166 },
167 wantErr: false,
168 verifyType: func(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#, g typesscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/types`/.Generatorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/types`/Generator#) {
169 t.Helperscip-go gomod github.com/golang/go/src . testing/common#Helper().()
170
171 _, ok := g.(*xoauth2scip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/generators/xoauth2`/.Generatorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/generators/xoauth2`/Generator#)
172 assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.Truescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/True().(t, ok, "generator should be *xouath2.Generator")
173 },
174 },
175 {
176 name: "successful creation of telegram generator without options",
177 args: args{
178 identifier: "telegram",
179 opts: nil,
180 },
181 wantErr: false,
182 verifyType: func(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#, g typesscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/types`/.Generatorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/types`/Generator#) {
183 t.Helperscip-go gomod github.com/golang/go/src . testing/common#Helper().()
184
185 tg, ok := g.(*telegramscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/telegram`/.Generatorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/telegram`/Generator#)
186 requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.Truescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/True().(t, ok, "generator should be *telegram.Generator")
187 assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.Nilscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/Nil().(t, tg.Readerscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/telegram`/Generator#Reader., "Reader should be nil when no WithInput option")
188 },
189 },
190 {
191 name: "successful creation of telegram generator with WithInput option",
192 args: args{
193 identifier: "telegram",
194 opts: []GeneratorOptionscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/generators`/GeneratorOption#{
195 WithInputscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/generators`/WithInput().(stringsscip-go gomod github.com/golang/go/src . strings/.NewReaderscip-go gomod github.com/golang/go/src . strings/NewReader().("telegram test")),
196 },
197 },
198 wantErr: false,
199 verifyType: func(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#, g typesscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/types`/.Generatorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/types`/Generator#) {
200 t.Helperscip-go gomod github.com/golang/go/src . testing/common#Helper().()
201
202 tg, ok := g.(*telegramscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/telegram`/.Generatorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/telegram`/Generator#)
203 requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.Truescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/True().(t, ok, "generator should be *telegram.Generator")
204 assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.NotNilscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/NotNil().(t, tg.Readerscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/telegram`/Generator#Reader., "Reader should be set")
205 },
206 },
207 {
208 name: "error on unknown generator",
209 args: args{
210 identifier: "unknown",
211 opts: nil,
212 },
213 wantErr: true,
214 wantErrIs: ErrUnknownGeneratorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/generators`/ErrUnknownGenerator.,
215 verifyType: func(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#, g typesscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/types`/.Generatorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/types`/Generator#) {
216 t.Helperscip-go gomod github.com/golang/go/src . testing/common#Helper().()
217 assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.Nilscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/Nil().(t, g, "generator should be nil on error")
218 },
219 },
220 {
221 name: "error on empty identifier",
222 args: args{
223 identifier: "",
224 opts: nil,
225 },
226 wantErr: true,
227 wantErrIs: ErrUnknownGeneratorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/generators`/ErrUnknownGenerator.,
228 verifyType: func(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#, g typesscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/types`/.Generatorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/types`/Generator#) {
229 t.Helperscip-go gomod github.com/golang/go/src . testing/common#Helper().()
230 assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.Nilscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/Nil().(t, g, "generator should be nil on error")
231 },
232 },
233 {
234 name: "case insensitive - uppercase BASIC",
235 args: args{
236 identifier: "BASIC",
237 opts: nil,
238 },
239 wantErr: false,
240 verifyType: func(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#, g typesscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/types`/.Generatorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/types`/Generator#) {
241 t.Helperscip-go gomod github.com/golang/go/src . testing/common#Helper().()
242
243 _, ok := g.(*basicscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/generators/basic`/.Generatorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/generators/basic`/Generator#)
244 assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.Truescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/True().(t, ok, "generator should be *basic.Generator (case insensitive)")
245 },
246 },
247 {
248 name: "case insensitive - mixed case Oauth2",
249 args: args{
250 identifier: "Oauth2",
251 opts: nil,
252 },
253 wantErr: false,
254 verifyType: func(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#, g typesscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/types`/.Generatorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/types`/Generator#) {
255 t.Helperscip-go gomod github.com/golang/go/src . testing/common#Helper().()
256
257 _, ok := g.(*xoauth2scip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/generators/xoauth2`/.Generatorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/generators/xoauth2`/Generator#)
258 assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.Truescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/True().(t, ok, "generator should be *xouath2.Generator (case insensitive)")
259 },
260 },
261 {
262 name: "multiple options - only last WithInput wins",
263 args: args{
264 identifier: "basic",
265 opts: []GeneratorOptionscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/generators`/GeneratorOption#{
266 WithInputscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/generators`/WithInput().(stringsscip-go gomod github.com/golang/go/src . strings/.NewReaderscip-go gomod github.com/golang/go/src . strings/NewReader().("first")),
267 WithInputscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/generators`/WithInput().(stringsscip-go gomod github.com/golang/go/src . strings/.NewReaderscip-go gomod github.com/golang/go/src . strings/NewReader().("second")),
268 },
269 },
270 wantErr: false,
271 verifyType: func(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#, g typesscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/types`/.Generatorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/types`/Generator#) {
272 t.Helperscip-go gomod github.com/golang/go/src . testing/common#Helper().()
273
274 bg, ok := g.(*basicscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/generators/basic`/.Generatorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/generators/basic`/Generator#)
275 requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.Truescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/True().(t, ok, "generator should be *basic.Generator")
276 assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.NotNilscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/NotNil().(t, bg.Inputscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/generators/basic`/Generator#Input., "Input should be set with the last option")
277
278 // Note: We verify the Input is set but don't read from it,
279 // as strings.Reader is single-use and would cause EOF error
280 // if the generator already consumed it.
281 },
282 },
283 }
284
285 for _, tt := range tests {
286 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#) {
287 t.Parallelscip-go gomod github.com/golang/go/src . testing/T#Parallel().()
288
289 got, err := NewGeneratorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/generators`/NewGenerator().(tt.args.identifier, tt.args.opts...)
290
291 if tt.wantErr {
292 requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.Errorscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/Error().(t, err, "NewGenerator() should return an error")
293
294 if tt.wantErrIs != nil {
295 requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.ErrorIsscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/ErrorIs().(t, err, tt.wantErrIs, "error should wrap %v", tt.wantErrIs)
296 }
297 } else {
298 requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.NoErrorscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/NoError().(t, err, "NewGenerator() should not return an error")
299 requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.NotNilscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/NotNil().(t, got, "NewGenerator() should return a non-nil generator")
300
301 // Verify it implements the types.Generator interface
302 _ = got
303
304 // Run type-specific verification
305 if tt.verifyType != nil {
306 tt.verifyType(t, got)
307 }
308 }
309
310 // Run common verification
311 if tt.verifyType != nil {
312 tt.verifyType(t, got)
313 }
314 })
315 }
316 }
317
318 // TestNewGenerator_VerifyInterface ensures all created generators implement
319 // the types.Generator interface properly.
320 func TestNewGenerator_VerifyInterfacescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/generators`/TestNewGenerator_VerifyInterface().(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#) {
321 t.Parallelscip-go gomod github.com/golang/go/src . testing/T#Parallel().()
322
323 generators := []string{"basic", "oauth2", "telegram"}
324
325 for _, gen := range generators {
326 t.Runscip-go gomod github.com/golang/go/src . testing/T#Run().(gen, func(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#) {
327 t.Parallelscip-go gomod github.com/golang/go/src . testing/T#Parallel().()
328
329 g, err := NewGeneratorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/generators`/NewGenerator().(gen)
330 requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.NoErrorscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/NoError().(t, err, "should create %s generator", gen)
331 requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.NotNilscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/NotNil().(t, g, "generator should not be nil")
332
333 // Verify interface implementation
334 assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.Implementsscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/Implements().(t, (*typesscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/types`/.Generatorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/types`/Generator#)(nil), g, "generator should implement types.Generator")
335
336 // Verify the Generate method exists and has correct signature
337 // by checking it can be called (with nil args for this test)
338 assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.NotPanicsscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/NotPanics().(t, func() {
339 // We just verify the method exists, not the actual functionality
340 _ = g.Generatescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/types`/Generator#Generate.
341 }, "generator should have Generate method")
342 })
343 }
344 }
345
346 // TestErrUnknownGenerator checks that ErrUnknownGenerator is properly defined
347 // and can be used with errors.Is.
348 func TestErrUnknownGeneratorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/generators`/TestErrUnknownGenerator().(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#) {
349 t.Parallelscip-go gomod github.com/golang/go/src . testing/T#Parallel().()
350
351 // Verify the error is defined
352 requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.Errorscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/Error().(t, ErrUnknownGeneratorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/generators`/ErrUnknownGenerator., "ErrUnknownGenerator should be defined")
353 assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/Equal().(t, "unknown generator", ErrUnknownGeneratorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/generators`/ErrUnknownGenerator..Error(), "error message should match")
354
355 // Verify it works with errors.Is
356 _, err := NewGeneratorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/generators`/NewGenerator().("nonexistent")
357 requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.Errorscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/Error().(t, err)
358 requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.ErrorIsscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/ErrorIs().(t, err, ErrUnknownGeneratorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/generators`/ErrUnknownGenerator., "error should be ErrUnknownGenerator")
359 assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.ErrorIsscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/ErrorIs().(t, err, ErrUnknownGeneratorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/generators`/ErrUnknownGenerator., "errors.Is should work")
360 }