packer-cn/packer/rpc/artifact_test.go

69 lines
1.2 KiB
Go
Raw Normal View History

2013-05-22 01:10:21 -04:00
package rpc
import (
"github.com/mitchellh/packer/packer"
"net/rpc"
2013-10-16 23:04:57 -04:00
"reflect"
2013-05-22 01:10:21 -04:00
"testing"
)
type testArtifact struct{}
func (testArtifact) BuilderId() string {
return "bid"
}
func (testArtifact) Files() []string {
return []string{"a", "b"}
}
func (testArtifact) Id() string {
return "id"
}
func (testArtifact) String() string {
return "string"
}
func (testArtifact) Destroy() error {
return nil
}
2013-05-22 01:10:21 -04:00
func TestArtifactRPC(t *testing.T) {
// Create the interface to test
a := new(testArtifact)
// Start the server
server := rpc.NewServer()
RegisterArtifact(server, a)
address := serveSingleConn(server)
// Create the client over RPC and run some methods to verify it works
client, err := rpc.Dial("tcp", address)
2013-10-16 23:04:57 -04:00
if err != nil {
t.Fatalf("err: %s", err)
}
2013-05-22 01:10:21 -04:00
aClient := Artifact(client)
// Test
2013-10-16 23:04:57 -04:00
if aClient.BuilderId() != "bid" {
t.Fatalf("bad: %s", aClient.BuilderId())
}
2013-05-22 01:10:21 -04:00
2013-10-16 23:04:57 -04:00
if !reflect.DeepEqual(aClient.Files(), []string{"a", "b"}) {
t.Fatalf("bad: %#v", aClient.Files())
}
2013-05-22 01:10:21 -04:00
2013-10-16 23:04:57 -04:00
if aClient.Id() != "id" {
t.Fatalf("bad: %s", aClient.Id())
}
2013-05-22 01:10:21 -04:00
2013-10-16 23:04:57 -04:00
if aClient.String() != "string" {
t.Fatalf("bad: %s", aClient.String())
}
}
func TestArtifact_Implements(t *testing.T) {
var _ packer.Artifact = Artifact(nil)
2013-05-22 01:10:21 -04:00
}