Skip to content

Commit

Permalink
fix: add an faq & upgrade dependencies (#88)
Browse files Browse the repository at this point in the history
* fix: add an faq for ssh-agent forwarding

* fix: update dependencies

* fix: updates tests to handle cobra version upgrade

* fix: updates tests to handle cobra version upgrade

* fix: update faq

* Update README.md

Co-authored-by: Tiffany K <tiffanykyi@gmail.com>

* Update README.md

Co-authored-by: Tiffany K <tiffanykyi@gmail.com>

---------

Co-authored-by: Tiffany K <tiffanykyi@gmail.com>
  • Loading branch information
jithine and tkyi authored Aug 24, 2023
1 parent 850c226 commit 0563f80
Show file tree
Hide file tree
Showing 8 changed files with 129 additions and 178 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,19 @@ $ go get github.com/screwdriver-cd/sd-local
$ go test -cover github.com/screwdriver-cd/sd-local/...
```
## FAQ
1. How to forward your local `ssh-agent` to `sd-local` in Mac?
If your `sd-local` build needs access to ssh keys for your ssh-agent, then you can do one of the following options:
1. If using [Colima](https://github.com/abiosoft/colima/):
```
sd-local build -i docker-build-api-pr --vol "$HOME/.ssh/known_hosts:/root/.ssh/known_hosts" -S $(colima ssh eval 'echo $SSH_AUTH_SOCK')
```
2. If using [Docker Desktop](https://www.docker.com/products/docker-desktop):
```
sd-local build -i docker-build-api-pr --vol "$HOME/.ssh/known_hosts:/root/.ssh/known_hosts"
```
## License
Code licensed under the BSD 3-Clause license. See [LICENSE](https://github.com/screwdriver-cd/sd-local/blob/master/LICENSE) file for terms.
Expand Down
15 changes: 9 additions & 6 deletions cmd/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,10 @@ func TestBuildCmd(t *testing.T) {
}

err := root.Execute()
want := "Error: can't pass the both options `meta` and `meta-file`, please specify only one of them\n" +
"Usage:\n build [job name] [flags]\n" +
wantErr := "can't pass the both options `meta` and `meta-file`, please specify only one of them"
want := "Usage:\n build [job name] [flags]\n" +
buildLocalFlags()
assert.Equal(t, wantErr, err.Error())
assert.Equal(t, want, buf.String())
assert.NotNil(t, err)
})
Expand All @@ -198,9 +199,10 @@ func TestBuildCmd(t *testing.T) {
buf := bytes.NewBuffer(nil)
root.SetOut(buf)
err := root.Execute()
want := "Error: accepts 1 arg(s), received 2\n" +
"Usage:\n build [job name] [flags]\n" +
wantErr := "accepts 1 arg(s), received 2"
want := "Usage:\n build [job name] [flags]\n" +
buildLocalFlags()
assert.Equal(t, wantErr, err.Error())
assert.Equal(t, want, buf.String())
assert.NotNil(t, err)
})
Expand All @@ -212,9 +214,10 @@ func TestBuildCmd(t *testing.T) {
buf := bytes.NewBuffer(nil)
root.SetOut(buf)
err := root.Execute()
want := "Error: accepts 1 arg(s), received 0\n" +
"Usage:\n build [job name] [flags]\n" +
wantErr := "accepts 1 arg(s), received 0"
want := "Usage:\n build [job name] [flags]\n" +
buildLocalFlags()
assert.Equal(t, wantErr, err.Error())
assert.Equal(t, want, buf.String())
assert.NotNil(t, err)
})
Expand Down
8 changes: 4 additions & 4 deletions cmd/config/use_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,18 @@ func TestConfigUseCmd(t *testing.T) {
{
name: "failure with too many args",
args: []string{"use", "test", "args"},
wantOut: "Error: accepts 1 arg(s), received 2\n",
wantOut: "accepts 1 arg(s), received 2",
checkErr: true,
},
{name: "failure without args",
args: []string{"use"},
wantOut: "Error: accepts 1 arg(s), received 0\n",
wantOut: "accepts 1 arg(s), received 0",
checkErr: true,
},
{
name: "failure because of passing unknown config",
args: []string{"use", "unknownconfig"},
wantOut: "Error: config `unknownconfig` does not exist\n",
wantOut: "config `unknownconfig` does not exist",
checkErr: true,
},
}
Expand All @@ -71,7 +71,7 @@ func TestConfigUseCmd(t *testing.T) {
err := cmd.Execute()
if tt.checkErr {
assert.NotNil(t, err)
assert.Equal(t, tt.wantOut, buf.String())
assert.Equal(t, tt.wantOut, err.Error())
} else {
assert.Nil(t, err)
assert.Equal(t, tt.wantOut, buf.String())
Expand Down
8 changes: 8 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ func newRootCmd() *cobra.Command {
Short: "Run build in local",
Long: `Run build instantly on your local machine with
a mostly the same environment as Screwdriver.cd's`,
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
err := cmd.Help()
if err != nil {
return err
}
return nil
},
}

