TestErrors tests some error cases. Note: This test is only executed if the initial connection to S3 works.
(t *testing.T)
| 91 | // |
| 92 | // Note: This test is only executed if the initial connection to S3 works. |
| 93 | func 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 |
nothing calls this directly
no test coverage detected