Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 package util | 1 package util |
| 2 | 2 |
| 3 import ( | 3 import ( |
| 4 "fmt" | 4 "fmt" |
| 5 "io/ioutil" | 5 "io/ioutil" |
| 6 "os" | 6 "os" |
| 7 "path/filepath" | 7 "path/filepath" |
| 8 "testing" | 8 "testing" |
| 9 | 9 |
| 10 "github.com/stretchr/testify/assert" | 10 "github.com/stretchr/testify/assert" |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 128 } | 128 } |
| 129 assert.False(t, result3) | 129 assert.False(t, result3) |
| 130 | 130 |
| 131 // Test with local timestamp missing. | 131 // Test with local timestamp missing. |
| 132 result4, err := gs.AreTimeStampsEqual(tmpDir+"dummy_name", "unit-tests/u til/") | 132 result4, err := gs.AreTimeStampsEqual(tmpDir+"dummy_name", "unit-tests/u til/") |
| 133 if err == nil { | 133 if err == nil { |
| 134 t.Error("Expected an error") | 134 t.Error("Expected an error") |
| 135 } | 135 } |
| 136 assert.False(t, result4) | 136 assert.False(t, result4) |
| 137 } | 137 } |
| 138 | |
| 139 // Will need a local valid google_storage_token.data file with read write access | |
| 140 // to run the below test. | |
| 141 func Auth_TestDownloadSwarmingArtifacts(t *testing.T) { | |
| 142 testPagesetsDirName := filepath.Join("unit-tests", "util", "page_sets") | |
| 143 | |
| 144 gs, err := NewGsUtil(nil) | |
| 145 assert.Nil(t, err) | |
| 146 | |
| 147 localDir := filepath.Join(os.TempDir(), "util_test") | |
|
dogben
2016/05/18 15:22:02
nit: Always prefer ioutil.TempDir over os.TempDir(
rmistry
2016/05/19 11:54:11
Done.
| |
| 148 defer util.RemoveAll(localDir) | |
| 149 pageSetToIndex, err := gs.DownloadSwarmingArtifacts(localDir, testPagese tsDirName, "10k", 1, 2) | |
| 150 if err != nil { | |
| 151 t.Errorf("Unexpected error: %s", err) | |
| 152 } | |
| 153 | |
| 154 // Examine contents of returned dictionary. | |
| 155 assert.Equal(t, 2, len(pageSetToIndex)) | |
| 156 assert.Equal(t, 1, pageSetToIndex[filepath.Join(localDir, "1.py")]) | |
| 157 assert.Equal(t, 2, pageSetToIndex[filepath.Join(localDir, "2.py")]) | |
| 158 // Examine contents of the local directory. | |
| 159 files, err := ioutil.ReadDir(localDir) | |
| 160 assert.Nil(t, err) | |
| 161 assert.Equal(t, 2, len(files)) | |
| 162 assert.Equal(t, "1.py", files[0].Name()) | |
| 163 assert.Equal(t, "2.py", files[1].Name()) | |
| 164 } | |
| OLD | NEW |