Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(403)

Unified Diff: gslib/tests/test_stat.py

Issue 698893003: Update checked in version of gsutil to version 4.6 (Closed) Base URL: http://dart.googlecode.com/svn/third_party/gsutil/
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « gslib/tests/test_signurl.py ('k') | gslib/tests/test_thread_pool.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: gslib/tests/test_stat.py
===================================================================
--- gslib/tests/test_stat.py (revision 33376)
+++ gslib/tests/test_stat.py (working copy)
@@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
-#
# Copyright 2013 Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -13,34 +12,47 @@
# 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.
+"""Tests for stat command."""
-import posixpath
-import re
-import subprocess
-import sys
+from __future__ import absolute_import
-import gslib
+from gslib.cs_api_map import ApiSelector
import gslib.tests.testcase as testcase
from gslib.tests.util import ObjectToURI as suri
-from gslib.wildcard_iterator import ContainsWildcard
+
class TestStat(testcase.GsUtilIntegrationTestCase):
"""Integration tests for stat command."""
def test_stat_output(self):
+ """Tests stat output of a single object."""
object_uri = self.CreateObject(contents='z')
stdout = self.RunGsUtil(['stat', suri(object_uri)], return_stdout=True)
self.assertIn(object_uri.uri, stdout)
self.assertIn('Creation time:', stdout)
- self.assertIn('Cache-Control:', stdout)
- self.assertIn('Content-Encoding:', stdout)
+
+ # Cache-Control and Content-Encoding can be different depending on
+ # whether the JSON or XML API is used. For JSON, only max-age and
+ # no-cache are respected. Although the object field will be populated
+ # with whatever we set, the actual header returned from the JSON API
+ # may differ from it (and differ from the XML response for the same object).
+ #
+ # Likewise, with contentEncoding, the field value and the header value
+ # are not guaranteed to match or be the same across APIs.
+ #
+ # JSON will not return a Cache-control or content-encoding with the
+ # current test object creation, so check these only for the XML API.
+ if self.default_provider == 'gs':
+ if self.test_api == ApiSelector.XML:
+ self.assertIn('Cache-Control:', stdout)
+ self.assertIn('Content-Encoding:', stdout)
+ self.assertIn('Generation:', stdout)
+ self.assertIn('Metageneration:', stdout)
+ self.assertIn('Hash (crc32c):', stdout)
+ self.assertIn('Hash (md5):', stdout)
self.assertIn('Content-Length:', stdout)
self.assertIn('Content-Type:', stdout)
- self.assertIn('Hash (crc32c):', stdout)
- self.assertIn('Hash (md5):', stdout)
self.assertIn('ETag:', stdout)
- self.assertIn('Generation:', stdout)
- self.assertIn('Metageneration:', stdout)
def test_minus_q_stat(self):
object_uri = self.CreateObject(contents='z')
@@ -55,3 +67,43 @@
self.RunGsUtil(['-q', 'stat', 'gs://'], expected_status=1)
self.RunGsUtil(['-q', 'stat', 'gs://bucket/object'], expected_status=1)
self.RunGsUtil(['-q', 'stat', 'file://tmp/abc'], expected_status=1)
+
+ def test_stat_one_missing(self):
+ bucket_uri = self.CreateBucket()
+ self.CreateObject(bucket_uri=bucket_uri, object_name='notmissing',
+ contents='z')
+ stdout = self.RunGsUtil(['stat', suri(bucket_uri, 'missing'),
+ suri(bucket_uri, 'notmissing')], expected_status=1,
+ return_stdout=True)
+ self.assertIn('No URLs matched %s' % suri(bucket_uri, 'missing'), stdout)
+ self.assertIn('%s:' % suri(bucket_uri, 'notmissing'), stdout)
+
+ def test_stat_one_missing_wildcard(self):
+ bucket_uri = self.CreateBucket()
+ self.CreateObject(bucket_uri=bucket_uri, object_name='notmissing',
+ contents='z')
+ stdout = self.RunGsUtil(['stat', suri(bucket_uri, 'missin*'),
+ suri(bucket_uri, 'notmissin*')], expected_status=1,
+ return_stdout=True)
+ self.assertIn('No URLs matched %s' % suri(bucket_uri, 'missin*'), stdout)
+ self.assertIn('%s:' % suri(bucket_uri, 'notmissing'), stdout)
+
+ def test_stat_bucket_wildcard(self):
+ bucket_uri = self.CreateBucket()
+ self.CreateObject(bucket_uri=bucket_uri, object_name='foo', contents='z')
+ stat_string = suri(bucket_uri)[:-1] + '?/foo'
+ self.RunGsUtil(['stat', stat_string])
+ stat_string2 = suri(bucket_uri)[:-1] + '*/foo'
+ self.RunGsUtil(['stat', stat_string2])
+
+ def test_stat_object_wildcard(self):
+ bucket_uri = self.CreateBucket()
+ object1_uri = self.CreateObject(bucket_uri=bucket_uri, object_name='foo1',
+ contents='z')
+ object2_uri = self.CreateObject(bucket_uri=bucket_uri, object_name='foo2',
+ contents='z')
+ stat_string = suri(object1_uri)[:-2] + '*'
+ stdout = self.RunGsUtil(['stat', stat_string], return_stdout=True)
+ self.assertIn(suri(object1_uri), stdout)
+ self.assertIn(suri(object2_uri), stdout)
+
« no previous file with comments | « gslib/tests/test_signurl.py ('k') | gslib/tests/test_thread_pool.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698