Skip to content

Commit

Permalink
refactor tests
Browse files Browse the repository at this point in the history
  • Loading branch information
duaraghav8 committed Oct 22, 2019
1 parent 17f9d51 commit 02f0990
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 52 deletions.
22 changes: 18 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ These commands demonstrate the different ways in which you can specify `groups`

3. List Groups present in the organization
```bash
# Load credentials from an environment file
source ~/.okta/creds.env

# List names of all groups
Expand All @@ -48,10 +49,23 @@ okta-admin list-groups
okta-admin list-groups -groups azkaban,durmstrang -detailed
```

## Developing
After cloning this repository, run `make bootstrap` to download tools necessary for developing. This project uses [Go Modules](https://blog.golang.org/using-go-modules) for dependency management.
## Building
After cloning this repository, run `make bootstrap` to download tools necessary for developing. This project uses [Go Modules](https://blog.golang.org/using-go-modules) for dependency management. You must have Go v1.13 or higher installed on your system.

Use `make test` to run tests and `make fmt` to run `gofmt` over the codebase. Finally, run `make build` to build binaries for distribution.
Run the make tasks:
```
make fmt
make test
# Linux
make linux/amd64
# Darwin
make darwin/amd64
# Windows
make windows/amd64
```

## License
This code is licensed under the MPLv2 license.
This code is licensed under the MPLv2 license.
10 changes: 2 additions & 8 deletions command/assign_user_groups_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package command

import (
"strings"
"testing"
)

Expand All @@ -13,13 +12,8 @@ func createTestAssignUserGroupsCommand(globalOptsHelpText string) *AssignUserGro

func TestAssignUserGroupsCommand_Help(t *testing.T) {
t.Parallel()
const globalHelpMsg = `
Welcome to Hogwarts!
`
c := createTestAssignUserGroupsCommand(globalHelpMsg)
if !strings.Contains(c.Help(), globalHelpMsg) {
t.Errorf("Expected final help message to contain \"%s\"", globalHelpMsg)
}
c := createTestAssignUserGroupsCommand(testHelpMessage)
testCommandHelp(t, c.Help())
}

func TestAssignUserGroupsCommand_ParseArgs(t *testing.T) {
Expand Down
13 changes: 13 additions & 0 deletions command/command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,14 @@ import (
"flag"
"io/ioutil"
"log"
"strings"
"testing"
)

const testHelpMessage = `
Welcome to Hogwarts!
`

func createTestCommand(globalOptsHelpText, flagSetName string) *Command {
m := &Metadata{
GlobalOptionsHelpText: globalOptsHelpText,
Expand All @@ -20,3 +26,10 @@ func createTestCommand(globalOptsHelpText, flagSetName string) *Command {
Logger: log.New(ioutil.Discard, "", 0),
}
}

func testCommandHelp(t *testing.T, commandHelpMsg string) {
t.Helper()
if !strings.Contains(commandHelpMsg, testHelpMessage) {
t.Errorf("Expected final help message to contain \"%s\"", testHelpMessage)
}
}
10 changes: 2 additions & 8 deletions command/create_user_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package command

import (
"strings"
"testing"
)

Expand All @@ -13,13 +12,8 @@ func createTestCreateUserCommand(globalOptsHelpText string) *CreateUserCommand {

func TestCreateUserCommand_Help(t *testing.T) {
t.Parallel()
const globalHelpMsg = `
Welcome to Hogwarts!
`
c := createTestCreateUserCommand(globalHelpMsg)
if !strings.Contains(c.Help(), globalHelpMsg) {
t.Errorf("Expected final help message to contain \"%s\"", globalHelpMsg)
}
c := createTestCreateUserCommand(testHelpMessage)
testCommandHelp(t, c.Help())
}

func TestCreateUserCommand_ParseArgs(t *testing.T) {
Expand Down
10 changes: 2 additions & 8 deletions command/deactivate_user_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package command

import (
"strings"
"testing"
)

Expand All @@ -13,13 +12,8 @@ func createTestDeactivateUserCommand(globalOptsHelpText string) *DeactivateUserC

func TestDeactivateUserCommand_Help(t *testing.T) {
t.Parallel()
const globalHelpMsg = `
Welcome to Hogwarts!
`
c := createTestDeactivateUserCommand(globalHelpMsg)
if !strings.Contains(c.Help(), globalHelpMsg) {
t.Errorf("Expected final help message to contain \"%s\"", globalHelpMsg)
}
c := createTestDeactivateUserCommand(testHelpMessage)
testCommandHelp(t, c.Help())
}

func TestDeactivateUserCommand_ParseArgs(t *testing.T) {
Expand Down
10 changes: 2 additions & 8 deletions command/list_groups_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package command

import (
"strings"
"testing"
)

Expand All @@ -13,13 +12,8 @@ func createTestListGroupsCommand(globalOptsHelpText string) *ListGroupsCommand {

func TestListGroupsCommand_Help(t *testing.T) {
t.Parallel()
const globalHelpMsg = `
Welcome to Hogwarts!
`
c := createTestListGroupsCommand(globalHelpMsg)
if !strings.Contains(c.Help(), globalHelpMsg) {
t.Errorf("Expected final help message to contain \"%s\"", globalHelpMsg)
}
c := createTestListGroupsCommand(testHelpMessage)
testCommandHelp(t, c.Help())
}

func TestListGroupsCommand_ParseArgs(t *testing.T) {
Expand Down
10 changes: 2 additions & 8 deletions command/reset_user_multifactor_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package command

import (
"strings"
"testing"
)

Expand All @@ -13,13 +12,8 @@ func createTestResetUserMultifactorsCommand(globalOptsHelpText string) *ResetUse

func TestResetUserMultifactorsCommand_Help(t *testing.T) {
t.Parallel()
const globalHelpMsg = `
Welcome to Hogwarts!
`
c := createTestResetUserMultifactorsCommand(globalHelpMsg)
if !strings.Contains(c.Help(), globalHelpMsg) {
t.Errorf("Expected final help message to contain \"%s\"", globalHelpMsg)
}
c := createTestResetUserMultifactorsCommand(testHelpMessage)
testCommandHelp(t, c.Help())
}

func TestResetUserMultifactorsCommand_ParseArgs(t *testing.T) {
Expand Down
10 changes: 2 additions & 8 deletions command/reset_user_password_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package command

import (
"strings"
"testing"
)

Expand All @@ -13,13 +12,8 @@ func createTestResetUserPasswordCommand(globalOptsHelpText string) *ResetUserPas

func TestResetUserPasswordCommand_Help(t *testing.T) {
t.Parallel()
const globalHelpMsg = `
Welcome to Hogwarts!
`
c := createTestResetUserPasswordCommand(globalHelpMsg)
if !strings.Contains(c.Help(), globalHelpMsg) {
t.Errorf("Expected final help message to contain \"%s\"", globalHelpMsg)
}
c := createTestResetUserPasswordCommand(testHelpMessage)
testCommandHelp(t, c.Help())
}

func TestResetUserPasswordCommand_ParseArgs(t *testing.T) {
Expand Down

0 comments on commit 02f0990

Please sign in to comment.