@@ -24,19 +24,14 @@ var (
2424)
2525
2626func TestMain (m * testing.M ) {
27- var err error
2827 directoryFactory = newDirectory ("" )
29- directoryTestingID , err = directoryFactory .Create ()
30- if err != nil {
31- panic (err )
32- }
33-
28+ directoryTestingID = directoryFactory .Create ()
3429 dirPrv , _ = directoryFactory .New (directoryTestingID )
3530
3631 if ! skipS3Tests {
3732 s3Factory , _ = newS3 (context .Background (), os .Getenv ("WORKSPACE_PROVIDER_S3_BUCKET" ), os .Getenv ("WORKSPACE_PROVIDER_S3_BASE_ENDPOINT" ))
3833 // This won't ever error because it doesn't create anything.
39- s3TestingID , _ = s3Factory .Create ()
34+ s3TestingID = s3Factory .Create ()
4035
4136 s3Client , _ := s3Factory .New (s3TestingID )
4237 s3Prv = s3Client .(* s3Provider )
@@ -63,18 +58,14 @@ func TestMain(m *testing.M) {
6358}
6459
6560func TestCreateAndRm (t * testing.T ) {
66- id , err := directoryFactory .Create ()
67- if err != nil {
68- t .Errorf ("error creating workspace: %v" , err )
69- }
70-
61+ id := directoryFactory .Create ()
7162 if ! strings .HasPrefix (id , DirectoryProvider + "://" ) {
7263 t .Errorf ("unexpected id: %s" , id )
7364 }
7465
75- // The directory should exist
76- if _ , err := os .Stat (strings .TrimPrefix (id , DirectoryProvider + "://" )); err != nil {
77- t .Errorf ("unexpcted error when checking if directory exists: %v" , err )
66+ // The directory should not exist yet
67+ if _ , err := os .Stat (strings .TrimPrefix (id , DirectoryProvider + "://" )); ! errors . Is ( err , os . ErrNotExist ) {
68+ t .Errorf ("unexpected error when checking if directory exists: %v" , err )
7869 }
7970
8071 if err := directoryFactory .Rm (context .Background (), id ); err != nil {
@@ -88,13 +79,10 @@ func TestCreateAndRm(t *testing.T) {
8879}
8980
9081func TestWriteFileWorkspaceDNE (t * testing.T ) {
91- id , err := directoryFactory .Create ()
92- if err != nil {
93- t .Fatalf ("error creating workspace: %v" , err )
94- }
82+ id := directoryFactory .Create ()
9583
9684 // Delete the directory
97- if err = os .RemoveAll (strings .TrimPrefix (id , DirectoryProvider + "://" )); err != nil {
85+ if err : = os .RemoveAll (strings .TrimPrefix (id , DirectoryProvider + "://" )); err != nil {
9886 t .Errorf ("unexpected error when removing workspace: %v" , err )
9987 }
10088
@@ -113,12 +101,9 @@ func TestWriteFileWorkspaceDNE(t *testing.T) {
113101}
114102
115103func TestEnsureCannotCreateUnsafeWorkspace (t * testing.T ) {
116- id , err := directoryFactory .Create ()
117- if err != nil {
118- t .Fatalf ("error creating workspace: %v" , err )
119- }
104+ id := directoryFactory .Create ()
120105
121- _ , err = directoryFactory .New (id + "/.." )
106+ _ , err : = directoryFactory .New (id + "/.." )
122107 if err == nil {
123108 t .Fatalf ("expected error when creating directory outside of workspace" )
124109 }
0 commit comments