TestNil tests the behaviour when passing nil or pointers to nil values to some methods. Note: This test is only executed if the initial connection to S3 works.
(t *testing.T)
| 152 | // |
| 153 | // Note: This test is only executed if the initial connection to S3 works. |
| 154 | func TestNil(t *testing.T) { |
| 155 | if !checkConnection() { |
| 156 | t.Skip("No connection to S3 could be established. Probably not running in a proper test environment.") |
| 157 | } |
| 158 | |
| 159 | // Test setting nil |
| 160 | |
| 161 | t.Run("set nil with JSON marshalling", func(t *testing.T) { |
| 162 | client := createClient(t, encoding.JSON) |
| 163 | err := client.Set("foo", nil) |
| 164 | if err == nil { |
| 165 | t.Error("Expected an error") |
| 166 | } |
| 167 | }) |
| 168 | |
| 169 | t.Run("set nil with Gob marshalling", func(t *testing.T) { |
| 170 | client := createClient(t, encoding.Gob) |
| 171 | err := client.Set("foo", nil) |
| 172 | if err == nil { |
| 173 | t.Error("Expected an error") |
| 174 | } |
| 175 | }) |
| 176 | |
| 177 | // Test passing nil or pointer to nil value for retrieval |
| 178 | |
| 179 | createTest := func(codec encoding.Codec) func(t *testing.T) { |
| 180 | return func(t *testing.T) { |
| 181 | client := createClient(t, codec) |
| 182 | |
| 183 | // Prep |
| 184 | err := client.Set("foo", test.Foo{Bar: "baz"}) |
| 185 | if err != nil { |
| 186 | t.Error(err) |
| 187 | } |
| 188 | |
| 189 | _, err = client.Get("foo", nil) // actually nil |
| 190 | if err == nil { |
| 191 | t.Error("An error was expected") |
| 192 | } |
| 193 | |
| 194 | var i interface{} // actually nil |
| 195 | _, err = client.Get("foo", i) |
| 196 | if err == nil { |
| 197 | t.Error("An error was expected") |
| 198 | } |
| 199 | |
| 200 | var valPtr *test.Foo // nil value |
| 201 | _, err = client.Get("foo", valPtr) |
| 202 | if err == nil { |
| 203 | t.Error("An error was expected") |
| 204 | } |
| 205 | } |
| 206 | } |
| 207 | t.Run("get with nil / nil value parameter", createTest(encoding.JSON)) |
| 208 | t.Run("get with nil / nil value parameter", createTest(encoding.Gob)) |
| 209 | } |
| 210 | |
| 211 | // TestClose tests if the close method returns any errors. |
nothing calls this directly
no test coverage detected