mirror of
https://github.com/prometheus/prometheus.git
synced 2025-08-06 22:27:17 +02:00
openstack tests: use new test.Cleanup function (#7514)
Since we dependend on go1.14 now, we can use T.Cleanup https://golang.org/pkg/testing/#T.Cleanup This provides a nicer approach to shut down the test server. Signed-off-by: Julien Pivotto <roidelapluie@inuits.eu>
This commit is contained in:
parent
ad7da8fd35
commit
27867412a7
@ -26,10 +26,6 @@ type OpenstackSDHypervisorTestSuite struct {
|
|||||||
Mock *SDMock
|
Mock *SDMock
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *OpenstackSDHypervisorTestSuite) TearDownSuite() {
|
|
||||||
s.Mock.ShutdownServer()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *OpenstackSDHypervisorTestSuite) SetupTest(t *testing.T) {
|
func (s *OpenstackSDHypervisorTestSuite) SetupTest(t *testing.T) {
|
||||||
s.Mock = NewSDMock(t)
|
s.Mock = NewSDMock(t)
|
||||||
s.Mock.Setup()
|
s.Mock.Setup()
|
||||||
@ -89,8 +85,6 @@ func TestOpenstackSDHypervisorRefresh(t *testing.T) {
|
|||||||
} {
|
} {
|
||||||
testutil.Equals(t, model.LabelValue(v), tg.Targets[1][model.LabelName(l)])
|
testutil.Equals(t, model.LabelValue(v), tg.Targets[1][model.LabelName(l)])
|
||||||
}
|
}
|
||||||
|
|
||||||
mock.TearDownSuite()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestOpenstackSDHypervisorRefreshWithDoneContext(t *testing.T) {
|
func TestOpenstackSDHypervisorRefreshWithDoneContext(t *testing.T) {
|
||||||
@ -103,6 +97,4 @@ func TestOpenstackSDHypervisorRefreshWithDoneContext(t *testing.T) {
|
|||||||
_, err := hypervisor.refresh(ctx)
|
_, err := hypervisor.refresh(ctx)
|
||||||
testutil.NotOk(t, err)
|
testutil.NotOk(t, err)
|
||||||
testutil.Assert(t, strings.Contains(err.Error(), context.Canceled.Error()), "%q doesn't contain %q", err, context.Canceled)
|
testutil.Assert(t, strings.Contains(err.Error(), context.Canceled.Error()), "%q doesn't contain %q", err, context.Canceled)
|
||||||
|
|
||||||
mock.TearDownSuite()
|
|
||||||
}
|
}
|
||||||
|
@ -27,10 +27,6 @@ type OpenstackSDInstanceTestSuite struct {
|
|||||||
Mock *SDMock
|
Mock *SDMock
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *OpenstackSDInstanceTestSuite) TearDownSuite() {
|
|
||||||
s.Mock.ShutdownServer()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *OpenstackSDInstanceTestSuite) SetupTest(t *testing.T) {
|
func (s *OpenstackSDInstanceTestSuite) SetupTest(t *testing.T) {
|
||||||
s.Mock = NewSDMock(t)
|
s.Mock = NewSDMock(t)
|
||||||
s.Mock.Setup()
|
s.Mock.Setup()
|
||||||
@ -128,8 +124,6 @@ func TestOpenstackSDInstanceRefresh(t *testing.T) {
|
|||||||
testutil.Equals(t, lbls, tg.Targets[i])
|
testutil.Equals(t, lbls, tg.Targets[i])
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
mock.TearDownSuite()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestOpenstackSDInstanceRefreshWithDoneContext(t *testing.T) {
|
func TestOpenstackSDInstanceRefreshWithDoneContext(t *testing.T) {
|
||||||
@ -142,6 +136,4 @@ func TestOpenstackSDInstanceRefreshWithDoneContext(t *testing.T) {
|
|||||||
_, err := hypervisor.refresh(ctx)
|
_, err := hypervisor.refresh(ctx)
|
||||||
testutil.NotOk(t, err)
|
testutil.NotOk(t, err)
|
||||||
testutil.Assert(t, strings.Contains(err.Error(), context.Canceled.Error()), "%q doesn't contain %q", err, context.Canceled)
|
testutil.Assert(t, strings.Contains(err.Error(), context.Canceled.Error()), "%q doesn't contain %q", err, context.Canceled)
|
||||||
|
|
||||||
mock.TearDownSuite()
|
|
||||||
}
|
}
|
||||||
|
@ -43,11 +43,7 @@ func (m *SDMock) Endpoint() string {
|
|||||||
func (m *SDMock) Setup() {
|
func (m *SDMock) Setup() {
|
||||||
m.Mux = http.NewServeMux()
|
m.Mux = http.NewServeMux()
|
||||||
m.Server = httptest.NewServer(m.Mux)
|
m.Server = httptest.NewServer(m.Mux)
|
||||||
}
|
m.t.Cleanup(m.Server.Close)
|
||||||
|
|
||||||
// ShutdownServer creates the mock server
|
|
||||||
func (m *SDMock) ShutdownServer() {
|
|
||||||
m.Server.Close()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const tokenID = "cbc36478b0bd8e67e89469c7749d4127"
|
const tokenID = "cbc36478b0bd8e67e89469c7749d4127"
|
||||||
|
Loading…
Reference in New Issue
Block a user