MCPcopy Create free account
hub / github.com/IceFireDB/IceFireDB / TestErrors

Function TestErrors

driver/oss/s3_test.go:93–149  ·  view source on GitHub ↗

TestErrors tests some error cases. Note: This test is only executed if the initial connection to S3 works.

(t *testing.T)

Source from the content-addressed store, hash-verified

91//
92// Note: This test is only executed if the initial connection to S3 works.
93func TestErrors(t *testing.T) {
94 if !checkConnection() {
95 t.Skip("No connection to S3 could be established. Probably not running in a proper test environment.")
96 }
97
98 // Test empty key
99 client := createClient(t, encoding.JSON)
100 err := client.Set("", "bar")
101 if err == nil {
102 t.Error("Expected an error")
103 }
104 _, err = client.Get("", new(string))
105 if err == nil {
106 t.Error("Expected an error")
107 }
108 err = client.Delete("")
109 if err == nil {
110 t.Error("Expected an error")
111 }
112
113 // Test client creation with bad options
114 options := oss.Options{
115 AWSaccessKeyID: accesskey,
116 AWSsecretAccessKey: secretkey,
117 }
118 client, err = oss.NewClient(options)
119 if err.Error() != "The BucketName in the options must not be empty" {
120 t.Error("An error was expected, but didn't occur.")
121 }
122 options = oss.Options{
123 BucketName: bucketname,
124 AWSaccessKeyID: accesskey,
125 }
126 client, err = oss.NewClient(options)
127 if err.Error() != "When passing credentials via options, you need to set BOTH AWSaccessKeyID AND AWSsecretAccessKey" {
128 t.Error("An error was expected, but didn't occur.")
129 }
130 options = oss.Options{
131 BucketName: bucketname,
132 AWSsecretAccessKey: secretkey,
133 }
134 client, err = oss.NewClient(options)
135 if err.Error() != "When passing credentials via options, you need to set BOTH AWSaccessKeyID AND AWSsecretAccessKey" {
136 t.Error("An error was expected, but didn't occur.")
137 }
138 // Bad credentials on actual AWS S3 endpoint (no custom endpoint for local Docker container)
139 options = oss.Options{
140 BucketName: bucketname,
141 AWSaccessKeyID: accesskey,
142 AWSsecretAccessKey: secretkey,
143 Region: endpoints.UsWest2RegionID,
144 }
145 _, err = oss.NewClient(options)
146 if strings.Index(err.Error(), "InvalidAccessKeyId: The AWS Access Key Id you provided does not exist in our records.") != 0 {
147 t.Errorf("An InvalidAccessKeyId error was expected, but it seems like it didn't occur. Instead, the error was: %v", err)
148 }
149}
150

Callers

nothing calls this directly

Calls 7

NewClientFunction · 0.92
checkConnectionFunction · 0.85
createClientFunction · 0.85
SetMethod · 0.80
ErrorMethod · 0.45
GetMethod · 0.45
DeleteMethod · 0.45

Tested by

no test coverage detected