~jtv/gwacl/require-storage-location

« back to all changes in this revision

Viewing changes to storage_base_test.go

  • Committer: jtv at canonical
  • Date: 2013-08-06 11:11:50 UTC
  • Revision ID: jtv@canonical.com-20130806111150-6ky59l9v5e6yunfv
Make StorageContext.AzureEndpoint required.

Show diffs side-by-side

added added

removed removed

Lines of Context:
6
6
import (
7
7
    "bytes"
8
8
    "encoding/base64"
 
9
    "errors"
9
10
    "fmt"
10
11
    "io/ioutil"
11
12
    . "launchpad.net/gocheck"
309
310
        "http://"+url.QueryEscape(account)+".blob.example.com")
310
311
}
311
312
 
312
 
func (*TestStorageContext) TestGetAccountURLDefaultsToInternationalEndpoint(c *C) {
 
313
func (*TestStorageContext) TestGetAccountURLRequiresEndpoint(c *C) {
313
314
    context := StorageContext{Account: "myaccount"}
314
315
    c.Check(
315
 
        context.getAccountURL(),
316
 
        Equals,
317
 
        "https://myaccount.blob.core.windows.net/")
 
316
        context.getAccountURL,
 
317
        Panics,
 
318
        errors.New("no Azure blob storage endpoint specified"))
318
319
}
319
320
 
320
 
func (suite *TestStorageContext) TestGetContainerURL(c *C) {
 
321
func (suite *TestStorageContext) TestGetContainerURLAddsContainer(c *C) {
321
322
    account := makeNastyURLUnfriendlyString()
322
323
    container := makeNastyURLUnfriendlyString()
323
 
    context := StorageContext{Account: account}
 
324
    context := StorageContext{
 
325
        Account:       account,
 
326
        AzureEndpoint: "http://example.com/",
 
327
    }
324
328
    c.Check(
325
329
        context.getContainerURL(container),
326
330
        Equals,
327
 
        "https://"+url.QueryEscape(account)+".blob.core.windows.net/"+url.QueryEscape(container))
 
331
        "http://"+url.QueryEscape(account)+".blob.example.com/"+url.QueryEscape(container))
 
332
}
 
333
 
 
334
func (suite *TestStorageContext) TestGetContainerURLAddsSlashIfNeeded(c *C) {
 
335
    context := StorageContext{
 
336
        Account:       "account",
 
337
        AzureEndpoint: "http://example.com",
 
338
    }
 
339
    c.Check(
 
340
        context.getContainerURL("container"),
 
341
        Equals,
 
342
        "http://account.blob.example.com/container")
328
343
}
329
344
 
330
345
func (suite *TestStorageContext) TestGetFileURL(c *C) {
331
346
    account := makeNastyURLUnfriendlyString()
332
347
    container := makeNastyURLUnfriendlyString()
333
348
    file := makeNastyURLUnfriendlyString()
334
 
    context := StorageContext{Account: account}
 
349
    context := StorageContext{
 
350
        Account:       account,
 
351
        AzureEndpoint: "http://example.com/",
 
352
    }
335
353
    c.Check(
336
354
        context.GetFileURL(container, file),
337
355
        Equals,
338
 
        "https://"+url.QueryEscape(account)+".blob.core.windows.net/"+url.QueryEscape(container)+"/"+url.QueryEscape(file))
 
356
        "http://"+url.QueryEscape(account)+".blob.example.com/"+url.QueryEscape(container)+"/"+url.QueryEscape(file))
339
357
}
340
358
 
341
359
func (suite *TestStorageContext) TestGetSignedFileURL(c *C) {
343
361
    container := "container"
344
362
    file := "/a/file"
345
363
    key := base64.StdEncoding.EncodeToString([]byte("dummykey"))
346
 
    context := StorageContext{Account: account, Key: key}
 
364
    context := StorageContext{
 
365
        Account:       account,
 
366
        Key:           key,
 
367
        AzureEndpoint: "http://example.com/",
 
368
    }
347
369
    expires := time.Now()
348
370
 
349
371
    signedURL := context.GetAnonymousFileURL(container, file, expires)
408
430
    response := makeHttpResponse(http.StatusOK, responseBody)
409
431
    transport := &TestTransport{Response: response}
410
432
    context := makeStorageContext(transport)
 
433
    context.AzureEndpoint = "http://example.com/"
411
434
    request := &ListContainersRequest{Marker: ""}
412
435
    results, err := context.ListContainers(request)
413
436
    c.Assert(err, IsNil)
414
437
    c.Check(transport.Request.URL.String(), Equals, fmt.Sprintf(
415
 
        "https://%s.blob.core.windows.net/?comp=list", context.Account))
 
438
        "http://%s.blob.example.com/?comp=list", context.Account))
