MCPcopy Create free account
hub / github.com/chainloop-dev/chainloop / TestExtractCreds

Function TestExtractCreds

pkg/blobmanager/s3/provider_test.go:128–181  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

126}
127
128func TestExtractCreds(t *testing.T) {
129 tetCases := []struct {
130 name string
131 location string
132 credsJSON []byte
133 wantErr bool
134 }{
135 {
136 name: "valid credentials",
137 location: "mybucket",
138 credsJSON: []byte(`{
139 "AccessKeyID": "keyID",
140 "SecretAccessKey": "keySecret",
141 "Region": "region-1"
142 }`),
143 },
144 {
145 name: "invalid location, missing bucket",
146 location: "",
147 wantErr: true,
148 credsJSON: []byte(`{
149 "AccessKeyID": "test",
150 "SecretAccessKey": "keySecret",
151 "Region": "test"
152 }`),
153 },
154 {
155 name: "invalid credentials, missing secret",
156 location: "account/container",
157 credsJSON: []byte(`{
158 "AccessKeyID": "test",
159 "Region": "region-1"
160 }`),
161 wantErr: true,
162 },
163 }
164
165 for _, tc := range tetCases {
166 t.Run(tc.name, func(t *testing.T) {
167 creds, err := extractCreds(tc.location, tc.credsJSON)
168 if tc.wantErr {
169 assert.Error(t, err)
170 } else {
171 assert.NoError(t, err)
172 assert.Equal(t, &Credentials{
173 Region: "region-1",
174 SecretAccessKey: "keySecret",
175 AccessKeyID: "keyID",
176 Location: tc.location,
177 }, creds)
178 }
179 })
180 }
181}
182
183func TestProviderID(t *testing.T) {
184 assert.Equal(t, "AWS-S3", NewBackendProvider(nil).ID())

Callers

nothing calls this directly

Calls 3

extractCredsFunction · 0.70
ErrorMethod · 0.65
RunMethod · 0.45

Tested by

no test coverage detected