aboutsummaryrefslogtreecommitdiff
path: root/field_test.go
diff options
context:
space:
mode:
authorStefan Majewsky <majewsky@gmx.net>2018-02-19 21:30:33 +0100
committerStefan Majewsky <majewsky@gmx.net>2018-02-19 21:33:49 +0100
commit60d4779889baedc44972d4749daa073efca3b25c (patch)
treed47746971f659d6f7e3affe428f239b289954f5b /field_test.go
parent8f777460661bbbcbe42730979140f525b382110e (diff)
downloadgo-schwift-60d4779889baedc44972d4749daa073efca3b25c.tar.gz
reorganize code
* Gophercloud dependencies move into subpackage gopherschwift. * Tests move into subpackage tests (to avoid import cycles). + Rename "Client" to "Backend".
Diffstat (limited to 'field_test.go')
-rw-r--r--field_test.go165
1 files changed, 0 insertions, 165 deletions
diff --git a/field_test.go b/field_test.go
deleted file mode 100644
index 539ed74..0000000
--- a/field_test.go
+++ /dev/null
@@ -1,165 +0,0 @@
-/******************************************************************************
-*
-* Copyright 2018 Stefan Majewsky <majewsky@gmx.net>
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*
-******************************************************************************/
-
-package schwift
-
-import (
- "net/http"
- "strconv"
- "testing"
-)
-
-func TestFieldString(t *testing.T) {
- hdr := make(AccountHeaders)
- expectBool(t, hdr.TempURLKey().Exists(), false)
- expectString(t, hdr.TempURLKey().Get(), "")
- expectSuccess(t, hdr.Validate())
-
- hdr["X-Account-Meta-Temp-Url-Key"] = ""
- expectBool(t, hdr.TempURLKey().Exists(), false)
- expectString(t, hdr.TempURLKey().Get(), "")
- expectSuccess(t, hdr.Validate())
-
- hdr["X-Account-Meta-Temp-Url-Key"] = "foo"
- expectBool(t, hdr.TempURLKey().Exists(), true)
- expectString(t, hdr.TempURLKey().Get(), "foo")
- expectSuccess(t, hdr.Validate())
-
- hdr.TempURLKey().Set("bar")
- expectHeaders(t, hdr, map[string]string{
- "X-Account-Meta-Temp-Url-Key": "bar",
- })
- hdr.TempURLKey().Clear()
- expectHeaders(t, hdr, map[string]string{
- "X-Account-Meta-Temp-Url-Key": "",
- })
- hdr.TempURLKey().Del()
- expectHeaders(t, hdr, nil)
- hdr.TempURLKey().Clear()
- expectHeaders(t, hdr, map[string]string{
- "X-Account-Meta-Temp-Url-Key": "",
- })
-}
-
-////////////////////////////////////////////////////////////////////////////////
-
-func TestFieldTimestamp(t *testing.T) {
- testWithAccount(t, func(a *Account) {
- hdr, err := a.Headers()
- if !expectSuccess(t, err) {
- return
- }
-
- expectBool(t, hdr.CreatedAt().Exists(), true)
-
- actual := float64(hdr.CreatedAt().Get().UnixNano()) / 1e9
- expected, _ := strconv.ParseFloat(hdr["X-Timestamp"], 64)
- expectFloat64(t, actual, expected)
- })
-
- hdr := make(AccountHeaders)
- expectBool(t, hdr.CreatedAt().Exists(), false)
- expectBool(t, hdr.CreatedAt().Get().IsZero(), true)
- expectSuccess(t, hdr.Validate())
-
- hdr["X-Timestamp"] = "wtf"
- expectBool(t, hdr.CreatedAt().Exists(), true)
- expectBool(t, hdr.CreatedAt().Get().IsZero(), true)
- expectError(t, hdr.Validate(), `Bad header X-Timestamp: strconv.ParseFloat: parsing "wtf": invalid syntax`)
-}
-
-func TestFieldHTTPTimestamp(t *testing.T) {
- testWithContainer(t, func(c *Container) {
- obj := c.Object("test")
- err := obj.Upload(nil, nil, nil)
- if !expectSuccess(t, err) {
- return
- }
-
- hdr, err := obj.Headers()
- if !expectSuccess(t, err) {
- return
- }
- expectBool(t, hdr.UpdatedAt().Exists(), true)
-
- actual := hdr.UpdatedAt().Get()
- expected, _ := http.ParseTime(hdr.Get("Last-Modified"))
- expectInt64(t, actual.Unix(), expected.Unix())
- })
-
- hdr := make(ObjectHeaders)
- expectBool(t, hdr.UpdatedAt().Exists(), false)
- expectBool(t, hdr.UpdatedAt().Get().IsZero(), true)
- expectSuccess(t, hdr.Validate())
-
- hdr["Last-Modified"] = "wtf"
- expectBool(t, hdr.UpdatedAt().Exists(), true)
- expectBool(t, hdr.UpdatedAt().Get().IsZero(), true)
- expectError(t, hdr.Validate(), `Bad header Last-Modified: parsing time "wtf" as "Mon Jan _2 15:04:05 2006": cannot parse "wtf" as "Mon"`)
-}
-
-////////////////////////////////////////////////////////////////////////////////
-
-func TestFieldUint64(t *testing.T) {
- hdr := make(AccountHeaders)
- expectBool(t, hdr.BytesUsedQuota().Exists(), false)
- expectUint64(t, hdr.BytesUsedQuota().Get(), 0)
- expectSuccess(t, hdr.Validate())
-
- hdr["X-Account-Meta-Quota-Bytes"] = "23"
- expectBool(t, hdr.BytesUsedQuota().Exists(), true)
- expectUint64(t, hdr.BytesUsedQuota().Get(), 23)
- expectSuccess(t, hdr.Validate())
-
- hdr["X-Account-Meta-Quota-Bytes"] = "-23"
- expectBool(t, hdr.BytesUsedQuota().Exists(), true)
- expectUint64(t, hdr.BytesUsedQuota().Get(), 0)
- expectError(t, hdr.Validate(), `Bad header X-Account-Meta-Quota-Bytes: strconv.ParseUint: parsing "-23": invalid syntax`)
-
- hdr.BytesUsedQuota().Set(9001)
- expectHeaders(t, hdr, map[string]string{
- "X-Account-Meta-Quota-Bytes": "9001",
- })
- hdr.BytesUsedQuota().Clear()
- expectHeaders(t, hdr, map[string]string{
- "X-Account-Meta-Quota-Bytes": "",
- })
- hdr.BytesUsedQuota().Del()
- expectHeaders(t, hdr, nil)
- hdr.BytesUsedQuota().Clear()
- expectHeaders(t, hdr, map[string]string{
- "X-Account-Meta-Quota-Bytes": "",
- })
-}
-
-func TestFieldUint64Readonly(t *testing.T) {
- hdr := make(AccountHeaders)
- expectBool(t, hdr.BytesUsed().Exists(), false)
- expectUint64(t, hdr.BytesUsed().Get(), 0)
- expectSuccess(t, hdr.Validate())
-
- hdr["X-Account-Bytes-Used"] = "23"
- expectBool(t, hdr.BytesUsed().Exists(), true)
- expectUint64(t, hdr.BytesUsed().Get(), 23)
- expectSuccess(t, hdr.Validate())
-
- hdr["X-Account-Bytes-Used"] = "-23"
- expectBool(t, hdr.BytesUsed().Exists(), true)
- expectUint64(t, hdr.BytesUsed().Get(), 0)
- expectError(t, hdr.Validate(), `Bad header X-Account-Bytes-Used: strconv.ParseUint: parsing "-23": invalid syntax`)
-}