How to use SetWorkingDir method of util Package

Best Gauge code snippet using util.SetWorkingDir

stream.go

Source:stream.go Github

copy

Full Screen

...64 for {65 e := <-ch66 res := getResponse(e, pid)67 if stream.Send(res) != nil || res.Type == gm.ExecutionResponse_SuiteEnd {68 util.SetWorkingDir(config.ProjectRoot)69 return70 }71 }72 }()73}74func getResponse(e event.ExecutionEvent, pid int) *gm.ExecutionResponse {75 switch e.Topic {76 case event.SuiteStart:77 return &gm.ExecutionResponse{Type: gm.ExecutionResponse_SuiteStart, RunnerProcessId: int32(pid)}78 case event.SpecStart:79 return &gm.ExecutionResponse{80 Type: gm.ExecutionResponse_SpecStart,81 ID: e.ExecutionInfo.CurrentSpec.FileName,82 RunnerProcessId: int32(pid),83 }84 case event.ScenarioStart:85 return &gm.ExecutionResponse{86 Type: gm.ExecutionResponse_ScenarioStart,87 ID: fmt.Sprintf("%s:%d", e.ExecutionInfo.CurrentSpec.GetFileName(), e.Item.(*gauge.Scenario).Heading.LineNo),88 RunnerProcessId: int32(pid),89 Result: &gm.Result{90 TableRowNumber: int64(getDataTableRowNumber(e.Item.(*gauge.Scenario))),91 },92 }93 case event.ScenarioEnd:94 scn := e.Item.(*gauge.Scenario)95 return &gm.ExecutionResponse{96 Type: gm.ExecutionResponse_ScenarioEnd,97 ID: fmt.Sprintf("%s:%d", e.ExecutionInfo.CurrentSpec.GetFileName(), scn.Heading.LineNo),98 RunnerProcessId: int32(pid),99 Result: &gm.Result{100 Status: getStatus(e.Result.(*result.ScenarioResult)),101 ExecutionTime: e.Result.ExecTime(),102 Errors: getErrors(e.Result.(*result.ScenarioResult).ProtoScenario.GetScenarioItems()),103 BeforeHookFailure: getHookFailure(e.Result.GetPreHook()),104 AfterHookFailure: getHookFailure(e.Result.GetPostHook()),105 TableRowNumber: int64(getDataTableRowNumber(scn)),106 },107 }108 case event.SpecEnd:109 return &gm.ExecutionResponse{110 Type: gm.ExecutionResponse_SpecEnd,111 ID: e.ExecutionInfo.CurrentSpec.FileName,112 RunnerProcessId: int32(pid),113 Result: &gm.Result{114 BeforeHookFailure: getHookFailure(e.Result.GetPreHook()),115 AfterHookFailure: getHookFailure(e.Result.GetPostHook()),116 },117 }118 case event.SuiteEnd:119 return &gm.ExecutionResponse{120 Type: gm.ExecutionResponse_SuiteEnd,121 RunnerProcessId: int32(pid),122 Result: &gm.Result{123 BeforeHookFailure: getHookFailure(e.Result.GetPreHook()),124 AfterHookFailure: getHookFailure(e.Result.GetPostHook()),125 },126 }127 }128 return nil129}130func getDataTableRowNumber(scn *gauge.Scenario) int {131 index := scn.DataTableRowIndex132 if scn.DataTableRow.IsInitialized() {133 index++134 }135 return index136}137func getErrorExecutionResponse(errs ...error) *gm.ExecutionResponse {138 var e []*gm.Result_ExecutionError139 for _, err := range errs {140 e = append(e, &gm.Result_ExecutionError{ErrorMessage: err.Error()})141 }142 return &gm.ExecutionResponse{143 Type: gm.ExecutionResponse_ErrorResult,144 Result: &gm.Result{145 Errors: e,146 },147 }148}149func getHookFailure(hookFailure **gm.ProtoHookFailure) *gm.Result_ExecutionError {150 if hookFailure != nil && *hookFailure != nil {151 return &gm.Result_ExecutionError{152 Screenshot: (**hookFailure).ScreenShot,153 ErrorMessage: (**hookFailure).ErrorMessage,154 StackTrace: (**hookFailure).StackTrace,155 }156 }157 return nil158}159func getErrors(items []*gm.ProtoItem) []*gm.Result_ExecutionError {160 var errors []*gm.Result_ExecutionError161 for _, item := range items {162 executionResult := item.GetStep().GetStepExecutionResult()163 res := executionResult.GetExecutionResult()164 switch item.GetItemType() {165 case gm.ProtoItem_Step:166 if executionResult.GetSkipped() {167 errors = append(errors, &gm.Result_ExecutionError{ErrorMessage: executionResult.SkippedReason})168 } else if res.GetFailed() {169 errors = append(errors, &gm.Result_ExecutionError{170 StackTrace: res.StackTrace,171 ErrorMessage: res.ErrorMessage,172 Screenshot: res.ScreenShot,173 })174 }175 case gm.ProtoItem_Concept:176 errors = append(errors, getErrors(item.GetConcept().GetSteps())...)177 }178 }179 return errors180}181func getStatus(result *result.ScenarioResult) gm.Result_Status {182 if result.ProtoScenario.GetExecutionStatus() == gm.ExecutionStatus_FAILED {183 return gm.Result_FAILED184 }185 if result.ProtoScenario.GetExecutionStatus() == gm.ExecutionStatus_SKIPPED {186 return gm.Result_SKIPPED187 }188 return gm.Result_PASSED189}190func setFlags(req *gm.ExecutionRequest) []error {191 resetFlags()192 reporter.IsParallel = req.GetIsParallel()193 execution.InParallel = req.GetIsParallel()194 filter.ExecuteTags = req.GetTags()195 execution.TableRows = req.GetTableRows()196 streams := int(req.GetParallelStreams())197 if streams < 1 {198 streams = util.NumberOfCores()199 }200 execution.NumberOfExecutionStreams = streams201 reporter.NumberOfExecutionStreams = streams202 filter.NumberOfExecutionStreams = streams203 execution.Strategy = strings.ToLower(req.GetStrategy().String())204 filter.DoNotRandomize = req.GetSort()205 reporter.Verbose = true206 logger.Initialize(strings.ToLower(req.GetLogLevel().String()))207 if req.GetWorkingDir() != "" {208 util.SetWorkingDir(req.GetWorkingDir())209 }210 var errs []error211 if req.GetEnv() != "" {212 if err := env.LoadEnv(req.GetEnv()); err != nil {213 errs = append(errs, err)214 }215 }216 return errs217}218func resetFlags() {219 cores := util.NumberOfCores()220 reporter.IsParallel = false221 execution.InParallel = false222 reporter.Verbose = false223 filter.ExecuteTags = ""224 execution.TableRows = ""225 execution.NumberOfExecutionStreams = cores226 reporter.NumberOfExecutionStreams = cores227 filter.NumberOfExecutionStreams = cores228 execution.Strategy = "lazy"229 filter.DoNotRandomize = false230 util.SetWorkingDir(config.ProjectRoot)231}...

