Skip to content
This repository was archived by the owner on Aug 26, 2022. It is now read-only.

Commit 8ad1ced

Browse files
committed
Populate claim data
This patch populates all claim data except for lshw characteristics, which is tracked separately by CTONET-528. This fulfills the definition of done requirements for CTONET-580. In order to make this change, some heavier architectural decisions were made. First, it was made explicit (in CONTRIBUTING.md) that configuration must be provided with working MarshalJSON and UnmarshalJSON interfaces (whether they are purely inherited or custom if needed). The reason is a claim is defined using JSON, and to make the test session repeatable, the configuration must be included in the claim. To keep track of the different configurations available, a lightweight singleton pool is abstracted called `Pool`. Different configurations must register with the Pool so they are included in the Claim. Information for registering with the Pool is included in Contributing.md. Version information is currently in pre-release, but eventually should be populated by a build system. For now, a "version.json" was abstracted to allow developers to bump the version, so it may be included in the claim file. Simply rev the version with a commit, then tag a release. Changes were 100% unit tested. The generated claim.json file was tested for compliance with test-network-function-claim's claim-schema.json (v0.0.4). Signed-off-by: Ryan Goulding <[email protected]>
1 parent 560cfdf commit 8ad1ced

24 files changed

+667
-111
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
claim.json
12
.idea
23
vendor
34
*.test

