Skip to content

Commit

Permalink
Merge pull request #951 from CircleCI-Public/generate-use-os-getwd
Browse files Browse the repository at this point in the history
use os.Getwd instead of "." for current directory
  • Loading branch information
loderunner authored Jun 13, 2023
2 parents 3717976 + b7555a9 commit 437b6c8
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 7 deletions.
11 changes: 9 additions & 2 deletions cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,15 @@ func migrateConfig(args []string) error {
}

func generateConfig(args []string) error {
path := "."
if len(args) == 1 {
var err error
var path string
if len(args) == 0 {
// use working directory as default
path, err = os.Getwd()
if err != nil {
return fmt.Errorf("couldn't get working directory")
}
} else {
path = args[0]
}

Expand Down
24 changes: 19 additions & 5 deletions cmd/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd_test

import (
"fmt"
"os"
"os/exec"
"path/filepath"

Expand Down Expand Up @@ -245,22 +246,35 @@ var _ = Describe("Config", func() {
})
})
})

Describe("generate", func() {
It("works without a path", func() {
command := exec.Command(pathCLI, "config", "generate")
command.Dir = "testdata/node"
session, err := gexec.Start(command, GinkgoWriter, GinkgoWriter)
session.Wait()
Expect(err).ShouldNot(HaveOccurred())

session.Wait()

Eventually(session.Err.Contents()).Should(BeEmpty())
Eventually(session.Out.Contents()).Should(MatchRegexp("#.*"))
Eventually(session.Out.Contents()).Should(MatchRegexp("npm run test"))
Eventually(session).Should(gexec.Exit(0))
})

It("works with a path", func() {
command := exec.Command(pathCLI, "config", "generate", "..")
wd, err := os.Getwd()
Expect(err).ShouldNot(HaveOccurred())

command := exec.Command(pathCLI, "config", "generate", "node")
command.Dir = filepath.Join(wd, "testdata")
session, err := gexec.Start(command, GinkgoWriter, GinkgoWriter)
session.Wait()
Expect(err).ShouldNot(HaveOccurred())

session.Wait()

Eventually(session.Err.Contents()).Should(BeEmpty())
Eventually(session.Out.Contents()).Should(MatchRegexp("#.*"))
Eventually(session.Out.Contents()).Should(MatchRegexp("npm run test"))
Eventually(session).Should(gexec.Exit(0))
})
})
})
10 changes: 10 additions & 0 deletions cmd/testdata/node/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "circleci-cli-node-test",
"version": "1.0.0",
"private": true,
"scripts": {
"build": "webpack",
"lint": "eslint .",
"test": "jest ."
}
}

0 comments on commit 437b6c8

Please sign in to comment.