Skip to content

Commit

Permalink
feat(kuma-cp) traffic trace api
Browse files Browse the repository at this point in the history
  • Loading branch information
jakubdyszkiewicz committed Feb 18, 2020
1 parent 7084a8a commit 2262b47
Show file tree
Hide file tree
Showing 3 changed files with 118 additions and 0 deletions.
1 change: 1 addition & 0 deletions pkg/api-server/definitions/all.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ var All = []ResourceWsDefinition{
TrafficPermissionWsDefinition,
TrafficLogWsDefinition,
TrafficRouteWsDefinition,
TrafficTraceWsDefinition,
}
17 changes: 17 additions & 0 deletions pkg/api-server/definitions/traffic_trace.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package definitions

import (
"github.com/Kong/kuma/pkg/core/resources/apis/mesh"
"github.com/Kong/kuma/pkg/core/resources/model"
)

var TrafficTraceWsDefinition = ResourceWsDefinition{
Name: "Traffic Trace",
Path: "traffic-traces",
ResourceFactory: func() model.Resource {
return &mesh.TrafficTraceResource{}
},
ResourceListFactory: func() model.ResourceList {
return &mesh.TrafficTraceResourceList{}
},
}
100 changes: 100 additions & 0 deletions pkg/api-server/traffic_trace_ws_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
package api_server_test

import (
"context"
"io/ioutil"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"

"github.com/ghodss/yaml"

mesh_proto "github.com/Kong/kuma/api/mesh/v1alpha1"
api_server "github.com/Kong/kuma/pkg/api-server"
config "github.com/Kong/kuma/pkg/config/api-server"
mesh_core "github.com/Kong/kuma/pkg/core/resources/apis/mesh"
"github.com/Kong/kuma/pkg/core/resources/model/rest"
"github.com/Kong/kuma/pkg/core/resources/store"
"github.com/Kong/kuma/pkg/plugins/resources/memory"
)

var _ = Describe("TrafficTrace WS", func() {
var apiServer *api_server.ApiServer
var resourceStore store.ResourceStore
var client resourceApiClient
var stop chan struct{}

BeforeEach(func() {
resourceStore = memory.NewStore()
apiServer = createTestApiServer(resourceStore, config.DefaultApiServerConfig())
client = resourceApiClient{
apiServer.Address(),
"/meshes/default/traffic-traces",
}
stop = make(chan struct{})
go func() {
defer GinkgoRecover()
err := apiServer.Start(stop)
Expect(err).ToNot(HaveOccurred())
}()
waitForServer(&client)
}, 5)

AfterEach(func() {
close(stop)
})

BeforeEach(func() {
// when
err := resourceStore.Create(context.Background(), &mesh_core.MeshResource{}, store.CreateByKey("default", "default"))
// then
Expect(err).ToNot(HaveOccurred())
})

Describe("PUT => GET", func() {

given := `
type: TrafficTrace
name: backends-eu
mesh: default
selectors:
- match:
service: backend
region: eu
conf:
backend: zipkin-eu
`
It("GET should return data saved by PUT", func() {
// given
resource := rest.Resource{
Spec: &mesh_proto.TrafficTrace{},
}

// when
err := yaml.Unmarshal([]byte(given), &resource)
// then
Expect(err).ToNot(HaveOccurred())

// when
response := client.put(resource)
// then
Expect(response.StatusCode).To(Equal(201))

// when
response = client.get("backends-eu")
// then
Expect(response.StatusCode).To(Equal(200))
// when
body, err := ioutil.ReadAll(response.Body)
// then
Expect(err).ToNot(HaveOccurred())

// when
actual, err := yaml.JSONToYAML(body)
// then
Expect(err).ToNot(HaveOccurred())
// and
Expect(actual).To(MatchYAML(given))
})
})
})

0 comments on commit 2262b47

Please sign in to comment.