-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moving envvars_test from e2e to conformance (#2602)
Change moves the envvars_test.go from e2e to conformance folder to use the test as a conformance test for the environment variables requirement specified in the run-time contract (https://github.com/knative/serving/blob/master/docs/runtime-contract.md) The test image is also changed to be more generic and provide a server that can be used to get information about the environment under which the container runs. Currently the iamge only exposes environment variables defined inside the container by exposing "/envvars" to fetch all the environment variables. The image folder name is also changed to "environment" to indicate this semantic change. Change also adds test/conformance/constants.go to define a way to have constants that can be shared between test-images and tests. Change also adds test/conformance/runtime_contract_types.go to define the runtime contract as go types.
- Loading branch information
1 parent
a1bd165
commit d525d17
Showing
8 changed files
with
222 additions
and
57 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
// +build e2e | ||
|
||
/* | ||
Copyright 2018 The Knative 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 conformance | ||
|
||
import ( | ||
"encoding/json" | ||
"strconv" | ||
"testing" | ||
|
||
"github.com/knative/pkg/test/logging" | ||
"github.com/knative/serving/test" | ||
) | ||
|
||
//TestShouldEnvVars verifies environment variables that are declared as "SHOULD be set" in runtime-contract | ||
func TestShouldEnvVars(t *testing.T) { | ||
logger := logging.GetContextLogger("TestShouldEnvVars") | ||
var names test.ResourceNames | ||
resp, err := fetchEnvInfo(t, logger, test.EnvImageEnvVarsPath, &names) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
var respValues ShouldEnvvars | ||
if err := json.Unmarshal(resp, &respValues); err != nil { | ||
t.Fatalf("Failed to unmarshall response : %v", err) | ||
} | ||
|
||
expectedValues := ShouldEnvvars { | ||
Service: names.Service, | ||
Configuration : names.Config, | ||
Revision : names.Revision, | ||
} | ||
if respValues != expectedValues { | ||
t.Fatalf("Received response failed to match execpted response. Received: %v Expected: %v", respValues, expectedValues) | ||
} | ||
} | ||
|
||
//TestMustEnvVars verifies environment variables that are declared as "MUST be set" in runtime-contract | ||
func TestMustEnvVars(t *testing.T) { | ||
logger := logging.GetContextLogger("TestMustEnvVars") | ||
var names test.ResourceNames | ||
resp, err := fetchEnvInfo(t, logger, test.EnvImageEnvVarsPath, &names) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
var respValues MustEnvvars | ||
if err := json.Unmarshal(resp, &respValues); err != nil { | ||
t.Fatalf("Failed to unmarshall response : %v", err) | ||
} | ||
|
||
expectedValues := MustEnvvars { | ||
// The port value needs to match the port exposed by the test-image. | ||
// We currently control them by using a common constant, but any change needs synchronization between this check | ||
// and the value used by the test-image. | ||
Port: strconv.Itoa(test.EnvImageServerPort), | ||
} | ||
if respValues != expectedValues { | ||
t.Fatalf("Received response failed to match execpted response. Received: %v Expected: %v", respValues, expectedValues) | ||
} | ||
} |
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,33 @@ | ||
// +build e2e | ||
|
||
/* | ||
Copyright 2018 The Knative 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 conformance | ||
|
||
//runtime_constract_types.go defines types that encapsulate run-time contract requirements as specified here: https://github.com/knative/serving/blob/master/docs/runtime-contract.md | ||
|
||
//ShouldEnvvars defines the environment variables that "SHOULD" be set. | ||
type ShouldEnvvars struct { | ||
Service string `json:"K_SERVICE"` | ||
Configuration string `json:"K_CONFIGURATION"` | ||
Revision string `json:"K_REVISION"` | ||
} | ||
|
||
//MustEnvvars defines environment variables that "MUST" be set. | ||
type MustEnvvars struct { | ||
Port string `json:"PORT"` | ||
} |
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,26 @@ | ||
/* | ||
Copyright 2018 The Knative 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 | ||
|
||
//image_constants.go defines constants that are shared between test-images and conformance tests | ||
|
||
//EnvImageServerPort is the port on which the environment test-image server starts. | ||
// TODO: Modify this port number after https://github.com/knative/serving/issues/2258 is fixed for a stricter verification. | ||
const EnvImageServerPort = 8080 | ||
|
||
//EnvImageEnvVarsPath path exposed by environment test-image to fetch environment variables. | ||
const EnvImageEnvVarsPath = "/envvars" |
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,15 @@ | ||
# Environment test image | ||
|
||
This directory contains the test image used to retrieve environment information under which the container runs. This is used by conformance tests to verify Knative [run-time contract](/docs/runtime-contract.md) | ||
|
||
The image contains a simple Go webserver, `environment.go`, which by default, listens on port defined in the constant [EnvImageServerPort](/test/conformance/constants.go). | ||
|
||
Currently the server exposes: | ||
|
||
* /envvars : To provide a JSON payload containing all the environment variables set inside the container | ||
|
||
## Building | ||
|
||
For details about building and adding new images, see the [section about test | ||
images](/test/README.md#test-images). | ||
|
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 was deleted.
Oops, something went wrong.
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