rootCmd.PersistentFlags().BoolVarP(
Expand Down
14 changes: 8 additions & 6 deletions cmd/root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func TestRootCmd(t *testing.T) {
buf := bytes.NewBuffer(nil)
root.SetOut(buf)
err := root.Execute()
want := "Run build instantly on your local machine with\na mostly the same environment as Screwdriver.cd's\n\nUsage:\n sd-local [command]\n\nAvailable Commands:\n build Run screwdriver build.\n help Help about any command\n\nFlags:\n -h, --help help for sd-local\n -v, --verbose verbose output.\n\nUse \"sd-local [command] --help\" for more information about a command.\n"
want := "Run build instantly on your local machine with\na mostly the same environment as Screwdriver.cd's\n\nUsage:\n sd-local [flags]\n sd-local [command]\n\nAvailable Commands:\n build Run screwdriver build.\n completion Generate the autocompletion script for the specified shell\n help Help about any command\n\nFlags:\n -h, --help help for sd-local\n -v, --verbose verbose output.\n\nUse \"sd-local [command] --help\" for more information about a command.\n"
assert.Equal(t, want, buf.String())
assert.Nil(t, err)
})
Expand All @@ -119,7 +119,7 @@ func TestRootCmd(t *testing.T) {
buf := bytes.NewBuffer(nil)
root.SetOut(buf)
err := root.Execute()
want := "Run build instantly on your local machine with\na mostly the same environment as Screwdriver.cd's\n\nUsage:\n sd-local [command]\n\nAvailable Commands:\n help Help about any command\n update Update to the latest version\n\nFlags:\n -h, --help help for sd-local\n -v, --verbose verbose output.\n\nUse \"sd-local [command] --help\" for more information about a command.\n"
want := "Run build instantly on your local machine with\na mostly the same environment as Screwdriver.cd's\n\nUsage:\n sd-local [flags]\n sd-local [command]\n\nAvailable Commands:\n completion Generate the autocompletion script for the specified shell\n help Help about any command\n update Update to the latest version\n\nFlags:\n -h, --help help for sd-local\n -v, --verbose verbose output.\n\nUse \"sd-local [command] --help\" for more information about a command.\n"
assert.Equal(t, want, buf.String())
assert.Nil(t, err)
})
Expand All @@ -131,11 +131,12 @@ func TestRootCmd(t *testing.T) {
buf := bytes.NewBuffer(nil)
root.SetOut(buf)
err := root.Execute()
want := "Error: accepts 1 arg(s), received 0\n" +
"Usage:\n sd-local build [job name] [flags]\n" +
wantErr := "accepts 1 arg(s), received 0"
want := "Usage:\n sd-local build [job name] [flags]\n" +
buildLocalFlags() +
"Global Flags:\n -v, --verbose verbose output.\n\n"
assert.Equal(t, want, buf.String())
assert.Equal(t, wantErr, err.Error())
assert.NotNil(t, err)
})

