Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 18 additions & 12 deletions src/envoy/mixer/integration_test/BUILD
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2016 Google Inc. All Rights Reserved.
# Copyright 2017 Istio Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -15,13 +15,15 @@
################################################################################
#

load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
load("@io_bazel_rules_go//go:def.bzl", "go_library")
load(":test_suite.bzl", "go_test_suite")

go_library(
name = "go_default_library",
srcs = [
"attributes.go",
"envoy.go",
"envoy_conf.go",
"http_client.go",
"http_server.go",
"mixer_server.go",
Expand All @@ -41,18 +43,22 @@ go_library(
],
)

go_test(
name = "mixer_test",
size = "small",
srcs = [
"mixer_test.go",
],
go_test_suite(
data = [
"envoy.conf",
"//src/envoy/mixer:envoy",
],
library = ":go_default_library",
# shared memory path /envoy_shared_memory_0 used by Envoy
# hot start is not working in sandbox mode.
local = True,
tags = [
# Use fixed ports, not in sanbbox, have to be run exclusively.
"exclusive",
# shared memory path /envoy_shared_memory_0 used by Envoy
# hot start is not working in sandbox mode.
"local",
],
tests = [
"check_cache_test.go",
"check_report_test.go",
"failed_request_test.go",
"quota_test.go",
],
)
16 changes: 15 additions & 1 deletion src/envoy/mixer/integration_test/attributes.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,21 @@ func verifyStringMap(actual map[string]string, expected map[string]interface{})
return nil
}

// Please see the comment at top of mixer_test.go for verification rules
// Attributes verification rules:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this rule applied to real situation or just for go test pipeline?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just for integration test.

//
// 1) If value is *, key must exist, but value is not checked.
// 1) If value is -, key must NOT exist.
// 3) At top level attributes, not inside StringMap, all keys must
// be listed. Extra keys are NOT allowed
// 3) Inside StringMap, not need to list all keys. Extra keys are allowed
//
// Attributes provided from envoy config
// * source.id and source.namespace are forwarded from client proxy
// * target.id and target.namespace are from server proxy
//
// HTTP header "x-istio-attributes" is used to forward attributes between
// proxy. It should be removed before calling mixer and backend.
//
func Verify(b *attribute.MutableBag, json_results string) error {
var r map[string]interface{}
if err := json.Unmarshal([]byte(json_results), &r); err != nil {
Expand Down
40 changes: 40 additions & 0 deletions src/envoy/mixer/integration_test/check_cache_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright 2017 Istio Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package test

import (
"fmt"
"testing"
)

func TestCheckCache(t *testing.T) {
s, err := SetUp(t, basicConfig+","+checkCacheConfig)
if err != nil {
t.Fatalf("Failed to setup test: %v", err)
}
defer s.TearDown()

url := fmt.Sprintf("http://localhost:%d/echo", ClientProxyPort)

// Issues a GET echo request with 0 size body
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shall we add body here for test?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

body is irreverent here, we just test chache for Check calls to mixer.

tag := "OKGet"
for i := 0; i < 10; i++ {
if _, _, err := HTTPGet(url); err != nil {
t.Errorf("Failed in request %s: %v", tag, err)
}
// Only the first check is called.
s.VerifyCheckCount(tag, 1)
}
}
154 changes: 154 additions & 0 deletions src/envoy/mixer/integration_test/check_report_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
// Copyright 2017 Istio Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package test

import (
"fmt"
"testing"
)

// Check attributes from a good GET request
const checkAttributesOkGet = `
{
"request.host": "localhost:27070",
"request.path": "/echo",
"request.time": "*",
"source.uid": "POD11",
"source.namespace": "XYZ11",
"target.uid": "POD222",
"target.namespace": "XYZ222",
"request.headers": {
":method": "GET",
":path": "/echo",
":authority": "localhost:27070",
"x-forwarded-proto": "http",
"x-istio-attributes": "-",
"x-request-id": "*"
}
}
`

// Report attributes from a good GET request
const reportAttributesOkGet = `
{
"request.host": "localhost:27070",
"request.path": "/echo",
"request.time": "*",
"source.uid": "POD11",
"source.namespace": "XYZ11",
"target.uid": "POD222",
"target.namespace": "XYZ222",
"request.headers": {
":method": "GET",
":path": "/echo",
":authority": "localhost:27070",
"x-forwarded-proto": "http",
"x-istio-attributes": "-",
"x-request-id": "*"
},
"request.size": 0,
"response.time": "*",
"response.size": 0,
"response.latency": "*",
"response.http.code": 200,
"response.headers": {
"date": "*",
"content-type": "text/plain; charset=utf-8",
"content-length": "0",
":status": "200",
"server": "envoy"
}
}
`

// Check attributes from a good POST request
const checkAttributesOkPost = `
{
"request.host": "localhost:27070",
"request.path": "/echo",
"request.time": "*",
"source.uid": "POD11",
"source.namespace": "XYZ11",
"target.uid": "POD222",
"target.namespace": "XYZ222",
"request.headers": {
":method": "POST",
":path": "/echo",
":authority": "localhost:27070",
"x-forwarded-proto": "http",
"x-istio-attributes": "-",
"x-request-id": "*"
}
}
`

// Report attributes from a good POST request
const reportAttributesOkPost = `
{
"request.host": "localhost:27070",
"request.path": "/echo",
"request.time": "*",
"source.uid": "POD11",
"source.namespace": "XYZ11",
"target.uid": "POD222",
"target.namespace": "XYZ222",
"request.headers": {
":method": "POST",
":path": "/echo",
":authority": "localhost:27070",
"x-forwarded-proto": "http",
"x-istio-attributes": "-",
"x-request-id": "*"
},
"request.size": 12,
"response.time": "*",
"response.size": 12,
"response.latency": "*",
"response.http.code": 200,
"response.headers": {
"date": "*",
"content-type": "text/plain",
"content-length": "12",
":status": "200",
"server": "envoy"
}
}
`

func TestCheckReportAttributes(t *testing.T) {
s, err := SetUp(t, basicConfig)
if err != nil {
t.Fatalf("Failed to setup test: %v", err)
}
defer s.TearDown()

url := fmt.Sprintf("http://localhost:%d/echo", ClientProxyPort)

// Issues a GET echo request with 0 size body
tag := "OKGet"
if _, _, err := HTTPGet(url); err != nil {
t.Errorf("Failed in request %s: %v", tag, err)
}
s.VerifyCheck(tag, checkAttributesOkGet)
s.VerifyReport(tag, reportAttributesOkGet)

// Issues a POST request.
tag = "OKPost"
if _, _, err := HTTPPost(url, "text/plain", "Hello World!"); err != nil {
t.Errorf("Failed in request %s: %v", tag, err)
}
s.VerifyCheck(tag, checkAttributesOkPost)
s.VerifyReport(tag, reportAttributesOkPost)
}
35 changes: 10 additions & 25 deletions src/envoy/mixer/integration_test/envoy.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,24 +39,6 @@ func getTestBinRootPath() string {
}
}

func getTestDataRootPath() string {
switch {
// custom path
case os.Getenv("TEST_DATA_ROOT") != "":
return os.Getenv("TEST_DATA_ROOT")
// running under bazel
case os.Getenv("TEST_SRCDIR") != "":
return os.Getenv("TEST_SRCDIR") + "/__main__"
// running with native go
case os.Getenv("GOPATH") != "":
list := strings.Split(os.Getenv("GOPATH"),
string(os.PathListSeparator))
return list[0]
default:
return ""
}
}

type Envoy struct {
cmd *exec.Cmd
}
Expand All @@ -76,14 +58,17 @@ func Run(name string, args ...string) (s string, err error) {
return
}

func NewEnvoy() (*Envoy, error) {
path := getTestBinRootPath() + "/src/envoy/mixer/envoy"
conf := getTestDataRootPath() +
"/src/envoy/mixer/integration_test/envoy.conf"
log.Printf("Envoy binary: %v\n", path)
log.Printf("Envoy config: %v\n", conf)
func NewEnvoy(conf string) (*Envoy, error) {
bin_path := getTestBinRootPath() + "/src/envoy/mixer/envoy"
log.Printf("Envoy binary: %v\n", bin_path)

conf_path := "/tmp/envoy.conf"
log.Printf("Envoy config: in %v\n%v\n", conf_path, conf)
if err := CreateEnvoyConf(conf_path, conf); err != nil {
return nil, err
}

cmd := exec.Command(path, "-c", conf, "-l", "debug")
cmd := exec.Command(bin_path, "-c", conf_path, "-l", "debug")
cmd.Stderr = os.Stderr
cmd.Stdout = os.Stdout
return &Envoy{
Expand Down
Loading