Skip to content

Commit

Permalink
add testing for argument type panics
Browse files Browse the repository at this point in the history
  • Loading branch information
KnicKnic committed Jul 7, 2019
1 parent 5bad2ef commit 8ce4c80
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
44 changes: 44 additions & 0 deletions pkg/powershell/higherops_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,3 +309,47 @@ func TestCpowershellCommandWithNamedParameters(t *testing.T) {
}
validate(t, "", record.lines)
}

func TestCpowershellCommandArgumentTypePanic(t *testing.T) {
record.Reset()
// create a runspace (where you run your powershell statements in)
runspace := CreateRunspace(fmtPrintLogger{}, nil)
// auto cleanup your runspace
defer runspace.Delete()

var caughtUnknownArgumentType bool
func() {
defer func() {
if r := recover(); r != nil {
if r == "unknown argument type" {
caughtUnknownArgumentType = true
}
}
}()
paramResults := runspace.ExecScript(`"Software" + "Type"`, true, nil, 1)
defer paramResults.Close()
}()

if !caughtUnknownArgumentType {
t.Fail()
}
caughtUnknownArgumentType = false

func() {
defer func() {
if r := recover(); r != nil {
if r == "unknown argument type" {
caughtUnknownArgumentType = true
}
}
}()
results := runspace.ExecCommand("Get-ItemPropertyValue", true, map[string]interface{}{
"Name": 1,
})
defer results.Close()
}()
if !caughtUnknownArgumentType {
t.Fail()
}
validate(t, "", record.lines)
}
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[![Build Status](https://dev.azure.com/oneeyedelf1/powershell.native/_apis/build/status/KnicKnic.go-powershell?branchName=master)](https://dev.azure.com/oneeyedelf1/powershell.native/_build/latest?definitionId=3&branchName=master)
[![Go Report Card](https://goreportcard.com/badge/github.com/KnicKnic/go-powershell)](https://goreportcard.com/report/github.com/KnicKnic/go-powershell)
[![gopherbadger](https://img.shields.io/badge/Go%20Coverage-97%25-brightgreen.svg?longCache=true&style=flat)](./scripts/code_coverage.ps1)
[![gopherbadger](https://img.shields.io/badge/Go%20Coverage-99%25-brightgreen.svg?longCache=true&style=flat)](./scripts/code_coverage.ps1)
[![GoDoc](https://godoc.org/github.com/KnicKnic/go-powershell/pkg/powershell?status.svg)](https://godoc.org/github.com/KnicKnic/go-powershell/pkg/powershell)

# Status
Expand Down

0 comments on commit 8ce4c80

Please sign in to comment.