gopkg.in/openshift/source-to-image.v1@v1.2.0/pkg/scm/downloaders/file/download_test.go (about) 1 package file 2 3 import ( 4 "path/filepath" 5 "strings" 6 "testing" 7 8 "github.com/openshift/source-to-image/pkg/api" 9 "github.com/openshift/source-to-image/pkg/scm/git" 10 testfs "github.com/openshift/source-to-image/pkg/test/fs" 11 ) 12 13 func TestDownload(t *testing.T) { 14 fs := &testfs.FakeFileSystem{} 15 f := &File{fs} 16 17 config := &api.Config{ 18 Source: git.MustParse("/foo"), 19 } 20 info, err := f.Download(config) 21 if err != nil { 22 t.Errorf("Unexpected error %v", err) 23 } 24 if fs.CopySource != "/foo" { 25 t.Errorf("Unexpected fs.CopySource %s", fs.CopySource) 26 } 27 if info.Location != config.Source.URL.Path || info.ContextDir != config.ContextDir { 28 t.Errorf("Unexpected info") 29 } 30 } 31 32 func TestDownloadRecursive(t *testing.T) { 33 fs := &testfs.FakeFileSystem{} 34 f := &File{fs} 35 36 config := &api.Config{ 37 Source: git.MustParse("some/a/../path"), 38 WorkingDir: "b/../some/path/target", 39 } 40 _, err := f.Download(config) 41 if err == nil { 42 t.Errorf("Expected recursive copy error, got nil") 43 } 44 if !strings.Contains(err.Error(), "recursive copy requested") { 45 t.Errorf("Expected error text: recursive copy requested, got: %v", err) 46 } 47 } 48 49 func TestDownloadWithContext(t *testing.T) { 50 fs := &testfs.FakeFileSystem{} 51 f := &File{fs} 52 53 config := &api.Config{ 54 Source: git.MustParse("/foo"), 55 ContextDir: "bar", 56 } 57 info, err := f.Download(config) 58 if err != nil { 59 t.Errorf("Unexpected error %v", err) 60 } 61 if filepath.ToSlash(fs.CopySource) != "/foo/bar" { 62 t.Errorf("Unexpected fs.CopySource %s", fs.CopySource) 63 } 64 if info.Location != config.Source.URL.Path || info.ContextDir != config.ContextDir { 65 t.Errorf("Unexpected info") 66 } 67 }