Debian Codegraph @

pkg/generators/xoauth2/xoauth2_test.go

raw symbols SCIP
1 package xoauth2scip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/generators/xoauth2`/
2
3 import (
4 "osscip-go gomod github.com/golang/go/src . os/"
5 "path/filepathscip-go gomod github.com/golang/go/src . `path/filepath`/"
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 "golang.org/x/oauth2scip-go gomod golang.org/x/oauth2 v0.36.0 `golang.org/x/oauth2`/"
11 )
12
13 func TestGenerator_Generatescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/generators/xoauth2`/TestGenerator_Generate().(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#) {
14 t.Parallelscip-go gomod github.com/golang/go/src . testing/T#Parallel().()
15
16 tests := []struct {
17 name string
18 props map[string]string
19 args []string
20 wantErr bool
21 expectPanic bool
22 errMsg string
23 }{
24 {
25 name: "gmail provider with credentials file",
26 props: map[string]string{"provider": "gmail"},
27 args: []string{"/nonexistent/credentials.json"},
28 wantErr: true,
29 errMsg: "failed to read file",
30 },
31 {
32 name: "gmail provider without args",
33 props: map[string]string{"provider": "gmail"},
34 args: []string{},
35 expectPanic: true,
36 },
37 {
38 name: "non-gmail provider with file arg",
39 props: map[string]string{"provider": "other"},
40 args: []string{"/nonexistent/config.json"},
41 wantErr: true,
42 errMsg: "failed to read file",
43 },
44 {
45 name: "no provider with file arg",
46 props: map[string]string{},
47 args: []string{"/nonexistent/config.json"},
48 wantErr: true,
49 errMsg: "failed to read file",
50 },
51 {
52 name: "interactive generator no args fails at scan",
53 props: map[string]string{},
54 args: []string{},
55 wantErr: true,
56 errMsg: "failed to scan input",
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 g := &Generatorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/generators/xoauth2`/Generator#{}
65
66 if tt.expectPanic {
67 assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.Panicsscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/Panics().(t, func() {
68 _, _ = g.Generatescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/generators/xoauth2`/Generator#Generate().(nil, tt.props, tt.args)
69 })
70
71 return
72 }
73
74 got, err := g.Generatescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/generators/xoauth2`/Generator#Generate().(nil, tt.props, tt.args)
75
76 if tt.wantErr {
77 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)
78 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, err.Error(), tt.errMsg)
79
80 return
81 }
82
83 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)
84 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, got)
85 })
86 }
87 }
88
89 func Test_generateOauth2Configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/generators/xoauth2`/Test_generateOauth2Config().(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#) {
90 t.Parallelscip-go gomod github.com/golang/go/src . testing/T#Parallel().()
91
92 type args struct {
93 conf *oauth2scip-go gomod golang.org/x/oauth2 v0.36.0 `golang.org/x/oauth2`/.Configscip-go gomod golang.org/x/oauth2 v0.36.0 `golang.org/x/oauth2`/Config#
94 host string
95 }
96
97 tests := []struct {
98 name string
99 args args
100 wantErr bool
101 errMsg string
102 }{}
103
104 for _, tt := range tests {
105 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#) {
106 t.Parallelscip-go gomod github.com/golang/go/src . testing/T#Parallel().()
107
108 got, err := generateOauth2Configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/generators/xoauth2`/generateOauth2Config().(tt.args.conf, tt.args.host)
109
110 if tt.wantErr {
111 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)
112 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, err.Error(), tt.errMsg)
113
114 return
115 }
116
117 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)
118 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, got)
119 })
120 }
121 }
122
123 func Test_oauth2GeneratorFilescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/generators/xoauth2`/Test_oauth2GeneratorFile().(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#) {
124 t.Parallelscip-go gomod github.com/golang/go/src . testing/T#Parallel().()
125
126 tests := []struct {
127 name string
128 file string
129 wantErr bool
130 errType error
131 errMsg string
132 }{
133 {
134 name: "nonexistent file",
135 file: "/nonexistent/path/config.json",
136 wantErr: true,
137 errType: ErrReadFileFailedscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/generators/xoauth2`/ErrReadFileFailed.,
138 errMsg: "failed to read file",
139 },
140 {
141 name: "invalid JSON file",
142 file: createTempFilescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/generators/xoauth2`/createTempFile().(t, "invalid json content"),
143 wantErr: true,
144 errType: ErrUnmarshalFailedscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/generators/xoauth2`/ErrUnmarshalFailed.,
145 errMsg: "failed to unmarshal JSON",
146 },
147 }
148
149 for _, tt := range tests {
150 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#) {
151 t.Parallelscip-go gomod github.com/golang/go/src . testing/T#Parallel().()
152
153 got, err := oauth2GeneratorFilescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/generators/xoauth2`/oauth2GeneratorFile().(tt.file)
154
155 if tt.wantErr {
156 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)
157 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, err.Error(), tt.errMsg)
158
159 if tt.errType != nil {
160 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.errType)
161 }
162
163 return
164 }
165
166 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)
167 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, got)
168 })
169 }
170 }
171
172 func Test_oauth2GeneratorGmailscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/generators/xoauth2`/Test_oauth2GeneratorGmail().(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#) {
173 t.Parallelscip-go gomod github.com/golang/go/src . testing/T#Parallel().()
174
175 tests := []struct {
176 name string
177 file string
178 wantErr bool
179 errType error
180 errMsg string
181 }{
182 {
183 name: "nonexistent credentials file",
184 file: "/nonexistent/path/credentials.json",
185 wantErr: true,
186 errType: ErrReadFileFailedscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/generators/xoauth2`/ErrReadFileFailed.,
187 errMsg: "failed to read file",
188 },
189 {
190 name: "invalid JSON credentials file",
191 file: createTempFilescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/generators/xoauth2`/createTempFile().(t, "invalid json content"),
192 wantErr: true,
193 errMsg: "invalid character",
194 },
195 }
196
197 for _, tt := range tests {
198 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#) {
199 t.Parallelscip-go gomod github.com/golang/go/src . testing/T#Parallel().()
200
201 got, err := oauth2GeneratorGmailscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/generators/xoauth2`/oauth2GeneratorGmail().(tt.file)
202
203 if tt.wantErr {
204 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)
205 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, err.Error(), tt.errMsg)
206
207 if tt.errType != nil {
208 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.errType)
209 }
210
211 return
212 }
213
214 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)
215 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, got)
216 })
217 }
218 }
219
220 // createTempFile creates a temporary file with the given content and returns its path.
221 func createTempFilescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/generators/xoauth2`/createTempFile().(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#, content string) string {
222 t.Helperscip-go gomod github.com/golang/go/src . testing/common#Helper().()
223
224 tmpDir := t.TempDirscip-go gomod github.com/golang/go/src . testing/common#TempDir().()
225 tmpFile := filepathscip-go gomod github.com/golang/go/src . `path/filepath`/.Joinscip-go gomod github.com/golang/go/src . `path/filepath`/Join().(tmpDir, "test-config.json")
226
227 err := osscip-go gomod github.com/golang/go/src . os/.WriteFilescip-go gomod github.com/golang/go/src . os/WriteFile().(tmpFile, []byte(content), 0o600)
228 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, "failed to create temp file")
229
230 return tmpFile
231 }