-
Notifications
You must be signed in to change notification settings - Fork 339
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7084a8a
commit 2262b47
Showing
3 changed files
with
118 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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{} | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | ||
}) | ||
}) | ||
}) |