Beispiel #1
0
func TestSSH_ID(t *testing.T) {
	didFetchDroplet := false

	client := &godo.Client{
		Droplets: &doit.DropletsServiceMock{
			GetFn: func(id int) (*godo.Droplet, *godo.Response, error) {
				assert.Equal(t, id, testDroplet.ID, "droplet ids did not match")
				didFetchDroplet = true
				return &testDroplet, nil, nil
			},
		},
	}

	withTestClient(client, func(c *TestConfig) {
		ms := &sshMock{}
		c.SSHFn = ms.cmd()

		ns := "test"
		err := RunSSH(ns, c, ioutil.Discard, []string{strconv.Itoa(testDroplet.ID)})
		assert.NoError(t, err)
		assert.True(t, didFetchDroplet)
		assert.True(t, ms.didRun)
		assert.Equal(t, "root", ms.user)
		assert.Equal(t, testDroplet.Networks.V4[0].IPAddress, ms.host)
	})
}
Beispiel #2
0
func TestKeysList(t *testing.T) {
	didList := false

	client := &godo.Client{
		Keys: &doit.KeysServiceMock{
			ListFn: func(opts *godo.ListOptions) ([]godo.Key, *godo.Response, error) {
				didList = true

				resp := &godo.Response{
					Links: &godo.Links{
						Pages: &godo.Pages{},
					},
				}

				return testKeyList, resp, nil
			},
		},
	}

	withTestClient(client, func(c *TestConfig) {
		ns := "test"
		RunKeyList(ns, c, ioutil.Discard, []string{})
		assert.True(t, didList)
	})
}
Beispiel #3
0
func TestDropletNeighbors(t *testing.T) {
	didRun := false
	client := &godo.Client{
		Droplets: &doit.DropletsServiceMock{
			NeighborsFn: func(id int) ([]godo.Droplet, *godo.Response, error) {
				didRun = true
				assert.Equal(t, id, 1)

				resp := &godo.Response{
					Links: &godo.Links{
						Pages: &godo.Pages{},
					},
				}
				return testDropletList, resp, nil
			},
		},
	}

	withTestClient(client, func(c *TestConfig) {
		ns := "test"
		c.Set(ns, doit.ArgDropletID, testDroplet.ID)

		err := RunDropletNeighbors(ns, c, ioutil.Discard, []string{})
		assert.NoError(t, err)
		assert.True(t, didRun)
	})
}
Beispiel #4
0
func TestDropletCommand(t *testing.T) {
	c := Droplet()

	expectedCmds := []string{"actions", "backups", "create", "delete", "get", "kernels", "list",
		"neighbors", "snapshots"}

	for _, ec := range expectedCmds {
		found := false
		for _, cmd := range c.Commands() {
			if cmd.Name() == ec {
				found = true
			}
		}

		assert.True(t, found, "could not find %s", ec)
	}

	c.Commands()[0].Name()
}
Beispiel #5
0
func TestRecordsList(t *testing.T) {
	recordsDidList := false

	client := &godo.Client{
		Domains: &doit.DomainsServiceMock{
			RecordsFn: func(name string, opts *godo.ListOptions) ([]godo.DomainRecord, *godo.Response, error) {
				recordsDidList = true
				return testRecordList, nil, nil
			},
		},
	}

	withTestClient(client, func(c *TestConfig) {
		ns := "test"

		err := RunRecordList(ns, c, ioutil.Discard, []string{"example.com"})
		assert.NoError(t, err)
		assert.True(t, recordsDidList)
	})
}
Beispiel #6
0
func TestMockCommand_Start(t *testing.T) {
	mc := NewMockCommand("/bin/ls")

	startErr := errors.New("start error")
	stopErr := errors.New("top error")
	mc.startFn = func() error {
		return startErr
	}
	mc.stopFn = func() error {
		return stopErr
	}

	err := mc.Start()
	assert.Error(t, err)
	assert.True(t, mc.running)

	err = mc.Stop()
	assert.Error(t, err)
	assert.False(t, mc.running)

}
Beispiel #7
0
func TestDropletsList(t *testing.T) {
	didRun := false
	client := &godo.Client{
		Droplets: &doit.DropletsServiceMock{
			ListFn: func(opts *godo.ListOptions) ([]godo.Droplet, *godo.Response, error) {
				didRun = true
				resp := &godo.Response{
					Links: &godo.Links{
						Pages: &godo.Pages{},
					},
				}
				return testDropletList, resp, nil
			},
		},
	}

	withTestClient(client, func(c *TestConfig) {
		ns := "test"
		err := RunDropletList(ns, c, ioutil.Discard, []string{})
		assert.NoError(t, err)
		assert.True(t, didRun)
	})
}
Beispiel #8
0
func TestImagesListUser(t *testing.T) {
	didRun := false

	client := &godo.Client{
		Images: &doit.ImagesServiceMock{
			ListUserFn: func(opts *godo.ListOptions) ([]godo.Image, *godo.Response, error) {
				didRun = true

				resp := &godo.Response{
					Links: &godo.Links{
						Pages: &godo.Pages{},
					},
				}
				return testImageList, resp, nil
			},
		},
	}

	withTestClient(client, func(c *TestConfig) {
		ns := "test"
		RunImagesListUser(ns, c, ioutil.Discard, []string{})
		assert.True(t, didRun)
	})
}
Beispiel #9
0
func TestLiveCommand_Run(t *testing.T) {
	lc := NewLiveCommand("/bin/ls")
	out, err := lc.Run("-d", "/tmp")
	assert.NoError(t, err)
	assert.True(t, len(string(out)) > 0)
}