@@ -22,7 +22,6 @@ import (
2222
2323 "github.com/go-git/go-git/v5/plumbing/transport"
2424 "github.com/go-git/go-git/v5/plumbing/transport/http"
25- "github.com/go-git/go-git/v5/plumbing/transport/ssh"
2625 corev1 "k8s.io/api/core/v1"
2726)
2827
@@ -65,39 +64,33 @@ var (
6564 }
6665)
6766
68- func TestAuthMethodFromSecret (t * testing.T ) {
67+ func TestAuthSecretStrategyForURL (t * testing.T ) {
6968 tests := []struct {
70- name string
71- url string
72- secret corev1.Secret
73- want transport.AuthMethod
74- wantErr bool
69+ name string
70+ url string
71+ want AuthSecretStrategy
7572 }{
76- {"HTTP" , "http://git.example.com/org/repo.git" , basicAuthSecretFixture , & http. BasicAuth {}, false },
77- {"HTTPS" , "https://git.example.com/org/repo.git" , basicAuthSecretFixture , & http. BasicAuth {}, false },
78- {"SSH" , "ssh://git.example.com:2222/org/repo.git" , privateKeySecretFixture , & ssh. PublicKeys {}, false },
79- {"unsupported" , "protocol://git. example.com/org/repo.git " , corev1. Secret {}, nil , false },
73+ {"HTTP" , "http://git.example.com/org/repo.git" , & BasicAuth {}},
74+ {"HTTPS" , "https://git.example.com/org/repo.git" , & BasicAuth {}},
75+ {"SSH" , "ssh://git.example.com:2222/org/repo.git" , & PublicKeyAuth {} },
76+ {"unsupported" , "protocol://example.com" , nil },
8077 }
8178 for _ , tt := range tests {
8279 t .Run (tt .name , func (t * testing.T ) {
83- got , err := AuthMethodFromSecret (tt .url , tt .secret )
84- if (err != nil ) != tt .wantErr {
85- t .Errorf ("AuthMethodFromSecret() error = %v, wantErr %v" , err , tt .wantErr )
86- return
87- }
80+ got := AuthSecretStrategyForURL (tt .url )
8881 if reflect .TypeOf (got ) != reflect .TypeOf (tt .want ) {
89- t .Errorf ("AuthMethodFromSecret () got = %v, want %v" , got , tt .want )
82+ t .Errorf ("AuthSecretStrategyForURL () got = %v, want %v" , got , tt .want )
9083 }
9184 })
9285 }
9386}
9487
95- func TestBasicAuthFromSecret (t * testing.T ) {
88+ func TestBasicAuthStrategy_Method (t * testing.T ) {
9689 tests := []struct {
9790 name string
9891 secret corev1.Secret
9992 modify func (secret * corev1.Secret )
100- want * http. BasicAuth
93+ want transport. AuthMethod
10194 wantErr bool
10295 }{
10396 {"username and password" , basicAuthSecretFixture , nil , & http.BasicAuth {Username : "git" , Password : "password" }, false },
@@ -111,19 +104,20 @@ func TestBasicAuthFromSecret(t *testing.T) {
111104 if tt .modify != nil {
112105 tt .modify (secret )
113106 }
114- got , err := BasicAuthFromSecret (* secret )
107+ s := & BasicAuth {}
108+ got , err := s .Method (* secret )
115109 if (err != nil ) != tt .wantErr {
116- t .Errorf ("BasicAuthFromSecret () error = %v, wantErr %v" , err , tt .wantErr )
110+ t .Errorf ("Method () error = %v, wantErr %v" , err , tt .wantErr )
117111 return
118112 }
119113 if ! reflect .DeepEqual (got , tt .want ) {
120- t .Errorf ("BasicAuthFromSecret () got = %v, want %v" , got , tt .want )
114+ t .Errorf ("Method () got = %v, want %v" , got , tt .want )
121115 }
122116 })
123117 }
124118}
125119
126- func TestPublicKeysFromSecret (t * testing.T ) {
120+ func TestPublicKeyStrategy_Method (t * testing.T ) {
127121 tests := []struct {
128122 name string
129123 secret corev1.Secret
@@ -143,9 +137,10 @@ func TestPublicKeysFromSecret(t *testing.T) {
143137 if tt .modify != nil {
144138 tt .modify (secret )
145139 }
146- _ , err := PublicKeysFromSecret (* secret )
140+ s := & PublicKeyAuth {}
141+ _ , err := s .Method (* secret )
147142 if (err != nil ) != tt .wantErr {
148- t .Errorf ("PublicKeysFromSecret () error = %v, wantErr %v" , err , tt .wantErr )
143+ t .Errorf ("Method () error = %v, wantErr %v" , err , tt .wantErr )
149144 return
150145 }
151146 })
0 commit comments