CONTRIBUTING.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,18 @@ Each contributed test is expected to implement the `reel.Handler` and `tnf.Test`
7474
must be based on CLI commands. No tests should utilize OpenShift client. The choice to avoid OpenShift client is
7575
deliberate, and was decided to aid in support of all versions of OpenShift despite the API(s) changing. Generally
7676
speaking, the CLI API changes much less quickly.
77+
78+
## Configuration guidelines
79+
80+
Most tests will require some form of configuration. All configuration must implement or inherit a working `MarshalJSON`
81+
and `UnmarshalJSON` interface. This is due to the fact that a
82+
[test-network-function-claim](https://github.com/redhat-nfvpe/test-network-function-claim) is output as JSON.
83+
84+
Additionally, each configuration type must be registered with `pkg/config/pool`. In order to register with the
85+
configuration pool, use code similar to the following:
86+
87+
```
88+
(*configpool.GetInstance()).RegisterConfiguration(configurationKey, config)
89+
```
90+
91+
Any configuration that adheres to these two requirements will automatically be included in the claim.

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ mocks:
6767
mockgen -source=./internal/reel/reel.go -destination=./internal/reel/mocks/mock_reel.go
6868

6969
unit-tests:
70-
go test -coverprofile=cover.out `go list ./... | grep -v "github.com/redhat-nfvpe/test-network-function/test-network-function" | grep -v mock` && go tool cover -html=cover.out
70+
go test -coverprofile=cover.out `go list ./... | grep -v "github.com/redhat-nfvpe/test-network-function/test-network-function" | grep -v mock`
7171

7272
lint:
7373
golint `go list ./... | grep -v vendor`

go.mod

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,17 @@ module github.com/redhat-nfvpe/test-network-function
33
go 1.14
44

55
require (
6+
github.com/basgys/goxml2json v1.1.0
7+
github.com/bitly/go-simplejson v0.5.0 // indirect
8+
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 // indirect
69
github.com/golang/mock v1.4.3
710
github.com/google/goexpect v0.0.0-20200816234442-b5b77125c2c5
11+
github.com/kr/pretty v0.2.1 // indirect
812
github.com/onsi/ginkgo v1.14.1
913
github.com/onsi/gomega v1.10.2
14+
github.com/redhat-nfvpe/test-network-function-claim v0.0.4
1015
github.com/sirupsen/logrus v1.6.0
11-
github.com/stretchr/testify v1.2.2
16+
github.com/stretchr/testify v1.6.1
1217
google.golang.org/grpc v1.31.0
1318
gopkg.in/yaml.v2 v2.3.0
1419
kubevirt.io/qe-tools v0.1.6

go.sum

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
11
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
22
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
3+
github.com/a-h/generate v0.0.0-20190312091541-e59c34d33fb3/go.mod h1:traiLYQ0YD7qUMCdjo6/jSaJRPHXniX4HVs+PhEhYpc=
4+
github.com/basgys/goxml2json v1.1.0 h1:4ln5i4rseYfXNd86lGEB+Vi652IsIXIvggKM/BhUKVw=
5+
github.com/basgys/goxml2json v1.1.0/go.mod h1:wH7a5Np/Q4QoECFIU8zTQlZwZkrilY0itPfecMw41Dw=
6+
github.com/bitly/go-simplejson v0.5.0 h1:6IH+V8/tVMab511d5bn4M7EwGXZf9Hj6i2xSwkNEM+Y=
7+
github.com/bitly/go-simplejson v0.5.0/go.mod h1:cXHtHw4XUPsvGaxgjIAn8PhEWG9NfngEKAMDJEczWVA=
8+
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 h1:DDGfHa7BWjL4YnC6+E63dPcxHo2sUxDIu8g3QgEJdRY=
9+
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869/go.mod h1:Ekp36dRnpXw/yCqJaO+ZrUyxD+3VXMFFr56k5XYrpB4=
310
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
411
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
512
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
13+
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
614
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
715
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
816
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
@@ -42,6 +50,11 @@ github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI=
4250
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
4351
github.com/konsorten/go-windows-terminal-sequences v1.0.3 h1:CE8S1cTafDpPvMhIxNJKvHsGVBgn1xWYf1NbHQhywc8=
4452
github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
53+
github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI=
54+
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
55+
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
56+
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
57+
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
4558
github.com/nxadm/tail v1.4.4 h1:DQuhQpB1tVlglWS2hLQ5OV6B5r8aGxSrPc5Qo6uTN78=
4659
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
4760
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
@@ -56,10 +69,15 @@ github.com/onsi/gomega v1.10.2/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1y
5669
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
5770
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
5871
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
72+
github.com/redhat-nfvpe/test-network-function-claim v0.0.4 h1:TNxLiOPAvBi0M8uWk83ukdo89qHSO28Pr+8fWbf+OLc=
73+
github.com/redhat-nfvpe/test-network-function-claim v0.0.4/go.mod h1:hswacvCvO0o9aZAero2OU4A6mHzELv2wqfR+cqyMMVg=
5974
github.com/sirupsen/logrus v1.6.0 h1:UBcNElsrwanuuMsnGSlYmtmgbb23qDR5dG+6X6Oo89I=
6075
github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88=
76+
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
6177
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
6278
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
79+
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
80+
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
6381
github.com/ziutek/telnet v0.0.0-20180329124119-c3b780dc415b h1:VfPXB/wCGGt590QhD1bOpv2J/AmC/RJNTg/Q59HKSB0=
6482
github.com/ziutek/telnet v0.0.0-20180329124119-c3b780dc415b/go.mod h1:IZpXDfkJ6tWD3PhBK5YzgQT+xJWh7OsdwiG8hA2MkO4=
6583
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
@@ -135,6 +153,8 @@ gopkg.in/yaml.v2 v2.2.4 h1:/eiJrUcujPVeJ3xlSWaiNi3uSVmDGBK1pDHUHAnao1I=
135153
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
136154
gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU=
137155
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
156+
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
157+
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
138158
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
139159
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
140160
kubevirt.io/qe-tools v0.1.6 h1:S6z9CATmgV2/z9CWetij++Rhu7l/Z4ObZqerLdNMo0Y=

pkg/config/doc.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/*
2+
Package config provides a config pool. Configurations registered with the pool are automatically included in the claim.
3+
*/
4+
package config

pkg/config/pool.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package config
2+
3+
import "fmt"
4+
5+
// instance is the Singleton for config Pool.
6+
var instance = &Pool{
7+
configurations: make(map[string]interface{}),
8+
}
9+
10+
// Pool follows the pool design pattern, and contains the named configurations.
11+
type Pool struct {
12+
configurations map[string]interface{}
13+
}
14+
15+
// RegisterConfiguration registers a configuration with the Pool. If configurationKey is already contained in the pool,
16+
// an appropriate error is returned.
17+
func (p *Pool) RegisterConfiguration(configurationKey string, configurationPayload interface{}) error {
18+
if _, ok := p.configurations[configurationKey]; ok {
19+
return fmt.Errorf("pool already contains a configuration for: %s", configurationKey)
20+
}
21+
p.configurations[configurationKey] = configurationPayload
22+
return nil
23+
}
24+
25+
// GetConfigurations returns the raw configuration map.
26+
func (p *Pool) GetConfigurations() map[string]interface{} {
27+
return p.configurations
28+
}
29+
30+
// GetInstance returns the singleton Pool
31+
func GetInstance() *Pool {
32+
return instance
33+
}

pkg/config/pool_test.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package config_test
2+
3+
import (
4+
"fmt"
5+
"github.com/redhat-nfvpe/test-network-function/pkg/config"
6+
"github.com/stretchr/testify/assert"
7+
"testing"
8+
)
9+
10+
func TestGetInstance(t *testing.T) {
11+
assert.NotNil(t, config.GetInstance())
12+
}
13+
14+
// Also tests GetConfigurations
15+
func TestPool_RegisterConfiguration(t *testing.T) {
16+
type arbitraryConfig struct {
17+
name string
18+
id int
19+
}
20+
assert.Nil(t, config.GetInstance().RegisterConfiguration("someKey", &arbitraryConfig{}))
21+
assert.Contains(t, config.GetInstance().GetConfigurations(), "someKey")
22+
assert.Equal(t, &arbitraryConfig{}, config.GetInstance().GetConfigurations()["someKey"])
23+
assert.Equal(t, fmt.Errorf("pool already contains a configuration for: someKey"),
24+
config.GetInstance().RegisterConfiguration("someKey", &arbitraryConfig{}))
25+
}

pkg/junit/convert.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package junit
2+
3+
import (
4+
"bytes"
5+
j "encoding/json"
6+
xj "github.com/basgys/goxml2json"
7+
"os"
8+
)
9+
10+
// ExportJUnitAsJSON attempts to read a JUnit XML file and converts it to a generic JSON map.
11+
func ExportJUnitAsJSON(junitFilename string) (map[string]interface{}, error) {
12+
xmlReader, err := os.Open(junitFilename)
13+
// An error is encountered reading the file.
14+
if err != nil {
15+
return nil, err
16+
}
17+
18+
junitJSONBuffer, err := xj.Convert(xmlReader)
19+
// An error is encountered translating from XML to JSON.
20+
if err != nil {
21+
return nil, err
22+
}
23+
24+
jsonMap, err := convertJSONBytesToMap(junitJSONBuffer)
25+
// An error is encountered unmarshalling the data.
26+
if err != nil {
27+
return nil, err
28+
}
29+
30+
return jsonMap, err
31+
}
32+
33+
// convertJSONBytesToMap is a utility function to convert a bytes.Buffer to a generic JSON map.
34+
func convertJSONBytesToMap(junitJSONBuffer *bytes.Buffer) (map[string]interface{}, error) {
35+
jsonMap := make(map[string]interface{})
36+
err := j.Unmarshal(junitJSONBuffer.Bytes(), &jsonMap)
37+
return jsonMap, err
38+
}

pkg/junit/doc.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/*
2+
Package junit provides utility conversion methods for encoding JUnit XML results to generic JSON.
3+
*/
4+
package junit

0 commit comments

Comments
 (0)