Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add some integration tests #520

Merged
merged 5 commits into from
Oct 2, 2017
Merged
Show file tree
Hide file tree
Changes from 4 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
3 changes: 3 additions & 0 deletions src/envoy/mixer/integration_test/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ go_test_suite(
"check_report_disable_test.go",
"disable_check_cache_test.go",
"failed_request_test.go",
"fault_inject_test.go",
"internal_fail_close_test.go",
"internal_fail_open_test.go",
"quota_cache_test.go",
"quota_test.go",
"report_batch_test.go",
Expand Down
6 changes: 3 additions & 3 deletions src/envoy/mixer/integration_test/check_fail_close_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import (

func TestFailClose(t *testing.T) {
s := &TestSetup{
t: t,
conf: basicConfig+","+networkFailClose,
t: t,
conf: basicConfig + "," + networkFailClose,
no_mixer: true,
}
if err := s.SetUp(); err != nil {
Expand All @@ -32,7 +32,7 @@ func TestFailClose(t *testing.T) {

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

tag := "Fail-Open"
tag := "Fail-CLOSE"
Copy link
Contributor

Choose a reason for hiding this comment

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

Fail-Close?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

// Use fail close policy.
code, _, err := HTTPGet(url)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions src/envoy/mixer/integration_test/check_fail_open_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import (

func TestFailOpen(t *testing.T) {
s := &TestSetup{
t: t,
conf: basicConfig,
t: t,
conf: basicConfig,
no_mixer: true,
}
if err := s.SetUp(); err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func TestCheckReportDisable(t *testing.T) {
var err error
// stop and start a new envoy config
s.envoy.Stop()
s.envoy, err = NewEnvoy(s.conf, checkOnlyFlags, s.stress)
s.envoy, err = NewEnvoy(s.conf, checkOnlyFlags, s.stress, s.fault_inject)
if err != nil {
t.Errorf("unable to re-create Envoy %v", err)
} else {
Expand All @@ -74,7 +74,7 @@ func TestCheckReportDisable(t *testing.T) {

// stop and start a new envoy config
s.envoy.Stop()
s.envoy, err = NewEnvoy(s.conf, reportOnlyFlags, s.stress)
s.envoy, err = NewEnvoy(s.conf, reportOnlyFlags, s.stress, s.fault_inject)
if err != nil {
t.Errorf("unable to re-create Envoy %v", err)
} else {
Expand Down
4 changes: 2 additions & 2 deletions src/envoy/mixer/integration_test/envoy.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,13 @@ func Run(name string, args ...string) (s string, err error) {
return
}

func NewEnvoy(conf, flags string, stress bool) (*Envoy, error) {
func NewEnvoy(conf, flags string, stress, fault_inject bool) (*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, flags, stress); err != nil {
if err := CreateEnvoyConf(conf_path, conf, flags, stress, fault_inject); err != nil {
return nil, err
}

Expand Down
20 changes: 19 additions & 1 deletion src/envoy/mixer/integration_test/envoy_conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ type ConfParam struct {
ServerConfig string
AccessLog string
MixerRouteFlags string
FaultFilter string
}

// A basic config
Expand Down Expand Up @@ -103,6 +104,19 @@ const defaultMixerRouteFlags = `
"mixer_control": "on",
`

const allAbortFaultFilter = `
{
"type": "decoder",
"name": "fault",
"config": {
"abort": {
"abort_percent": 100,
"http_status": 503
}
}
},
`

// The envoy config template
const envoyConfTempl = `
{
Expand Down Expand Up @@ -152,6 +166,7 @@ const envoyConfTempl = `
{{.ServerConfig}}
}
},
{{.FaultFilter}}
{
"type": "decoder",
"name": "router",
Expand Down Expand Up @@ -320,7 +335,7 @@ func getConf() ConfParam {
}
}

func CreateEnvoyConf(path, conf, flags string, stress bool) error {
func CreateEnvoyConf(path, conf, flags string, stress, fault_inject bool) error {
c := getConf()
c.ServerConfig = conf
c.MixerRouteFlags = defaultMixerRouteFlags
Expand All @@ -330,5 +345,8 @@ func CreateEnvoyConf(path, conf, flags string, stress bool) error {
if stress {
c.AccessLog = "/dev/null"
}
if fault_inject {
c.FaultFilter = allAbortFaultFilter
}
return c.write(path)
}
125 changes: 125 additions & 0 deletions src/envoy/mixer/integration_test/fault_inject_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
// 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.
// 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 fault injected GET request
const checkAttributes = `
{
"context.protocol": "http",
"mesh1.ip": "[1 1 1 1]",
"mesh2.ip": "[0 0 0 0 0 0 0 0 0 0 255 255 204 152 189 116]",
"mesh3.ip": "[0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 8]",
"request.host": "localhost:27070",
"request.path": "/echo",
"request.time": "*",
"request.useragent": "Go-http-client/1.1",
"request.method": "GET",
"request.scheme": "http",
"source.uid": "POD11",
"source.namespace": "XYZ11",
"source.name": "source-name",
"source.user": "source-user",
"source.ip": "*",
"source.port": "*",
"target.name": "target-name",
"target.user": "target-user",
"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 fault inject GET request
const reportAttributes = `
{
"context.protocol": "http",
"mesh1.ip": "[1 1 1 1]",
"mesh2.ip": "[0 0 0 0 0 0 0 0 0 0 255 255 204 152 189 116]",
"mesh3.ip": "[0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 8]",
"request.host": "localhost:27070",
"request.path": "/echo",
"request.time": "*",
"request.useragent": "Go-http-client/1.1",
"request.method": "GET",
"request.scheme": "http",
"source.uid": "POD11",
"source.namespace": "XYZ11",
"source.name": "source-name",
"source.user": "source-user",
"source.ip": "*",
"source.port": "*",
"target.name": "target-name",
"target.user": "target-user",
"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": 18,
"response.duration": "*",
"response.code": 503,
"response.headers": {
"date": "*",
"content-type": "text/plain",
"content-length": "18",
":status": "503",
"server": "envoy"
}
}
`

func TestFaultInject(t *testing.T) {
s := &TestSetup{
t: t,
conf: basicConfig,
fault_inject: true,
}
if err := s.SetUp(); err != nil {
t.Fatalf("Failed to setup test: %v", err)
}
defer s.TearDown()

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

tag := "FaultInject"
code, _, err := HTTPGet(url)
if err != nil {
t.Errorf("Failed in request %s: %v", tag, err)
}
if code != 503 {
t.Errorf("Status code 503 is expected, got %d.", code)
}
s.VerifyCheck(tag, checkAttributes)
s.VerifyReport(tag, reportAttributes)
}
49 changes: 49 additions & 0 deletions src/envoy/mixer/integration_test/internal_fail_close_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// 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.
// 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"

rpc "github.com/googleapis/googleapis/google/rpc"
)

func TestFailCloseForMixerInternal(t *testing.T) {
s := &TestSetup{
t: t,
conf: basicConfig + "," + networkFailClose,
}
if err := s.SetUp(); err != nil {
t.Fatalf("Failed to setup test: %v", err)
}
defer s.TearDown()

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

tag := "Fail-Close"
// Mixer to return INTERNAL error.
s.mixer.check.r_status = rpc.Status{
Code: int32(rpc.INTERNAL),
}
code, _, err := HTTPGet(url)
if err != nil {
t.Errorf("Failed in request %s: %v", tag, err)
}
// Since fail_close policy, expect 500.
if code != 500 {
t.Errorf("Status code 500 is expected, got %d.", code)
}
}
49 changes: 49 additions & 0 deletions src/envoy/mixer/integration_test/internal_fail_open_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// 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.
// 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"

rpc "github.com/googleapis/googleapis/google/rpc"
)

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

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

tag := "Fail-Open"
// Mixer to return INTERNAL error.
s.mixer.check.r_status = rpc.Status{
Code: int32(rpc.INTERNAL),
}
code, _, err := HTTPGet(url)
if err != nil {
t.Errorf("Failed in request %s: %v", tag, err)
}
// Since fail_open policy by default, expect 200.
if code != 200 {
t.Errorf("Status code 200 is expected, got %d.", code)
}
}
11 changes: 6 additions & 5 deletions src/envoy/mixer/integration_test/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@ import (
)

type TestSetup struct {
t *testing.T
conf string
stress bool
no_mixer bool
t *testing.T
conf string
stress bool
fault_inject bool
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: faultInject and noMixer

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

no_mixer bool

envoy *Envoy
mixer *MixerServer
Expand All @@ -32,7 +33,7 @@ type TestSetup struct {

func (s *TestSetup) SetUp() error {
var err error
s.envoy, err = NewEnvoy(s.conf, "", s.stress)
s.envoy, err = NewEnvoy(s.conf, "", s.stress, s.fault_inject)
if err != nil {
log.Printf("unable to create Envoy %v", err)
} else {
Expand Down