github.com/Azure/draft-classic@v0.16.0/pkg/draft/pack/create_test.go (about) 1 package pack 2 3 import ( 4 "io/ioutil" 5 "os" 6 "path/filepath" 7 "testing" 8 ) 9 10 func TestCreateFrom(t *testing.T) { 11 tdir, err := ioutil.TempDir("", "pack-") 12 if err != nil { 13 t.Fatal(err) 14 } 15 defer os.RemoveAll(tdir) 16 17 odir, err := os.Getwd() 18 if err != nil { 19 t.Error("could not get current workdir") 20 } 21 22 if err := os.Chdir(tdir); err != nil { 23 t.Errorf("expected err to be nil, got %v", err) 24 } 25 26 if err := CreateFrom(tdir, filepath.Join(odir, "testdata", "pack-python"), ""); err != nil { 27 t.Errorf("expected err to be nil, got %v", err) 28 } 29 30 // verify that chart dir used cwd 31 if _, err := os.Stat(filepath.Join(tdir, "charts/", filepath.Base(tdir))); err != nil { 32 if os.IsNotExist(err) { 33 t.Error("expected chart directory to match workingdir") 34 } 35 } 36 37 // return to previous workdir 38 if err := os.Chdir(odir); err != nil { 39 t.Errorf("expected err to be nil, got %v", err) 40 } 41 42 // verify that canada.txt was copied over 43 if _, err := os.Stat(filepath.Join(tdir, "canada.txt")); err != nil { 44 if os.IsNotExist(err) { 45 t.Error("expected Canada to exist") 46 } 47 } 48 49 // verify that some-script.sh was copied over 50 if _, err := os.Stat(filepath.Join(tdir, "scripts", "some-script.sh")); err != nil { 51 if os.IsNotExist(err) { 52 t.Error("expected scripts/some-script.sh to exist") 53 } 54 } 55 56 if err := CreateFrom(tdir, filepath.Join("testdata", "pack-does-not-exist"), ""); err == nil { 57 t.Error("expected err to be non-nil with an invalid source pack") 58 } 59 }