@@ -135,20 +135,39 @@ func TestWithUserAgent(t *testing.T) {
135135}
136136
137137func TestWithAuthMethod (t * testing.T ) {
138- t .Run ("api key" , func (t * testing.T ) {
139- c := & configMock {
140- publicKey : "test-public" ,
141- privateKey : "test-private" ,
142- }
143- e := newEvent (withAuthMethod (c ))
144- assert .Equal (t , "api_key" , e .Properties ["auth_method" ])
145- })
146- t .Run ("Oauth" , func (t * testing.T ) {
147- e := newEvent (withAuthMethod (& configMock {
148- accessToken : "test" ,
149- }))
150- assert .Equal (t , "oauth" , e .Properties ["auth_method" ])
151- })
138+ tests := []struct {
139+ name string
140+ cfg * configMock
141+ expected string
142+ }{
143+ {
144+ name : "api key" ,
145+ cfg : & configMock {
146+ authType : config .APIKeys ,
147+ },
148+ expected : "api_key" ,
149+ },
150+ {
151+ name : "user account" ,
152+ cfg : & configMock {
153+ authType : config .UserAccount ,
154+ },
155+ expected : "oauth" ,
156+ },
157+ {
158+ name : "service account" ,
159+ cfg : & configMock {
160+ authType : config .ServiceAccount ,
161+ },
162+ expected : "service_account" ,
163+ },
164+ }
165+ for _ , tt := range tests {
166+ t .Run (tt .name , func (t * testing.T ) {
167+ e := newEvent (withAuthMethod (tt .cfg ))
168+ assert .Equal (t , tt .expected , e .Properties ["auth_method" ])
169+ })
170+ }
152171}
153172
154173func TestWithService (t * testing.T ) {
@@ -446,15 +465,13 @@ func Test_withOutput(t *testing.T) {
446465}
447466
448467type configMock struct {
449- name string
450- publicKey string
451- privateKey string
452- accessToken string
453- service string
454- url string
455- project string
456- org string
457- out string
468+ name string
469+ authType config.AuthMechanism
470+ service string
471+ url string
472+ project string
473+ org string
474+ out string
458475}
459476
460477var _ Authenticator = configMock {}
@@ -479,16 +496,8 @@ func (c configMock) OpsManagerURL() string {
479496 return c .url
480497}
481498
482- func (c configMock ) PublicAPIKey () string {
483- return c .publicKey
484- }
485-
486- func (c configMock ) PrivateAPIKey () string {
487- return c .privateKey
488- }
489-
490- func (c configMock ) AccessToken () string {
491- return c .accessToken
499+ func (c configMock ) AuthType () config.AuthMechanism {
500+ return c .authType
492501}
493502
494503func (c configMock ) Output () string {
0 commit comments