github.com/swaros/contxt/module/runner@v0.0.0-20240305083542-3dbd4436ac40/shared_test.go (about) 1 package runner_test 2 3 import ( 4 "os" 5 "path/filepath" 6 "testing" 7 8 "github.com/swaros/contxt/module/runner" 9 ) 10 11 func TestGetPath(t *testing.T) { 12 shared := runner.NewSharedHelperWithPath("/home/user") 13 if shared.GetSharedPath("test") != filepath.Clean("/home/user/.contxt/shared/test") { 14 t.Error("unexpected path:", shared.GetSharedPath("test")) 15 } 16 } 17 18 func TestGetPathWithSub(t *testing.T) { 19 shared := runner.NewSharedHelperWithPath("/home/user") 20 if shared.GetBasePath() != "/home/user" { 21 t.Error("unexpected path", shared.GetBasePath()) 22 } 23 24 } 25 26 func TestCheckOrCreateUseConfig(t *testing.T) { 27 if path, err := os.MkdirTemp("", "testCase*"); err != nil { 28 t.Error(err) 29 } else { 30 defer os.RemoveAll(path) 31 shared := runner.NewSharedHelperWithPath(path) 32 if libPaqth, gitError := shared.CheckOrCreateUseConfig("swaros/ctx-git"); gitError != nil { 33 t.Error(gitError) 34 } else { 35 expectedPath := path + "/.contxt/shared/swaros/ctx-git/source" // like /tmp/testCase4133459873/.contxt/shared/swaros/ctx-git/source 36 if libPaqth != filepath.Clean(expectedPath) { 37 t.Error("unexpected path", libPaqth, "expected:", expectedPath) 38 } 39 } 40 } 41 } 42 43 func TestCheckOrCreateUseConfigNotExists(t *testing.T) { 44 t.Skip("not working on github without prompt for password") 45 if path, err := os.MkdirTemp("", "testCase*"); err != nil { 46 t.Error(err) 47 } else { 48 defer os.RemoveAll(path) 49 shared := runner.NewSharedHelperWithPath(path) 50 if libPaqth, gitError := shared.CheckOrCreateUseConfig("swaros/ctx-notThere"); gitError == nil { 51 if libPaqth != "" { 52 t.Error("should return an empty path") 53 } 54 t.Error("should return an error, because the repo does not exists") 55 } 56 } 57 }