From 94b3b6f9f0a2a5509441ad9edc3687eec38a3f8a Mon Sep 17 00:00:00 2001 From: John Bryan Sazon Date: Thu, 24 May 2018 11:10:05 +0800 Subject: [PATCH] Skip aws s3 upload test if AWS vars are undefined --- s3/upload_test.go | 53 ++++++++++++++++++++++++++--------------------- 1 file changed, 29 insertions(+), 24 deletions(-) diff --git a/s3/upload_test.go b/s3/upload_test.go index 79c5f36..7321825 100644 --- a/s3/upload_test.go +++ b/s3/upload_test.go @@ -34,13 +34,16 @@ import ( func TestUploadFile(t *testing.T) { if os.Getenv("GOTEST_AWS_BUCKET") == "" { - t.Fatal("GOTEST_AWS_BUCKET env variable is not set.") + fmt.Println("Skipping Test") + return } if os.Getenv("AWS_ACCESS_KEY") == "" { - t.Fatal("AWS_ACCESS_KEY env variable is not set.") + fmt.Println("Skipping Test") + return } if os.Getenv("AWS_SECRET_ACCESS_KEY") == "" { - t.Fatal("AWS_SECRET_ACCESS_KEY env variable is not set.") + fmt.Println("Skipping Test") + return } file, err := os.Create("samplefile.txt") if err != nil { @@ -70,26 +73,28 @@ func TestUploadAssets(t *testing.T) { {"upload ios assets", "ios_test", "../parser/testdata/sample.ipa"}, {"upload android assets", "android_test", "../parser/testdata/sample.apk"}, } - for _, tc := range tt { - t.Run(tc.name, func(t *testing.T) { - appInfo, err := ipapk.NewAppParser(tc.file) - if err != nil { - t.Fatal(err) - } - var app parser.MobileApp - app.UploadDate = time.Now().Format(time.RFC1123) - app.AppInfo = appInfo - app.File = tc.file - if err := app.GenerateAssets(); err != nil { - t.Fatal(err) - } - assets, err := UploadAssets(&app, os.Getenv("GOTEST_AWS_BUCKET"), tc.destDir) - if err != nil { - t.Fatal(err) - } - for _, v := range assets { - fmt.Println("s3 url:", v) - } - }) + if os.Getenv("GOTEST_AWS_BUCKET") != "" { + for _, tc := range tt { + t.Run(tc.name, func(t *testing.T) { + appInfo, err := ipapk.NewAppParser(tc.file) + if err != nil { + t.Fatal(err) + } + var app parser.MobileApp + app.UploadDate = time.Now().Format(time.RFC1123) + app.AppInfo = appInfo + app.File = tc.file + if err := app.GenerateAssets(); err != nil { + t.Fatal(err) + } + assets, err := UploadAssets(&app, os.Getenv("GOTEST_AWS_BUCKET"), tc.destDir) + if err != nil { + t.Fatal(err) + } + for _, v := range assets { + fmt.Println("s3 url:", v) + } + }) + } } }