13dab7dd24
* Divest api/ package of deps elsewhere in the nomad repo. This will allow making api/ a module without then pulling in the external repo, leading to a package name conflict. This required some migration of tests to an apitests/ folder (can be moved anywhere as it has no deps on it). It also required some duplication of code, notably some test helpers from api/ -> apitests/ and part (but not all) of testutil/ -> api/testutil/. Once there's more separation and an e.g. sdk/ folder those can be removed in favor of a dep on the sdk/ folder, provided the sdk/ folder doesn't depend on api/ or /. * Also remove consul dep from api/ package * Fix stupid linters * Some restructuring
54 lines
1.2 KiB
Go
54 lines
1.2 KiB
Go
package api
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestOperator_RaftGetConfiguration(t *testing.T) {
|
|
t.Parallel()
|
|
c, s := makeClient(t, nil, nil)
|
|
defer s.Stop()
|
|
|
|
operator := c.Operator()
|
|
out, err := operator.RaftGetConfiguration(nil)
|
|
if err != nil {
|
|
t.Fatalf("err: %v", err)
|
|
}
|
|
if len(out.Servers) != 1 ||
|
|
!out.Servers[0].Leader ||
|
|
!out.Servers[0].Voter {
|
|
t.Fatalf("bad: %v", out)
|
|
}
|
|
}
|
|
|
|
func TestOperator_RaftRemovePeerByAddress(t *testing.T) {
|
|
t.Parallel()
|
|
c, s := makeClient(t, nil, nil)
|
|
defer s.Stop()
|
|
|
|
// If we get this error, it proves we sent the address all the way
|
|
// through.
|
|
operator := c.Operator()
|
|
err := operator.RaftRemovePeerByAddress("nope", nil)
|
|
if err == nil || !strings.Contains(err.Error(),
|
|
"address \"nope\" was not found in the Raft configuration") {
|
|
t.Fatalf("err: %v", err)
|
|
}
|
|
}
|
|
|
|
func TestOperator_RaftRemovePeerByID(t *testing.T) {
|
|
t.Parallel()
|
|
c, s := makeClient(t, nil, nil)
|
|
defer s.Stop()
|
|
|
|
// If we get this error, it proves we sent the address all the way
|
|
// through.
|
|
operator := c.Operator()
|
|
err := operator.RaftRemovePeerByID("nope", nil)
|
|
if err == nil || !strings.Contains(err.Error(),
|
|
"id \"nope\" was not found in the Raft configuration") {
|
|
t.Fatalf("err: %v", err)
|
|
}
|
|
}
|