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

Side by Side Diff: ct/go/util/util_test.go

Issue 777413002: Add new tests to presubmit, fix errors (Closed) Base URL: https://skia.googlesource.com/buildbot@master
Patch Set: rebase Created 6 years 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 unified diff | Download patch
« no previous file with comments | « ct/go/util/gs.go ('k') | go/gitinfo/gitinfo.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "strconv" 8 "strconv"
9 "testing" 9 "testing"
10 ) 10 )
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 t.Error("Unexpected lack of error") 48 t.Error("Unexpected lack of error")
49 } 49 }
50 } 50 }
51 51
52 func TestCreateTimestampFile(t *testing.T) { 52 func TestCreateTimestampFile(t *testing.T) {
53 realDir := filepath.Join(os.TempDir(), "util_test") 53 realDir := filepath.Join(os.TempDir(), "util_test")
54 os.Mkdir(realDir, 0755) 54 os.Mkdir(realDir, 0755)
55 defer os.RemoveAll(realDir) 55 defer os.RemoveAll(realDir)
56 timestampFilePath := filepath.Join(realDir, TIMESTAMP_FILE_NAME) 56 timestampFilePath := filepath.Join(realDir, TIMESTAMP_FILE_NAME)
57 if err := CreateTimestampFile(realDir); err != nil { 57 if err := CreateTimestampFile(realDir); err != nil {
58 » » t.Error("Unexpected error: %s", err) 58 » » t.Errorf("Unexpected error: %s", err)
59 } 59 }
60 // Assert timestamp file exists. 60 // Assert timestamp file exists.
61 if _, err := os.Stat(timestampFilePath); err != nil { 61 if _, err := os.Stat(timestampFilePath); err != nil {
62 t.Errorf("Timestamp file %s was not created!", timestampFilePath ) 62 t.Errorf("Timestamp file %s was not created!", timestampFilePath )
63 } 63 }
64 // Assert timestamp file contains int64. 64 // Assert timestamp file contains int64.
65 fileContent, err := ioutil.ReadFile(timestampFilePath) 65 fileContent, err := ioutil.ReadFile(timestampFilePath)
66 if err != nil { 66 if err != nil {
67 t.Errorf("Unexpected error: %s", err) 67 t.Errorf("Unexpected error: %s", err)
68 } 68 }
69 if _, err := strconv.ParseInt(string(fileContent), 10, 64); err != nil { 69 if _, err := strconv.ParseInt(string(fileContent), 10, 64); err != nil {
70 » » t.Error("Unexpected value in %s: %s", timestampFilePath, err) 70 » » t.Errorf("Unexpected value in %s: %s", timestampFilePath, err)
71 } 71 }
72 72
73 // Assert error returned when specified dir does not exist. 73 // Assert error returned when specified dir does not exist.
74 nonexistantDir := filepath.Join(os.TempDir(), "util_test_nonexistant") 74 nonexistantDir := filepath.Join(os.TempDir(), "util_test_nonexistant")
75 os.RemoveAll(nonexistantDir) 75 os.RemoveAll(nonexistantDir)
76 if err := CreateTimestampFile(nonexistantDir); err != nil { 76 if err := CreateTimestampFile(nonexistantDir); err != nil {
77 // Expected error 77 // Expected error
78 } else { 78 } else {
79 t.Error("Unexpected lack of error") 79 t.Error("Unexpected lack of error")
80 } 80 }
81 } 81 }
OLDNEW
« no previous file with comments | « ct/go/util/gs.go ('k') | go/gitinfo/gitinfo.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698