Remove extra test flags from all commands

Currently all commands are being build with extra flags. The extra
flags appear because of a direct import of the testing package from
the fake_etcd_client.go source file.

Remove the direct import of the testing package. Add a tools.T
interface to support existing behavior. Also clean up two TODO items
by remove using of the expectError and expectNoError functions.

Fixes #579
This commit is contained in:
Kelsey Hightower
2014-07-27 06:30:32 -07:00
parent 8a5cc87df8
commit 87fa19cdfe
5 changed files with 68 additions and 38 deletions

View File

@@ -34,7 +34,9 @@ func TestExtractFromNonExistentFile(t *testing.T) {
ch := make(chan interface{}, 1)
c := SourceFile{"/some/fake/file", ch}
err := c.extractFromPath()
expectError(t, err)
if err == nil {
t.Errorf("Expected error")
}
}
func TestUpdateOnNonExistentFile(t *testing.T) {
@@ -94,7 +96,9 @@ func TestExtractFromBadDataFile(t *testing.T) {
ch := make(chan interface{}, 1)
c := SourceFile{file.Name(), ch}
err := c.extractFromPath()
expectError(t, err)
if err == nil {
t.Errorf("Expected error")
}
expectEmptyChannel(t, ch)
}
@@ -102,15 +106,18 @@ func TestExtractFromValidDataFile(t *testing.T) {
manifest := api.ContainerManifest{ID: ""}
text, err := json.Marshal(manifest)
expectNoError(t, err)
if err != nil {
t.Errorf("Unexpected error: %v", err)
}
file := writeTestFile(t, os.TempDir(), "test_pod_config", string(text))
defer os.Remove(file.Name())
ch := make(chan interface{}, 1)
c := SourceFile{file.Name(), ch}
err = c.extractFromPath()
expectNoError(t, err)
if err != nil {
t.Errorf("Unexpected error: %v", err)
}
update := (<-ch).(kubelet.PodUpdate)
expected := CreatePodUpdate(kubelet.SET, kubelet.Pod{Name: simpleSubdomainSafeHash(file.Name()), Manifest: manifest})
if !reflect.DeepEqual(expected, update) {
@@ -120,13 +127,17 @@ func TestExtractFromValidDataFile(t *testing.T) {
func TestExtractFromEmptyDir(t *testing.T) {
dirName, err := ioutil.TempDir("", "foo")
expectNoError(t, err)
if err != nil {
t.Errorf("Unexpected error: %v", err)
}
defer os.RemoveAll(dirName)
ch := make(chan interface{}, 1)
c := SourceFile{dirName, ch}
err = c.extractFromPath()
expectNoError(t, err)
if err != nil {
t.Errorf("Unexpected error: %v", err)
}
update := (<-ch).(kubelet.PodUpdate)
expected := CreatePodUpdate(kubelet.SET)
@@ -143,15 +154,23 @@ func TestExtractFromDir(t *testing.T) {
files := make([]*os.File, len(manifests))
dirName, err := ioutil.TempDir("", "foo")
expectNoError(t, err)
if err != nil {
t.Errorf("Unexpected error: %v", err)
}
for i, manifest := range manifests {
data, err := json.Marshal(manifest)
expectNoError(t, err)
if err != nil {
t.Errorf("Unexpected error: %v", err)
}
file, err := ioutil.TempFile(dirName, manifest.ID)
expectNoError(t, err)
if err != nil {
t.Errorf("Unexpected error: %v", err)
}
name := file.Name()
expectNoError(t, file.Close())
if err := file.Close(); err != nil {
t.Errorf("Unexpected error: %v", err)
}
ioutil.WriteFile(name, data, 0755)
files[i] = file
}
@@ -159,7 +178,9 @@ func TestExtractFromDir(t *testing.T) {
ch := make(chan interface{}, 1)
c := SourceFile{dirName, ch}
err = c.extractFromPath()
expectNoError(t, err)
if err != nil {
t.Errorf("Unexpected error: %v", err)
}
update := (<-ch).(kubelet.PodUpdate)
expected := CreatePodUpdate(