Skip to content

Commit

Permalink
increased test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
kris-anderson committed Feb 14, 2021
1 parent aa96f89 commit e8f2e6c
Show file tree
Hide file tree
Showing 7 changed files with 198 additions and 135 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,12 @@ jobs:
- name: Move autocompletions for fish
run: mv completions/fish/awsprofile.fish build/completions/fish/awsprofile.fish

- name: Move awsprofile.sh to build/awsprofile
- name: Move bin/awsprofile to build/awsprofile
run: mv bin/awsprofile build/awsprofile

- name: Remove ShellSpec lines from build/awsprofile
run: sed -i -- '/# used by ShellSpec for tests/,+4d' build/awsprofile

- name: Get the version
run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV

Expand Down
5 changes: 5 additions & 0 deletions bin/awsprofile
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,11 @@ empty_input() {
test "$1" = ""
}

# used by ShellSpec for tests
# do not modify or delete these comments
# these lines are deleted during the build process
${__SOURCED__:+return}

######################
## command: current ##
######################
Expand Down
187 changes: 73 additions & 114 deletions spec/awsprofile_doctor_spec.sh
Original file line number Diff line number Diff line change
@@ -1,124 +1,83 @@
Describe 'awsprofile --doctor'
Describe 'awsprofile doctor'

#
# basic checks
#
#
# basic checks
#

Describe 'command responds'
Describe 'command responds'

It 'checks for the correct ouput'
When call ./bin/awsprofile doctor
The status should be success
The output should include "Checking for required command line utilities"
End

End

#
# package checks
#

# basename

Describe 'checks that utility basename is installed'

It 'prints basename ok'
When call ./bin/awsprofile doctor
The status should be success
The output should include "[ok] basename"
End
It 'checks for the correct ouput'
When call ./bin/awsprofile doctor
The status should be success
The output should include "Checking for required command line utilities"
End

command() { return 1; }

It 'prints basename failed'
When run source ./bin/awsprofile doctor
The status should be success
The output should include "[failed] basename"
End

End

# find
#
# package checks
#

Describe 'checks required utilities are installed'

It 'prints ok basename'
When call ./bin/awsprofile doctor
The status should be success
The output should include "[ok] basename"
End

It 'prints ok find'
When call ./bin/awsprofile doctor
The status should be success
The output should include "[ok] find"
End

It 'prints ok readlink'
When call ./bin/awsprofile doctor
The status should be success
The output should include "[ok] readlink"
End

It 'prints ok realpath'
When call ./bin/awsprofile doctor
The status should be success
The output should include "[ok] realpath"
End

It 'prints credentials should not exist ok'
When call ./bin/awsprofile doctor
The status should be success
The output should include "[ok] credentials should not exist"
End

It 'prints credentials should not exist ok'
When call ./bin/awsprofile doctor
The status should be success
The output should include "[ok] credentials should not exist"
End

# Intercept begin
# __begin__() {
# test() {
# if [ "$1" = "-f" ] && [ "$2" = "$HOME/.aws/credentials" ]; then
# return 0
# else
# return 1
# fi
# }
# }

# It 'prints credentials should not exist'
# When run source ./bin/awsprofile --doctor
# The output should include "$(printf "credentials should not exist [failed]")"
# End

It 'prints config should not exist ok'
When call ./bin/awsprofile doctor
The status should be success
The output should include "[ok] config should not exist"
End

Describe 'checks that utility find is installed'

It 'prints find ok'
When call ./bin/awsprofile doctor
The status should be success
The output should include "[ok] find"
End

# command() { return 1; }
Mock test_if_utility_installed
if [ "$1" = "find" ]; then
exit 1
else
echo "command: command not found" >&2
exit 127
fi
End

# It 'prints find failed'
# When run source ./bin/awsprofile doctor
# The status should be success
# The output should include "$(printf "find [failed]")"
# End

# It 'prints correct output'
# When call test_if_utility_installed "dsds"
# The status should be failure
# End

End

Describe 'others tests'

It 'prints readlink ok'
When call ./bin/awsprofile doctor
The status should be success
The output should include "[ok] readlink"
End

It 'prints realpath ok'
When call ./bin/awsprofile doctor
The status should be success
The output should include "[ok] realpath"
End

