Skip to content

Commit

Permalink
(test) move gitlab.init() to be run explicitly from main()
Browse files Browse the repository at this point in the history
This allows the tests to be run from, from the testdata directory and
removes unnecessary init() calls.

Set `StrictHostKeyChecking no` for `gitlab.com` for travis
  • Loading branch information
zaquestion committed Nov 15, 2017
1 parent 5b136f1 commit e39a3a2
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 10 deletions.
6 changes: 6 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ go_import_path: github.com/zaquestion/lab
sudo: false

script:
- echo -e "Host *\n\tStrictHostKeyChecking no\n" >> ~/.ssh/config
- echo -e "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDkTcgXnHuqR0gbwegnr9Zxz4hTkjjV/SpgJNPJz7mo/HKNbx0rqjj1P0yGR053R9GSFFim2ut4NK9DPPUkQdyucw+DoLkYRHJmlJ4BNa9NTCD0sl+eSXO2969kZojCYSOgbmkCJx8mdgTwhzdgE/jhBrsY0hPE6pRTlU+H68/zeNdJUAIJf0LLXOm3hpTKLA19VICltl/j9VvBJpgRHdBylXEyL8HokYpjkQQk1ZXj3m7Nlo8yDdg4VcljOJWC+Xh8kxRMfK5x/VRVsYKCQXN5QlzKeqf7USRDUS/7mFoPUBW+d4kwKtGxRsWuIL2yeqzifZUTOgsh9+ZWAWxWffQZ your_email@example.com" > ~/.ssh/id_rsa.pub
- echo -e "-----BEGIN RSA PRIVATE KEY-----\nMIIEpAIBAAKCAQEA5E3IF5x7qkdIG8HoJ6/Wcc+IU5I41f0qYCTTyc+5qPxyjW8d\nK6o49T9MhkdOd0fRkhRYptrreDSvQzz1JEHcrnMPg6C5GERyZpSeATWvTUwg9LJf\nnklztvevZGaIwmEjoG5pAicfJnYE8Ic3YBP44Qa7GNITxOqUU5VPh+vP83jXSVAC\nCX9Cy1zpt4aUyiwNfVSApbZf4/VbwSaYER3QcpVxMi/B6JGKY5EEJNWV495uzZaP\nMg3YOFXJYziVgvl4fJM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J7k5NrbgikbH8WP36UxKkYNr1IC\nHOFImPTYRSKjVsL+fIUNb1DSp3S6SsYbL7v3XJJQqtlQiDq8U8x1aQFXJ9C4EoLR\nzhKrKsECgYBtU/TSF/TATZY5XtrN9O+HX1Fbz70Ci8XgvioheVI2fezOcXPRzDcC\nOYPaCMNKA5E8gHdg4s0TN7uDvKTJ+KhSg2V7gZ39A28dHrJaRX7Nz4k6t2uEBjX9\na1JidpAIbJ+3w7+hj6L299tVZvS+Y/6Dz/uuEQGXfJg/l/5CCvQPsA==\n-----END RSA PRIVATE KEY-----" > ~/.ssh/id_rsa
- chmod 600 ~/.ssh/id_rsa*
- eval `ssh-agent -s`
- ssh-add ~/.ssh/id_rsa
- make test

deploy:
Expand Down
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,3 @@ internal-test:
mv testdata/test.git testdata/.git
go test ./...
mv testdata/.git testdata/test.git

1 change: 1 addition & 0 deletions cmd/mrCheckout_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ func Test_mrCheckoutCmdRun(t *testing.T) {
cmd.Dir = repo
b, err := cmd.CombinedOutput()
if err != nil {
t.Log(string(b))
t.Fatal(err)
}
t.Log(string(b))
Expand Down
6 changes: 0 additions & 6 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,3 @@ func Execute() {
os.Exit(1)
}
}

func init() {
// Unsure if this will mess up in other parts of the cli, so modified
// the function to return a string
// RootCmd.SetUsageFunc(labUsage)
}
3 changes: 2 additions & 1 deletion cmd/root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ func copyTestRepo(t *testing.T) string {
}

func TestRootCloneNoArg(t *testing.T) {
cmd := exec.Command("./lab_bin", "clone")
cmd := exec.Command("../lab_bin", "clone")
cmd.Dir = "./testdata"
b, _ := cmd.CombinedOutput()
require.Contains(t, string(b), "You must specify a repository to clone.")
}
2 changes: 1 addition & 1 deletion internal/gitlab/gitlab.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ var (

const defaultGitLabHost = "https://gitlab.com"

func init() {
func Init() {
reader := bufio.NewReader(os.Stdin)
var err error
host, err = gitconfig.Entire("gitlab.host")
Expand Down
6 changes: 5 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package main

import "github.com/zaquestion/lab/cmd"
import (
"github.com/zaquestion/lab/cmd"
"github.com/zaquestion/lab/internal/gitlab"
)

func main() {
gitlab.Init()
cmd.Execute()
}

0 comments on commit e39a3a2

Please sign in to comment.