github.com/kyma-project/kyma/components/asset-store-controller-manager@v0.0.0-20191203152857-3792b5df17c5/internal/loader/single_loader_test.go (about) 1 package loader 2 3 import ( 4 "io/ioutil" 5 "os" 6 "testing" 7 8 "github.com/kyma-project/kyma/components/asset-store-controller-manager/pkg/apis/assetstore/v1alpha2" 9 "github.com/onsi/gomega" 10 ) 11 12 func TestLoader_Load_Single(t *testing.T) { 13 t.Run("Success", func(t *testing.T) { 14 // Given 15 g := gomega.NewGomegaWithT(t) 16 loader := &loader{ 17 temporaryDir: "/tmp", 18 osRemoveAllFunc: os.RemoveAll, 19 osCreateFunc: os.Create, 20 httpGetFunc: get, 21 ioutilTempDir: ioutil.TempDir, 22 } 23 24 // When 25 _, files, err := loader.Load("test", "asset", v1alpha2.AssetSingle, "") 26 27 // Then 28 g.Expect(err).NotTo(gomega.HaveOccurred()) 29 g.Expect(files).To(gomega.HaveLen(1)) 30 }) 31 32 t.Run("SuccessNoFileInPath", func(t *testing.T) { 33 // Given 34 g := gomega.NewGomegaWithT(t) 35 loader := &loader{ 36 temporaryDir: "/tmp", 37 osRemoveAllFunc: os.RemoveAll, 38 osCreateFunc: os.Create, 39 httpGetFunc: get, 40 ioutilTempDir: ioutil.TempDir, 41 } 42 43 // When 44 _, files, err := loader.Load("https://ala.ma/", "asset", v1alpha2.AssetSingle, "") 45 46 // Then 47 g.Expect(err).NotTo(gomega.HaveOccurred()) 48 g.Expect(files).To(gomega.HaveLen(1)) 49 }) 50 51 t.Run("FailTemp", func(t *testing.T) { 52 // Given 53 g := gomega.NewGomegaWithT(t) 54 loader := &loader{ 55 temporaryDir: "/tmp", 56 osRemoveAllFunc: os.RemoveAll, 57 osCreateFunc: os.Create, 58 httpGetFunc: get, 59 ioutilTempDir: tempDirError, 60 } 61 62 // When 63 _, _, err := loader.Load("test", "asset", v1alpha2.AssetSingle, "") 64 65 // Then 66 g.Expect(err).To(gomega.HaveOccurred()) 67 }) 68 69 t.Run("FailCreate", func(t *testing.T) { 70 // Given 71 g := gomega.NewGomegaWithT(t) 72 loader := &loader{ 73 temporaryDir: "/tmp", 74 osRemoveAllFunc: os.RemoveAll, 75 osCreateFunc: createError, 76 httpGetFunc: get, 77 ioutilTempDir: ioutil.TempDir, 78 } 79 80 // When 81 _, _, err := loader.Load("test", "asset", v1alpha2.AssetSingle, "") 82 83 // Then 84 g.Expect(err).To(gomega.HaveOccurred()) 85 }) 86 87 t.Run("FailDownload", func(t *testing.T) { 88 // Given 89 g := gomega.NewGomegaWithT(t) 90 loader := &loader{ 91 temporaryDir: "/tmp", 92 osRemoveAllFunc: os.RemoveAll, 93 osCreateFunc: os.Create, 94 httpGetFunc: get, 95 ioutilTempDir: ioutil.TempDir, 96 } 97 98 // When 99 _, _, err := loader.Load("error3", "asset", v1alpha2.AssetSingle, "") 100 101 // Then 102 g.Expect(err).To(gomega.HaveOccurred()) 103 }) 104 }