It 'prints credentials should not exist ok'
When call ./bin/awsprofile doctor
The status should be success
The output should include "[ok] credentials should not exist"
End

It 'prints credentials should not exist ok'
When call ./bin/awsprofile doctor
The status should be success
The output should include "[ok] credentials should not exist"
End

# Intercept begin
# __begin__() {
# test() {
# if [ "$1" = "-f" ] && [ "$2" = "$HOME/.aws/credentials" ]; then
# return 0
# else
# return 1
# fi
# }
# }

# It 'prints credentials should not exist'
# When run source ./bin/awsprofile --doctor
# The output should include "$(printf "credentials should not exist [failed]")"
# End

It 'prints config should not exist ok'
When call ./bin/awsprofile doctor
The status should be success
The output should include "[ok] config should not exist"
End

End

End
14 changes: 7 additions & 7 deletions spec/awsprofile_help_spec.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
Describe 'awsprofile --help'
Describe 'awsprofile help'

Describe 'help command'
It 'prints help information'
When call ./bin/awsprofile help
The status should be success
The output should include "awsprofile <command> [options]"
Describe 'help command'
It 'prints help information'
When call ./bin/awsprofile help
The status should be success
The output should include "awsprofile <command> [options]"
End
End
End

End
11 changes: 11 additions & 0 deletions spec/awsprofile_initial_setup_spec.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Describe 'awsprofile initial-setup'

Describe 'initial-setup command'
It 'prints initial setup instructions'
When call ./bin/awsprofile initial-setup
The status should be success
The output should include "Take the content from these files:"
End
End

End
97 changes: 91 additions & 6 deletions spec/awsprofile_spec.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,96 @@
Describe 'awsprofile'

Describe 'no command provided'
It 'prints an warning that no command was provided'
When call ./bin/awsprofile
The status should be failure
The output should include "** Warning **"
Include bin/awsprofile

Describe 'no command provided'
It 'prints an warning that no command was provided'
When call ./bin/awsprofile
The status should be failure
The output should include "** Warning **"
End
End

Describe 'arrow_icon()'
It 'outputs arrow icon and provided text'
When call arrow_icon test
The line 1 should eq "${BOLD}${YELLOW}${RESET}test"
The lines of output should eq 1
End
End

Describe 'print_warning()'
It 'outputs warning text'
When call print_warning test
The line 1 should eq "${BOLD}${YELLOW}** Warning **${RESET}"
The line 2 should eq "test"
The lines of output should eq 2
End
End

Describe 'print_error()'
It 'outputs error text'
When call print_error test
The line 1 should eq "${BOLD}${RED}** Error **${RESET}"
The line 2 should eq "test"
The lines of output should eq 2
End
End

Describe 'ok()'
It 'outputs [ok]'
When call ok
The line 1 should eq "${BOLD}${GREEN}[ok]${RESET}"
The lines of output should eq 1
End
End

Describe 'failed()'
It 'outputs [failed]'
When call failed
The line 1 should eq "${BOLD}${RED}[failed]${RESET}"
The lines of output should eq 1
End
End

Describe 'error()'
It 'outputs [error]'
When call error
The line 1 should eq "${BOLD}${RED}[error]${RESET}"
The lines of output should eq 1
End
End

# Describe 'get_profiles()'
# It 'outputs profile information'
# When call get_profiles
# The status should be success
# End
# End

Describe 'no_command_provided()'
It 'it tests as successful because no command was provided'
When call no_command_provided
The status should be success
End

It 'tests as failed because a command was provided'
When call no_command_provided test
The status should be failure
End
End

Describe 'empty_input()'

It 'it tests as successful because no input was provided'
When call empty_input
The status should be success
End

It 'tests as failed because a input was provided'
When call empty_input test
The status should be failure
End

End
End

End
14 changes: 7 additions & 7 deletions spec/awsprofile_version_spec.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
Describe 'awsprofile --version'
Describe 'awsprofile version'

Describe 'version command'
It 'prints version information'
When call ./bin/awsprofile version
The status should be success
The output should include "__release_version__"
Describe 'version command'
It 'prints version information'
When call ./bin/awsprofile version
The status should be success
The output should include "__release_version__"
End
End
End

End

0 comments on commit e8f2e6c

Please sign in to comment.