Skip to content

Commit

Permalink
fix build and add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
KnicKnic committed Jul 4, 2019
1 parent 643d707 commit 2195458
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 3 deletions.
7 changes: 5 additions & 2 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ steps:
dir . ;'
- task: CmdLine@2
inputs:
script: 'go build -x -v'
script: 'go build github.com/KnicKnic/go-powershell/pkg/powershell'
# - task: PowerShell@2
# inputs:
# errorActionPreference: 'continue'
Expand Down Expand Up @@ -81,7 +81,10 @@ steps:
script: 'go test github.com/KnicKnic/go-powershell/tests'
- task: CmdLine@2
inputs:
script: 'go build -a -o go-powershell.exe .\test_app\cmd'
script: 'go test github.com/KnicKnic/go-powershell/pkg/powershell'
- task: CmdLine@2
inputs:
script: 'go build -a -o go-powershell.exe github.com/KnicKnic/go-powershell/test_app/cmd'
- task: PowerShell@2
inputs:
targetType: 'inline'
Expand Down
37 changes: 37 additions & 0 deletions pkg/powershell/higherops_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,4 +183,41 @@ func Example_localScope() {
// In Logging : Debug: ab ba
}

type callbackAddRef struct{}

func (c callbackAddRef) Callback(str string, input []Object, results CallbackResultsWriter) {
for _, object := range input {
results.Write(object.AddRef(), true)
}
}

func Example_callbackWriteTrue() {
runspace := CreateRunspace(fmtPrintLogger{}, callbackAddRef{})
defer runspace.Delete()
results := runspace.ExecStr(`1 | send-hostcommand -message 'empty'`, true )
defer results.Close()
// Output:
}
type callbackAddRefSave struct{
objects *[]Object
}

func (c callbackAddRefSave) Callback(str string, input []Object, results CallbackResultsWriter) {
for _, object := range input {
*c.objects = append(*c.objects, object.AddRef())
}
}
func Example_callbackSaveObject() {
var callback callbackAddRefSave
callback.objects = &([]Object{})
runspace := CreateRunspace(fmtPrintLogger{}, callback)
defer runspace.Delete()
results := runspace.ExecStr(`1 | send-hostcommand -message 'empty'`, true )
defer results.Close()
results2 := runspace.ExecStr(`write-host $args[0]`, true, (*callback.objects)[0] )
defer results2.Close()
for _,object := range *callback.objects{
object.Close()
}
// Output: In Logging : Debug: 1
}
2 changes: 1 addition & 1 deletion tests/a_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package tests

import (
"fmt"
powershell "github.com/KnicKnic/go-powershell"
"github.com/KnicKnic/go-powershell/pkg/powershell"
)

// GLogInfoLogger is a simple struct that provides ability to send logs to glog at Info level
Expand Down

0 comments on commit 2195458

Please sign in to comment.