winrmtest

package module
v0.0.0-...-fbc9ae5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 3, 2021 License: MIT Imports: 12 Imported by: 227 modules, 216 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

winrmtest

An in-progress testing package to compliment the masterzen/winrm Go-based winrm library.

My primary use-case for this is for dylanmei/packer-communicator-winrm, a Packer communicator plugin for interacting with machines using Windows Remote Management.

Example Use

A fictitious "Windows tools" package.


package wintools

import (
	"io"
	"testing"
	"github.com/dylanmei/winrmtest"
)

func Test_empty_temp_directory(t *testing.T) {
	r := winrmtest.NewRemote()
	defer r.Close()

	r.CommandFunc(wimrmtest.MatchText("dir C:\Temp"), func(out, err io.Writer) int {
		out.Write([]byte(` Volume in drive C is Windows 2012 R2
 Volume Serial Number is XXXX-XXXX

 Directory of C:\

File Not Found`))
		return 0
	})

	lister := NewDirectoryLister(r.Host, r.Port)
	list, _ := lister.TempDirectory()

	if count := len(list.Dirs()); count != 0 {
		t.Errorf("Expected 0 directories but found %d.\n", count)
	}

	if count := len(list.Files()); count != 0 {
		t.Errorf("Expected 0 files but found %d.\n", count)
	}
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CommandFunc

type CommandFunc func(out, err io.Writer) (exitCode int)

CommandFunc respresents a function used to mock WinRM commands

type MatcherFunc

type MatcherFunc func(candidate string) bool

MatcherFunc respresents a function used to match WinRM commands

func MatchPattern

func MatchPattern(pattern string) MatcherFunc

MatchPattern return a new MatcherFunc based on pattern matching

func MatchText

func MatchText(text string) MatcherFunc

MatchText return a new MatcherFunc based on text matching

type Remote

type Remote struct {
	Host string
	Port int
	// contains filtered or unexported fields
}

Remote respresents a WinRM server

func NewRemote

func NewRemote() *Remote

NewRemote returns a new initialized Remote

func (*Remote) Close

func (r *Remote) Close()

Close closes the WinRM server

func (*Remote) CommandFunc

func (r *Remote) CommandFunc(m MatcherFunc, f CommandFunc)

CommandFunc adds a WinRM command mock function to the WinRM server

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL