コード例 #1
0
ファイル: commmand_test.go プロジェクト: alexcb/doit
func TestLiveCommand_Start(t *testing.T) {
	lc := NewLiveCommand("/bin/ls")
	err := lc.Start("/tmp")
	assert.NoError(t, err)

	assert.Equal(t, []string{"/bin/ls", "/tmp"}, lc.cmd.Args)

	err = lc.Stop()
	assert.NoError(t, err)
}
コード例 #2
0
ファイル: ssh_test.go プロジェクト: alexcb/doit
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)
	})
}
コード例 #3
0
ファイル: ssh_test.go プロジェクト: alexcb/doit
func TestSSH_Name(t *testing.T) {
	didFetchDroplet := false

	client := &godo.Client{
		Droplets: &doit.DropletsServiceMock{
			ListFn: func(*godo.ListOptions) ([]godo.Droplet, *godo.Response, error) {
				didFetchDroplet = true
				return testDropletList, nil, nil
			},
		},
	}

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

		ns := "test"

		err := RunSSH(ns, c, ioutil.Discard, []string{testDroplet.Name})
		assert.NoError(t, err)

		assert.Equal(t, "root", ms.user)
		assert.Equal(t, testDroplet.Networks.V4[0].IPAddress, ms.host)
	})
}
コード例 #4
0
ファイル: droplets_test.go プロジェクト: alexcb/doit
func TestDropletCreate(t *testing.T) {
	client := &godo.Client{
		Droplets: &doit.DropletsServiceMock{
			CreateFn: func(cr *godo.DropletCreateRequest) (*godo.Droplet, *godo.Response, error) {
				expected := &godo.DropletCreateRequest{
					Name:     "droplet",
					Image:    godo.DropletCreateImage{Slug: "image"},
					Region:   "dev0",
					Size:     "1gb",
					UserData: "#cloud-config",
					SSHKeys:  []godo.DropletCreateSSHKey{},
				}

				assert.Equal(t, cr, expected, "create requests did not match")

				return &testDroplet, nil, nil
			},
		},
	}

	withTestClient(client, func(c *TestConfig) {
		ns := "test"
		c.Set(ns, doit.ArgRegionSlug, "dev0")
		c.Set(ns, doit.ArgSizeSlug, "1gb")
		c.Set(ns, doit.ArgImage, "image")
		c.Set(ns, doit.ArgUserData, "#cloud-config")

		err := RunDropletCreate(ns, c, ioutil.Discard, []string{"droplet"})
		assert.NoError(t, err)
	})
}
コード例 #5
0
ファイル: sshkeys_test.go プロジェクト: alexcb/doit
func TestSSHPublicKeyImportWithName(t *testing.T) {
	pubkey := "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCn6eZ8ve0ha04rPRZuoPXK1AQ/h21qslWCzoDcOciXn5OcyafkZw+31k/afaBTeW62D8fXd8e/1xWbFfp/2GqmslYpNCTPrtpNhsE8I0yKjJ8FxX9FfsCOu/Sv83dWgSpiT7pNWVKarZjW9KdKKRQljq1i+H5pX3r5Q9I1v+66mYTe7qsKGas9KWy0vkGoNSqmTCl+d+Y0286chtqBqBjSCUCI8oLKPnJB86Lj344tFGmzDIsJKXMVHTL0dF8n3u6iWN4qiRU+JvkoIkI3v0JvyZXxhR2uPIS1yUAY2GC+2O5mfxydJQzBdtag5Uw8Y7H5yYR1gar/h16bAy5XzRvp testkey"
	path := filepath.Join(os.TempDir(), "key.pub")
	err := ioutil.WriteFile(path, []byte(pubkey), 0600)
	assert.NoError(t, err)
	defer os.Remove(path)

	client := &godo.Client{
		Keys: &doit.KeysServiceMock{
			CreateFn: func(req *godo.KeyCreateRequest) (*godo.Key, *godo.Response, error) {
				expected := &godo.KeyCreateRequest{
					Name:      "custom",
					PublicKey: pubkey,
				}
				assert.Equal(t, req, expected)
				return &testKey, nil, nil
			},
		},
	}

	withTestClient(client, func(c *TestConfig) {
		ns := "test"
		c.Set(ns, doit.ArgKeyPublicKeyFile, path)

		RunKeyImport(ns, c, ioutil.Discard, []string{"custom"})
	})
}
コード例 #6
0
ファイル: actions_test.go プロジェクト: alexcb/doit
func TestActionList(t *testing.T) {
	actionDidList := false

	client := &godo.Client{
		Actions: &doit.ActionsServiceMock{
			ListFn: func(opts *godo.ListOptions) ([]godo.Action, *godo.Response, error) {
				actionDidList = true
				resp := &godo.Response{
					Links: &godo.Links{
						Pages: &godo.Pages{},
					},
				}
				return testActionList, resp, nil
			},
		},
	}

	withTestClient(client, func(c *TestConfig) {
		ns := "test"
		err := RunCmdActionList(ns, c, ioutil.Discard, []string{})
		assert.NoError(t, err)

		if !actionDidList {
			t.Errorf("Action() did not run")
		}
	})
}
コード例 #7
0
ファイル: droplets_test.go プロジェクト: alexcb/doit
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)
	})
}
コード例 #8
0
ファイル: domains_test.go プロジェクト: alexcb/doit
func TestRecordsUpdate(t *testing.T) {
	client := &godo.Client{
		Domains: &doit.DomainsServiceMock{
			EditRecordFn: func(name string, id int, req *godo.DomainRecordEditRequest) (*godo.DomainRecord, *godo.Response, error) {
				expected := &godo.DomainRecordEditRequest{
					Type: "A",
					Name: "foo.example.com.",
					Data: "192.168.1.1",
				}

				assert.Equal(t, "example.com", name)
				assert.Equal(t, 1, id)
				assert.Equal(t, expected, req)

				return &testRecord, nil, nil
			},
		},
	}

	withTestClient(client, func(c *TestConfig) {
		ns := "test"
		c.Set(ns, doit.ArgRecordID, 1)
		c.Set(ns, doit.ArgRecordType, "A")
		c.Set(ns, doit.ArgRecordName, "foo.example.com.")
		c.Set(ns, doit.ArgRecordData, "192.168.1.1")

		err := RunRecordUpdate(ns, c, ioutil.Discard, []string{"example.com"})
		assert.NoError(t, err)
	})
}
コード例 #9
0
ファイル: droplets_test.go プロジェクト: alexcb/doit
func TestDropletKernelList(t *testing.T) {
	client := &godo.Client{
		Droplets: &doit.DropletsServiceMock{
			KernelsFn: func(id int, opts *godo.ListOptions) ([]godo.Kernel, *godo.Response, error) {
				if got, expected := id, 1; got != expected {
					t.Errorf("KernelsFn() id = %d; expected %d", got, expected)
				}

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

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

		err := RunDropletKernels(ns, c, ioutil.Discard, []string{})
		assert.NoError(t, err)
	})
}
コード例 #10
0
ファイル: actions_test.go プロジェクト: alexcb/doit
func TestActionGet(t *testing.T) {
	client := &godo.Client{
		Actions: &doit.ActionsServiceMock{
			GetFn: func(id int) (*godo.Action, *godo.Response, error) {
				if got, expected := id, testAction.ID; got != expected {
					t.Errorf("GetFn() called with %d; expected %d", got, expected)
				}
				return &testAction, nil, nil
			},
		},
	}

	withTestClient(client, func(c *TestConfig) {
		err := RunCmdActionGet("test", c, ioutil.Discard, []string{strconv.Itoa(testAction.ID)})
		assert.NoError(t, err)
	})
}
コード例 #11
0
ファイル: droplets_test.go プロジェクト: alexcb/doit
func TestDropletGet(t *testing.T) {
	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")
				return &testDroplet, nil, nil
			},
		},
	}

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

		err := RunDropletGet(ns, c, ioutil.Discard, []string{strconv.Itoa(testDroplet.ID)})
		assert.NoError(t, err)
	})
}
コード例 #12
0
ファイル: domains_test.go プロジェクト: alexcb/doit
func TestDomainsDelete(t *testing.T) {
	client := &godo.Client{
		Domains: &doit.DomainsServiceMock{
			DeleteFn: func(name string) (*godo.Response, error) {
				if got, expected := name, testDomain.Name; got != expected {
					t.Errorf("DeleteFn() received %q; expected %q", got, expected)
				}
				return nil, nil
			},
		},
	}

	withTestClient(client, func(c *TestConfig) {
		ns := "test"
		err := RunDomainDelete(ns, c, ioutil.Discard, []string{testDomain.Name})
		assert.NoError(t, err)
	})
}
コード例 #13
0
ファイル: domains_test.go プロジェクト: alexcb/doit
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)
	})
}
コード例 #14
0
ファイル: domains_test.go プロジェクト: alexcb/doit
func TestRecordsDelete(t *testing.T) {
	client := &godo.Client{
		Domains: &doit.DomainsServiceMock{
			DeleteRecordFn: func(name string, id int) (*godo.Response, error) {
				if got, expected := name, "example.com"; got != expected {
					t.Errorf("CreateFn domain name = %q; expected %q", got, expected)
				}
				if got, expected := id, 1; got != expected {
					t.Errorf("CreateFn id = %d; expected %d", got, expected)
				}
				return nil, nil
			},
		},
	}

	withTestClient(client, func(c *TestConfig) {
		ns := "test"
		c.Set(ns, doit.ArgRecordID, 1)
		err := RunRecordDelete(ns, c, ioutil.Discard, []string{"example.com"})
		assert.NoError(t, err)
	})
}
コード例 #15
0
ファイル: domains_test.go プロジェクト: alexcb/doit
func TestDomainsCreate(t *testing.T) {
	client := &godo.Client{
		Domains: &doit.DomainsServiceMock{
			CreateFn: func(req *godo.DomainCreateRequest) (*godo.Domain, *godo.Response, error) {
				expected := &godo.DomainCreateRequest{
					Name:      testDomain.Name,
					IPAddress: "127.0.0.1",
				}
				if got := req; !reflect.DeepEqual(got, expected) {
					t.Errorf("CreateFn() called with %#v; expected %#v", got, expected)
				}
				return &testDomain, nil, nil
			},
		},
	}

	withTestClient(client, func(c *TestConfig) {
		ns := "test"
		c.Set(ns, doit.ArgIPAddress, "127.0.0.1")
		err := RunDomainCreate(ns, c, ioutil.Discard, []string{testDomain.Name})
		assert.NoError(t, err)
	})
}
コード例 #16
0
ファイル: droplets_test.go プロジェクト: alexcb/doit
func TestDropletBackupList(t *testing.T) {
	client := &godo.Client{
		Droplets: &doit.DropletsServiceMock{
			BackupsFn: func(id int, opts *godo.ListOptions) ([]godo.Image, *godo.Response, error) {
				assert.Equal(t, 1, id)

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

	withTestClient(client, func(c *TestConfig) {
		ns := "test"
		c.Set(ns, doit.ArgDropletID, 1)
		err := RunDropletBackups(ns, c, ioutil.Discard, []string{})
		assert.NoError(t, err)
	})
}
コード例 #17
0
ファイル: droplets_test.go プロジェクト: alexcb/doit
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)
	})
}
コード例 #18
0
ファイル: account_test.go プロジェクト: alexcb/doit
func TestAccountGet(t *testing.T) {
	accountDidGet := false

	client := &godo.Client{
		Account: &doit.AccountServiceMock{
			GetFn: func() (*godo.Account, *godo.Response, error) {
				accountDidGet = true
				return testAccount, nil, nil
			},
		},
	}

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

		err := RunAccountGet(ns, c, ioutil.Discard, []string{})
		assert.NoError(t, err)

		if !accountDidGet {
			t.Errorf("could not retrieve account")
		}
	})
}
コード例 #19
0
ファイル: domains_test.go プロジェクト: alexcb/doit
func TestDomainsList(t *testing.T) {
	domainsDisList := false

	client := &godo.Client{
		Domains: &doit.DomainsServiceMock{
			ListFn: func(opts *godo.ListOptions) ([]godo.Domain, *godo.Response, error) {
				domainsDisList = true
				resp := &godo.Response{
					Links: &godo.Links{},
				}
				return testDomainList, resp, nil
			},
		},
	}

	withTestClient(client, func(c *TestConfig) {
		ns := "test"
		err := RunDomainList(ns, c, ioutil.Discard, []string{})
		assert.NoError(t, err)
		if !domainsDisList {
			t.Errorf("List() did not run")
		}
	})
}
コード例 #20
0
ファイル: commmand_test.go プロジェクト: alexcb/doit
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)
}