Skip to content

Commit

Permalink
change: import Change type from docker
Browse files Browse the repository at this point in the history
Related to #65.
  • Loading branch information
fsouza committed Jan 27, 2014
1 parent 10676d9 commit b6ab52c
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
33 changes: 33 additions & 0 deletions change.go
@@ -0,0 +1,33 @@
// Copyright 2014 go-dockerclient authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package docker

import "fmt"

type ChangeType int

const (
ChangeModify ChangeType = iota
ChangeAdd
ChangeDelete
)

type Change struct {
Path string
Kind ChangeType
}

func (change *Change) String() string {
var kind string
switch change.Kind {
case ChangeModify:
kind = "C"
case ChangeAdd:
kind = "A"
case ChangeDelete:
kind = "D"
}
return fmt.Sprintf("%s %s", kind, change.Path)
}
26 changes: 26 additions & 0 deletions change_test.go
@@ -0,0 +1,26 @@
// Copyright 2014 go-dockerclient authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package docker

import (
"testing"
)

func TestChangeString(t *testing.T) {
var tests = []struct {
change Change
expected string
}{
{Change{"/etc/passwd", ChangeModify}, "C /etc/passwd"},
{Change{"/etc/passwd", ChangeAdd}, "A /etc/passwd"},
{Change{"/etc/passwd", ChangeDelete}, "D /etc/passwd"},
{Change{"/etc/passwd", 33}, " /etc/passwd"},
}
for _, tt := range tests {
if got := tt.change.String(); got != tt.expected {
t.Errorf("Change.String(): want %q. Got %q.", tt.expected, got)
}
}
}

0 comments on commit b6ab52c

Please sign in to comment.