Expand All @@ -146,8 +147,9 @@ func TestRootCmd(t *testing.T) {
buf := bytes.NewBuffer(nil)
root.SetOut(buf)
err := root.Execute()
want := "Error: unknown command \"hoge\" for \"sd-local\"\nRun 'sd-local --help' for usage.\n"
assert.Equal(t, want, buf.String())
wantErr := "unknown command \"hoge\" for \"sd-local\""

assert.Equal(t, wantErr, err.Error())
assert.NotNil(t, err)
})
}
11 changes: 8 additions & 3 deletions cmd/update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func TestSelfUpdate(t *testing.T) {
{
name: "Failed current version is dev",
current: "dev",
errOutput: "Error: This is a development version and cannot be updated\nUsage:\n update [flags]\n\nFlags:\n -h, --help help for update\n -y, --yes answer yes for all questions\n\n",
errOutput: "This is a development version and cannot be updated",
logOutput: []string{
"Current version: dev",
},
Expand Down Expand Up @@ -155,8 +155,13 @@ func TestSelfUpdate(t *testing.T) {
updateFlag = true
errBuf := bytes.NewBuffer(nil)
cmd.SetOut(errBuf)
cmd.Execute()
assert.Equal(t, tt.errOutput, errBuf.String())
cmdErr := cmd.Execute()

if tt.errOutput != "" {
assert.Equal(t, tt.errOutput, cmdErr.Error())

}

for _, want := range tt.logOutput {
assert.Contains(t, logBuf.String(), want)
}
Expand Down
38 changes: 20 additions & 18 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,39 @@ go 1.19

require (
github.com/blang/semver v3.5.1+incompatible
github.com/creack/pty v1.1.11
github.com/creack/pty v1.1.18
github.com/go-yaml/yaml v2.1.0+incompatible
github.com/google/uuid v1.2.0
github.com/joho/godotenv v1.3.0
github.com/google/uuid v1.3.1
github.com/joho/godotenv v1.5.1
github.com/mitchellh/go-homedir v1.1.0
github.com/mitchellh/mapstructure v1.4.1
github.com/rhysd/go-github-selfupdate v1.2.2
github.com/sirupsen/logrus v1.5.0
github.com/spf13/cobra v0.0.7
github.com/stretchr/testify v1.5.0
github.com/mitchellh/mapstructure v1.5.0
github.com/rhysd/go-github-selfupdate v1.2.3
github.com/sirupsen/logrus v1.9.3
github.com/spf13/cobra v1.7.0
github.com/stretchr/testify v1.7.0
gitlab.com/c0b/go-ordered-json v0.0.0-20201030195603-febf46534d5a
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9
golang.org/x/crypto v0.12.0
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/golang/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/go-github/v30 v30.1.0 // indirect
github.com/google/go-querystring v1.0.0 // indirect
github.com/google/go-querystring v1.1.0 // indirect
github.com/inconshreveable/go-update v0.0.0-20160112193335-8152e7eb6ccf // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/konsorten/go-windows-terminal-sequences v1.0.2 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/kr/pretty v0.2.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/tcnksm/go-gitconfig v0.1.2 // indirect
github.com/ulikunitz/xz v0.5.10 // indirect
golang.org/x/net v0.0.0-20201021035429-f5854403a974 // indirect
golang.org/x/oauth2 v0.0.0-20181106182150-f42d05182288 // indirect
golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4 // indirect
google.golang.org/appengine v1.3.0 // indirect
github.com/ulikunitz/xz v0.5.11 // indirect
golang.org/x/net v0.14.0 // indirect
golang.org/x/oauth2 v0.11.0 // indirect
golang.org/x/sys v0.11.0 // indirect
golang.org/x/term v0.11.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
gopkg.in/yaml.v2 v2.2.8 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading

0 comments on commit 0563f80

Please sign in to comment.