416
439
    c.Check(transport.Request.Header.Get("Authorization"), Not(Equals), "")
417
440
    c.Assert(results, NotNil)
418
441
    c.Assert(results.Containers[0].Name, Equals, "name-value")
666
689
    response := makeHttpResponse(http.StatusCreated, "")
667
690
    transport := &TestTransport{Response: response}
668
691
    context := makeStorageContext(transport)
 
692
    context.AzureEndpoint = "http://example.com/"
669
693
    containerName := MakeRandomString(10)
670
694
    err := context.CreateContainer(containerName)
671
695
    c.Assert(err, IsNil)
672
696
    c.Check(transport.Request.URL.String(), Equals, fmt.Sprintf(
673
 
        "https://%s.blob.core.windows.net/%s?restype=container",
 
697
        "http://%s.blob.example.com/%s?restype=container",
674
698
        context.Account, containerName))
675
699
    c.Check(transport.Request.Header.Get("Authorization"), Not(Equals), "")
676
700
}
720
744
    response := makeHttpResponse(http.StatusAccepted, "")
721
745
    transport := &TestTransport{Response: response}
722
746
    context := makeStorageContext(transport)
 
747
    context.AzureEndpoint = "http://example.com/"
723
748
    containerName := MakeRandomString(10)
724
749
    err := context.DeleteContainer(containerName)
725
750
    c.Assert(err, IsNil)
726
751
    c.Check(transport.Request.URL.String(), Equals, fmt.Sprintf(
727
 
        "https://%s.blob.core.windows.net/%s?restype=container",
 
752
        "http://%s.blob.example.com/%s?restype=container",
728
753
        context.Account, containerName))
729
754
    c.Check(transport.Request.Method, Equals, "DELETE")
730
755
    c.Check(transport.Request.Header.Get("Authorization"), Not(Equals), "")
786
811
 
787
812
    transport := &TestTransport{Response: response}
788
813
    context := makeStorageContext(transport)
 
814
    context.AzureEndpoint = "http://example.com/"
789
815
    containerName := MakeRandomString(10)
790
816
    props, err := context.GetContainerProperties(containerName)
791
817
    c.Assert(err, IsNil)
792
818
    c.Check(transport.Request.URL.String(), Equals, fmt.Sprintf(
793
 
        "https://%s.blob.core.windows.net/%s?restype=container",
 
819
        "http://%s.blob.example.com/%s?restype=container",
794
820
        context.Account, containerName))
795
821
    c.Check(transport.Request.Method, Equals, "GET")
796
822
    c.Check(transport.Request.Header.Get("Authorization"), Not(Equals), "")
1099
1125
    response := makeHttpResponse(http.StatusCreated, "")
1100
1126
    transport := &TestTransport{Response: response}
1101
1127
    context := makeStorageContext(transport)
 
1128
    context.AzureEndpoint = "http://example.com/"
1102
1129
    blocklist := &BlockList{}
1103
1130
    blocklist.Add(BlockListLatest, "b1")
1104
1131
    blocklist.Add(BlockListLatest, "b2")
1107
1134
 
1108
1135
    c.Check(transport.Request.Method, Equals, "PUT")
1109
1136
    c.Check(transport.Request.URL.String(), Equals, fmt.Sprintf(
1110
 
        "https://%s.blob.core.windows.net/container/blobname?comp=blocklist",
 
1137
        "http://%s.blob.example.com/container/blobname?comp=blocklist",
1111
1138
        context.Account))
1112
1139
    c.Check(transport.Request.Header.Get("Authorization"), Not(Equals), "")
1113
1140
 
1340
1367
    response := makeHttpResponse(http.StatusOK, "")
1341
1368
    transport := &TestTransport{Response: response}
1342
1369
    context := makeStorageContext(transport)
 
1370
    context.AzureEndpoint = "http://example.com/"
1343
1371
    err := context.SetContainerACL(&SetContainerACLRequest{
1344
1372
        Container: "mycontainer", Access: "container"})
1345
1373
 
1347
1375
    c.Check(transport.Request.Method, Equals, "PUT")
1348
1376
    c.Check(transport.Request.URL.String(), Matches,
1349
1377
        fmt.Sprintf(
1350
 
            "https://%s.blob.core.windows.net/mycontainer?.*", context.Account))
 
1378
            "http://%s.blob.example.com/mycontainer?.*", context.Account))
1351
1379
    c.Check(transport.Request.URL.Query(), DeepEquals, url.Values{
1352
1380
        "comp":    {"acl"},
1353
1381
        "restype": {"container"},