Full Screen

Full Screen

container.go

Source:container.go Github

copy

Full Screen

...173 }174 }175 return nil176}177// SetWorkingDir resets the current working directory.178func (c *Container) setWorkingDir(path string) {179 path = c.FS.Canonical(path)180 c.WorkingDir = path181 c.FS.SetWorkingDir(path)182}183// CurrentNotebook returns the current default notebook.184func (c *Container) CurrentNotebook() (*core.Notebook, error) {185 return c.currentNotebook, c.currentNotebookErr186}187func (c *Container) NewNoteFilter(opts fzf.NoteFilterOpts) *fzf.NoteFilter {188 opts.PreviewCmd = c.Config.Tool.FzfPreview189 opts.LineTemplate = c.Config.Tool.FzfLine190 opts.FzfOptions = c.Config.Tool.FzfOptions191 opts.NewBinding = c.Config.Tool.FzfBindNew192 return fzf.NewNoteFilter(opts, c.FS, c.Terminal, c.TemplateLoader)193}194func (c *Container) NewNoteEditor(notebook *core.Notebook) (*editor.Editor, error) {195 return editor.NewEditor(notebook.Config.Tool.Editor)...

Full Screen

Full Screen

generators.go

Source:generators.go Github

copy

Full Screen

1package generators2import (3 "fmt"4 "genie/generators/service"5 "genie/util"6 "github.com/AlecAivazis/survey/v2"7 "github.com/fatih/color"8 "os"9 "os/exec"10)11const UserCancelSurveyMessage = "Hey where did you go? I am so lonely now 😪"12const UserCancelProjectMessage = "👍 Okay...better luck next time!"13var terminal = util.NewTerminal()14type Generatorer interface {15 GetName() string16 AskQuestions() error17 Execute()18}19type Generatorser interface {20 Add(generator Generatorer) Generatorer21 Find(name string) Generatorer22 Run()23}24type Generators struct {25 Store map[string]Generatorer26 Order []Generatorer27}28func (g *Generators) Add(generator Generatorer) Generatorer {29 g.Order = append(g.Order, generator)30 g.Store[generator.GetName()] = generator31 return generator32}33func (g *Generators) Find(name string) Generatorer {34 return g.Store[name]35}36func (g *Generators) Run() {37 g.printHeader()38 var err error39 for _, gen := range g.Order {40 if err = gen.AskQuestions(); err != nil {41 fmt.Println(UserCancelSurveyMessage)42 break43 }44 }45 if err == nil {46 fmt.Println("")47 s := g.Find(service.NAME).(*service.Generator)48 var execute bool49 err := survey.AskOne(&survey.Confirm{50 Message: fmt.Sprintf("Your service will be created at: %s, continue?", s.Responses.ServicePath()),51 Default: true,52 }, &execute)53 if execute {54 for _, gen := range g.Order {55 gen.Execute()56 }57 g.setWorkingDir()58 g.changeFileMode()59 // g.execGoModule111()60 // g.execGoModVendor()61 g.execGoGenerate()62 g.execGoFmt()63 g.printInstructions()64 } else if err != nil {65 fmt.Println(UserCancelSurveyMessage)66 } else {67 fmt.Println(UserCancelProjectMessage)68 }69 }70}71func (*Generators) printHeader() {72 header := util.NewHeader()73 header.Print()74}75func (g *Generators) setWorkingDir() {76 s := g.Find(service.NAME).(*service.Generator)77 path := s.Responses.ServicePath()78 if err := os.Chdir(path); err != nil {79 panic(err)80 }81}82func (*Generators) changeFileMode() {83 cmd := exec.Command("chmod", "+x", "generate.sh")84 if err := cmd.Run(); err != nil {85 panic(err)86 }87}88func (*Generators) execGoModule111() {89 s := terminal.ShowBusy("export GOMODULE111=on...")90 cmd := exec.Command("export", "GOMODULE111=on")91 if err := cmd.Run(); err != nil {92 panic(err)93 }94 s.Stop()95}96func (*Generators) execGoModVendor() {97 s := terminal.ShowBusy("go mod vendor...")98 cmd := exec.Command("go", "mod", "vendor")99 if err := cmd.Run(); err != nil {100 panic(err)101 }102 s.Stop()103}104func (*Generators) execGoGenerate() {105 s := terminal.ShowBusy("go generate...")106 cmd := exec.Command("go", "generate")107 if err := cmd.Run(); err != nil {108 panic(err)109 }110 s.Stop()111}112func (*Generators) execGoFmt() {113 s := terminal.ShowBusy("go fmt")114 cmd := exec.Command("go", "fmt", "./...")115 if err := cmd.Run(); err != nil {116 panic(err)117 }118 s.Stop()119}120func (g *Generators) printInstructions() {121 s := g.Find(service.NAME).(*service.Generator)122 fmt.Println("\n🧞 Service generation complete")123 fmt.Println("------------------------------------------------")124 fmt.Println("In terminal #1, to run the server...")125 color.HiGreen(fmt.Sprintf("cd %s\n", s.Responses.ServicePath()))126 color.HiGreen("export GOMODULE111=on\n")127 color.HiGreen("go mod vendor\n")128 color.HiGreen("go run cmd/main.go\n\n")129 fmt.Println("In terminal #2, to run the client...")130 color.HiGreen("go run test/main.go\n\n")131}132var instance = &Generators{133 Store: map[string]Generatorer{},134}135func GetInstance() Generatorser {136 return instance137}...

Full Screen

Full Screen

SetWorkingDir

Using AI Code Generation

copy

Full Screen

1func main() {2 util.SetWorkingDir()3}4func main() {5 util.GetWorkingDir()6}7func main() {8 util.SetWorkingDir()9}10import (11var (12func GetWorkingDirOnce() string {13 once.Do(func() {14 workingDir = filepath.Dir(GetCurrentFile())15 })16}17func GetCurrentFile() string {18}19func GetWorkingDir() string {20}21func SetWorkingDir() {22 workingDir = filepath.Dir(GetCurrentFile())23}24func main() {25 util.SetWorkingDir()26}27func main() {28 util.GetWorkingDir()29}30func main() {31 util.SetWorkingDir()32}

Full Screen

Full Screen

SetWorkingDir

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 util.SetWorkingDir()4 fmt.Println("Working directory is set")5}6import (7func SetWorkingDir() {8 dir, err := filepath.Abs(filepath.Dir(os.Args[0]))9 if err != nil {10 fmt.Println(err)11 }12 os.Chdir(dir)13}14main.main()15Your name to display (optional):16Your name to display (optional):17Your name to display (optional):18Your name to display (optional):

Full Screen

Full Screen

SetWorkingDir

Using AI Code Generation

copy

Full Screen

1func main() {2 util.SetWorkingDir()3}4import (5func SetWorkingDir() {6 dir, err := filepath.Abs(filepath.Dir(os.Args[0]))7 if err != nil {8 fmt.Println(err)9 }10 err = os.Chdir(dir)11 if err != nil {12 fmt.Println(err)13 }14}

Full Screen

Full Screen

SetWorkingDir

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println(util.GetWorkingDir())4}5import (6func GetWorkingDir() string {7 dir, err := filepath.Abs(filepath.Dir(os.Args[0]))8 if err != nil {9 log.Fatal(err)10 }11}

Full Screen

Full Screen

SetWorkingDir

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 util.SetWorkingDir()4 fmt.Println("Working directory is set")5}6import (7func SetWorkingDir() {8 err := os.Chdir("C:\\Users\\Krishna\\Desktop\\Go")9 if err != nil {10 fmt.Println(err)11 }12}13import (14func main() {15 path, err := os.Getwd()16 if err != nil {17 fmt.Println(err)18 }19 fmt.Println("Current working directory is", path)20}21import (22func main() {23 user, err := user.Current()24 if err != nil {25 fmt.Println(err)26 }27 fmt.Println("Current user is", user.Username)28}29import (30func main() {31 user, err := user.Current()32 if err != nil {33 fmt.Println(err)34 }35 fmt.Println("Home directory is", user.HomeDir)36}37import (38func main() {39 user, err := user.Current()40 if err != nil {41 fmt.Println(err)42 }43 fmt.Println("Group ID is", user.Gid)44}

Full Screen

Full Screen

SetWorkingDir

Using AI Code Generation

copy

Full Screen

1util.SetWorkingDir("C:/Users/ABC/Desktop/Go/1.go")2import (3func SetWorkingDir(path string) {4 ex, err := os.Executable()5 if err != nil {6 panic(err)7 }8 exPath := filepath.Dir(ex)9 os.Chdir(exPath)10}

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Gauge automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful