Skip to content

Commit

Permalink
Now with tests
Browse files Browse the repository at this point in the history
  • Loading branch information
conortm committed Apr 29, 2015
1 parent 61c35c8 commit a66e5bd
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 3 deletions.
13 changes: 13 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
language: go
sudo: false
go:
- 1.4.2
- tip
before_install:
- go get github.com/axw/gocov/gocov
- go get github.com/mattn/goveralls
- if ! go get code.google.com/p/go.tools/cmd/cover; then go get golang.org/x/tools/cmd/cover; fi
script:
- $HOME/gopath/bin/goveralls -service=travis-ci
notifications:
email: false
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# ghkeys
# ghkeys [![Build Status](https://travis-ci.org/conortm/ghkeys.svg?branch=testing)](https://travis-ci.org/conortm/ghkeys)

A simple command line tool for syncing server users' authorized SSH keys with those of one or more GitHub accounts.
[ghkeys](https://github.com/conortm/ghkeys) is a simple command line tool for syncing server users' authorized SSH keys with those of one or more GitHub accounts.

Via configuration, specify individual GitHub users and/or entire teams, whose SSH keys should either be output directly or written to server users' `authorized_keys` files.

Expand Down
3 changes: 2 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"flag"
"fmt"
"log"
"os"
"strings"
)
Expand All @@ -28,7 +29,7 @@ func usage() {

func check(err error) {
if err != nil {
panic(err)
log.Fatal(err)
}
}

Expand Down
41 changes: 41 additions & 0 deletions main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package main

import (
"io/ioutil"
"os"
"testing"

"github.com/stretchr/testify/assert"
)

func TestConfig(t *testing.T) {
configFile, _ := ioutil.TempFile("", "ghkeys")
defer os.RemoveAll(configFile.Name())

configContent := `---
github_token: github_token_value
users:
- username: user_1
github_users:
- github_user_1
- github_user_2
- username: user_2
github_teams:
- MyOrg/Team 1
- MyOrg/Team 2
`
ioutil.WriteFile(configFile.Name(), []byte(configContent), os.ModePerm)

testConfig, err := newConfig(configFile.Name())
assert.Nil(t, err)
assert.Equal(t, "github_token_value", testConfig.GithubToken)
assert.Len(t, testConfig.Users, 2)
assert.Equal(t, "user_1", testConfig.Users[0].Username)
assert.Len(t, testConfig.Users[0].GithubUsers, 2)
assert.Equal(t, "github_user_1", testConfig.Users[0].GithubUsers[0])
assert.Nil(t, testConfig.Users[0].GithubTeams)
assert.Nil(t, testConfig.Users[1].GithubUsers)
assert.Len(t, testConfig.Users[1].GithubTeams, 2)
assert.Equal(t, "MyOrg/Team 1", testConfig.Users[1].GithubTeams[0])

}

0 comments on commit a66e5bd

Please sign in to comment.