Example #1
0
func TestWriteExtraInvalid(t *testing.T) {
	src := `
  [foo]
  hello=world
  `
	src2 := `
	[foo]
	goodbye=all
	herp?
	other=data
	`

	expBytes := 27
	file, err := Load(strings.NewReader(src))
	if err != nil {
		t.Skipped()
	}

	n, err := file.Write([]byte(src2))
	if n != expBytes {
		t.Errorf("Expected to write %d bytes, got %d", expBytes, n)
	}
	if err == nil {
		t.Errorf("Expected an error on partial write, got none")
	}

	check := func(section, key, expect string) {
		checkStr(t, file, section, key, expect)
	}

	check("foo", "hello", "world")
	check("foo", "goodbye", "all")
}
Example #2
0
func TestWriteExtra(t *testing.T) {
	src := `
  [foo]
  hello=world
  `
	src2 := `
	[foo]
	goodbye=all
	[bar]
	other=data
	`

	expBytes := len(src2)
	file, err := Load(strings.NewReader(src))
	if err != nil {
		t.Skipped()
	}

	n, err := file.Write([]byte(src2))
	if n != expBytes {
		t.Errorf("Expected to write %d bytes, got %d", expBytes, n)
	}

	check := func(section, key, expect string) {
		checkStr(t, file, section, key, expect)
	}

	check("foo", "hello", "world")
	check("foo", "goodbye", "all")
	check("bar", "other", "data")
}
Example #3
0
func initTestServer(t *testing.T) (*testutil.TestServer, *api.Client) {
	if testing.Short() {
		t.Skip("skipping test dependent on consul because of short mode")
	}
	defer func() {
		// if consul is not in the $PATH, NewTestServer will skip the test,
		// which should be treated as an error
		if t.Skipped() {
			t.Error("failing skipped test")
		}
	}()
	server := testutil.NewTestServerConfig(t, func(c *testutil.TestServerConfig) {
		ports := getPorts(t, 6)
		c.Ports = &testutil.TestPortConfig{
			DNS:     ports[0],
			HTTP:    ports[1],
			RPC:     ports[2],
			SerfLan: ports[3],
			SerfWan: ports[4],
			Server:  ports[5],
		}
	})
	client, err := api.NewClient(&api.Config{
		Address: server.HTTPAddr,
	})
	if err != nil {
		t.Fatal(err)
	}
	return server, client
}
Example #4
0
func dependOn(t *testing.T, deps ...func(*testing.T)) {
	for _, dependancy := range deps {
		dependancy(t)

		if t.Skipped() || t.Failed() {
			t.Skip("Dependency failed, Skipping.")
		}
	}
}
Example #5
0
func dependOn(t *testing.T, deps ...func(*testing.T)) {
	// stops things getting logged into other test logs
	temp := new(testing.T)
	for _, dependancy := range deps {
		dependancy(temp)

		if temp.Skipped() || temp.Failed() {
			t.Skip("Dependency failed, Skipping.")
		}
	}
}
Example #6
0
func makeStore(t *testing.T) (kp.Store, *testutil.TestServer) {
	if testing.Short() {
		t.Skip("skipping test dependendent on consul because of short mode")
	}

	// testutil.NewTestServerConfig will skip the test if "consul" isn't in the system path.
	// We'd rather the test fail.
	defer func() {
		if t.Skipped() {
			t.Fatalf("test skipped by testutil package")
		}
	}()

	// Create server
	server := testutil.NewTestServerConfig(t, func(c *testutil.TestServerConfig) {
		// consul output in test output is noisy
		c.Stdout = ioutil.Discard
		c.Stderr = ioutil.Discard

		// If ports are left to their defaults, this test conflicts
		// with the test consul servers in pkg/kp
		var offset uint64
		idx := int(atomic.AddUint64(&offset, 1))
		c.Ports = &testutil.TestPortConfig{
			DNS:     26000 + idx,
			HTTP:    27000 + idx,
			RPC:     28000 + idx,
			SerfLan: 29000 + idx,
			SerfWan: 30000 + idx,
			Server:  31000 + idx,
		}
	})

	client := kp.NewConsulClient(kp.Options{
		Address: server.HTTPAddr,
	})
	store := kp.NewConsulStore(client)
	return store, server
}
Example #7
0
// Create a new test fixture that spins up a local Consul server.
func NewConsulTestFixture(t *testing.T) *ConsulTestFixture {
	if testing.Short() {
		t.Skip("skipping test dependent on consul because of short mode")
	}

	// testutil.NewTestServerConfig will skip the test if "consul" isn't in the system path.
	// We'd rather the test fail.
	defer func() {
		if t.Skipped() {
			t.Error("failing skipped test")
		}
	}()
	server := testutil.NewTestServer(t)
	client := NewConsulClient(Options{
		Address: server.HTTPAddr,
	})
	store := NewConsulStore(client)
	return &ConsulTestFixture{
		TestServer: server,
		Store:      store,
		Client:     client,
		T:          t,
	}
}
Example #8
0
func TestAddPatternsFromPathFileOpenErr(t *testing.T) {
	t.Skipped()
}