2019-03-05 07:16:53 +00:00
|
|
|
// Copyright 2019 Drone.IO Inc. All rights reserved.
|
|
|
|
// Use of this source code is governed by the Drone Non-Commercial License
|
|
|
|
// that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
// +build !oss
|
|
|
|
|
|
|
|
package sink
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/drone/drone/mock"
|
|
|
|
"github.com/golang/mock/gomock"
|
|
|
|
"github.com/h2non/gock"
|
|
|
|
)
|
|
|
|
|
|
|
|
var noContext = context.Background()
|
|
|
|
|
|
|
|
func TestDo(t *testing.T) {
|
|
|
|
controller := gomock.NewController(t)
|
|
|
|
|
|
|
|
gock.InterceptClient(httpClient)
|
|
|
|
defer func() {
|
|
|
|
gock.RestoreClient(httpClient)
|
|
|
|
gock.Off()
|
|
|
|
controller.Finish()
|
|
|
|
}()
|
|
|
|
|
|
|
|
users := mock.NewMockUserStore(controller)
|
|
|
|
users.EXPECT().Count(gomock.Any()).Return(int64(10), nil)
|
|
|
|
|
|
|
|
repos := mock.NewMockRepositoryStore(controller)
|
|
|
|
repos.EXPECT().Count(gomock.Any()).Return(int64(20), nil)
|
|
|
|
|
|
|
|
builds := mock.NewMockBuildStore(controller)
|
|
|
|
builds.EXPECT().Count(gomock.Any()).Return(int64(30), nil)
|
|
|
|
|
|
|
|
gock.New("https://api.datadoghq.com").
|
|
|
|
Post("/api/v1/series").
|
|
|
|
JSON(sample).
|
|
|
|
Reply(200)
|
|
|
|
|
|
|
|
d := new(Datadog)
|
|
|
|
d.users = users
|
|
|
|
d.repos = repos
|
|
|
|
d.builds = builds
|
|
|
|
d.system.Host = "test.example.com"
|
2019-03-13 22:16:42 +00:00
|
|
|
d.config.License = "trial"
|
|
|
|
d.config.EnableGithub = true
|
|
|
|
d.config.EnableAgents = true
|
2019-03-05 07:16:53 +00:00
|
|
|
d.config.Endpoint = "https://api.datadoghq.com/api/v1/series"
|
|
|
|
d.do(noContext, 915148800)
|
|
|
|
|
|
|
|
if gock.IsPending() {
|
|
|
|
t.Errorf("Unfinished requests")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var sample = `{
|
|
|
|
"series" : [
|
|
|
|
{
|
|
|
|
"metric": "drone.users",
|
|
|
|
"points": [[915148800, 10]],
|
|
|
|
"type": "gauge",
|
2019-03-13 22:16:42 +00:00
|
|
|
"host": "test.example.com",
|
|
|
|
"tags": ["remote:github:cloud","scheduler:internal:agents","license:trial"]
|
2019-03-05 07:16:53 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"metric": "drone.repos",
|
|
|
|
"points": [[915148800, 20]],
|
|
|
|
"type": "gauge",
|
2019-03-13 22:16:42 +00:00
|
|
|
"host": "test.example.com",
|
|
|
|
"tags": ["remote:github:cloud","scheduler:internal:agents","license:trial"]
|
2019-03-05 07:16:53 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"metric": "drone.builds",
|
|
|
|
"points": [[915148800, 30]],
|
|
|
|
"type": "gauge",
|
2019-03-13 22:16:42 +00:00
|
|
|
"host": "test.example.com",
|
|
|
|
"tags": ["remote:github:cloud","scheduler:internal:agents","license:trial"]
|
2019-03-05 07:16:53 +00:00
|
|
|
}
|
|
|
|
]
|
|
|
|
}`
|