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

Commit

Permalink
Populate claim data
Browse files Browse the repository at this point in the history
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 <rgouldin@redhat.com>
  • Loading branch information
ryandgoulding committed Nov 10, 2020
1 parent 560cfdf commit 8ad1ced
Show file tree
Hide file tree
Showing 24 changed files with 667 additions and 111 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
claim.json
.idea
vendor
*.test
Expand Down
15 changes: 15 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,18 @@ Each contributed test is expected to implement the `reel.Handler` and `tnf.Test`
must be based on CLI commands. No tests should utilize OpenShift client. The choice to avoid OpenShift client is
deliberate, and was decided to aid in support of all versions of OpenShift despite the API(s) changing. Generally
speaking, the CLI API changes much less quickly.

## Configuration guidelines

Most tests will require some form of configuration. All configuration must implement or inherit a working `MarshalJSON`
and `UnmarshalJSON` interface. This is due to the fact that a
[test-network-function-claim](https://github.com/redhat-nfvpe/test-network-function-claim) is output as JSON.

Additionally, each configuration type must be registered with `pkg/config/pool`. In order to register with the
configuration pool, use code similar to the following:

```
(*configpool.GetInstance()).RegisterConfiguration(configurationKey, config)
```

Any configuration that adheres to these two requirements will automatically be included in the claim.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ mocks:
mockgen -source=./internal/reel/reel.go -destination=./internal/reel/mocks/mock_reel.go

unit-tests:
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
go test -coverprofile=cover.out `go list ./... | grep -v "github.com/redhat-nfvpe/test-network-function/test-network-function" | grep -v mock`

lint:
golint `go list ./... | grep -v vendor`
Expand Down
7 changes: 6 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,17 @@ module github.com/redhat-nfvpe/test-network-function
go 1.14

require (
github.com/basgys/goxml2json v1.1.0
github.com/bitly/go-simplejson v0.5.0 // indirect
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 // indirect
github.com/golang/mock v1.4.3
github.com/google/goexpect v0.0.0-20200816234442-b5b77125c2c5
github.com/kr/pretty v0.2.1 // indirect
github.com/onsi/ginkgo v1.14.1
github.com/onsi/gomega v1.10.2
github.com/redhat-nfvpe/test-network-function-claim v0.0.4
github.com/sirupsen/logrus v1.6.0
github.com/stretchr/testify v1.2.2
github.com/stretchr/testify v1.6.1
google.golang.org/grpc v1.31.0
gopkg.in/yaml.v2 v2.3.0
kubevirt.io/qe-tools v0.1.6
Expand Down
20 changes: 20 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/a-h/generate v0.0.0-20190312091541-e59c34d33fb3/go.mod h1:traiLYQ0YD7qUMCdjo6/jSaJRPHXniX4HVs+PhEhYpc=
github.com/basgys/goxml2json v1.1.0 h1:4ln5i4rseYfXNd86lGEB+Vi652IsIXIvggKM/BhUKVw=
github.com/basgys/goxml2json v1.1.0/go.mod h1:wH7a5Np/Q4QoECFIU8zTQlZwZkrilY0itPfecMw41Dw=
github.com/bitly/go-simplejson v0.5.0 h1:6IH+V8/tVMab511d5bn4M7EwGXZf9Hj6i2xSwkNEM+Y=
github.com/bitly/go-simplejson v0.5.0/go.mod h1:cXHtHw4XUPsvGaxgjIAn8PhEWG9NfngEKAMDJEczWVA=
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 h1:DDGfHa7BWjL4YnC6+E63dPcxHo2sUxDIu8g3QgEJdRY=
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869/go.mod h1:Ekp36dRnpXw/yCqJaO+ZrUyxD+3VXMFFr56k5XYrpB4=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
Expand Down Expand Up @@ -42,6 +50,11 @@ github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/konsorten/go-windows-terminal-sequences v1.0.3 h1:CE8S1cTafDpPvMhIxNJKvHsGVBgn1xWYf1NbHQhywc8=
github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI=
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/nxadm/tail v1.4.4 h1:DQuhQpB1tVlglWS2hLQ5OV6B5r8aGxSrPc5Qo6uTN78=
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
Expand All @@ -56,10 +69,15 @@ github.com/onsi/gomega v1.10.2/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1y
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
github.com/redhat-nfvpe/test-network-function-claim v0.0.4 h1:TNxLiOPAvBi0M8uWk83ukdo89qHSO28Pr+8fWbf+OLc=
github.com/redhat-nfvpe/test-network-function-claim v0.0.4/go.mod h1:hswacvCvO0o9aZAero2OU4A6mHzELv2wqfR+cqyMMVg=
github.com/sirupsen/logrus v1.6.0 h1:UBcNElsrwanuuMsnGSlYmtmgbb23qDR5dG+6X6Oo89I=
github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/ziutek/telnet v0.0.0-20180329124119-c3b780dc415b h1:VfPXB/wCGGt590QhD1bOpv2J/AmC/RJNTg/Q59HKSB0=
github.com/ziutek/telnet v0.0.0-20180329124119-c3b780dc415b/go.mod h1:IZpXDfkJ6tWD3PhBK5YzgQT+xJWh7OsdwiG8hA2MkO4=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
Expand Down Expand Up @@ -135,6 +153,8 @@ gopkg.in/yaml.v2 v2.2.4 h1:/eiJrUcujPVeJ3xlSWaiNi3uSVmDGBK1pDHUHAnao1I=
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU=
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
kubevirt.io/qe-tools v0.1.6 h1:S6z9CATmgV2/z9CWetij++Rhu7l/Z4ObZqerLdNMo0Y=
Expand Down
4 changes: 4 additions & 0 deletions pkg/config/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/*
Package config provides a config pool. Configurations registered with the pool are automatically included in the claim.
*/
package config
33 changes: 33 additions & 0 deletions pkg/config/pool.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package config

import "fmt"

// instance is the Singleton for config Pool.
var instance = &Pool{
configurations: make(map[string]interface{}),
}

// Pool follows the pool design pattern, and contains the named configurations.
type Pool struct {
configurations map[string]interface{}
}

// RegisterConfiguration registers a configuration with the Pool. If configurationKey is already contained in the pool,
// an appropriate error is returned.
func (p *Pool) RegisterConfiguration(configurationKey string, configurationPayload interface{}) error {
if _, ok := p.configurations[configurationKey]; ok {
return fmt.Errorf("pool already contains a configuration for: %s", configurationKey)
}
p.configurations[configurationKey] = configurationPayload
return nil
}

// GetConfigurations returns the raw configuration map.
func (p *Pool) GetConfigurations() map[string]interface{} {
return p.configurations
}

// GetInstance returns the singleton Pool
func GetInstance() *Pool {
return instance
}
25 changes: 25 additions & 0 deletions pkg/config/pool_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package config_test

import (
"fmt"
"github.com/redhat-nfvpe/test-network-function/pkg/config"
"github.com/stretchr/testify/assert"
"testing"
)

func TestGetInstance(t *testing.T) {
assert.NotNil(t, config.GetInstance())
}

// Also tests GetConfigurations
func TestPool_RegisterConfiguration(t *testing.T) {
type arbitraryConfig struct {
name string
id int
}
assert.Nil(t, config.GetInstance().RegisterConfiguration("someKey", &arbitraryConfig{}))
assert.Contains(t, config.GetInstance().GetConfigurations(), "someKey")
assert.Equal(t, &arbitraryConfig{}, config.GetInstance().GetConfigurations()["someKey"])
assert.Equal(t, fmt.Errorf("pool already contains a configuration for: someKey"),
config.GetInstance().RegisterConfiguration("someKey", &arbitraryConfig{}))
}
38 changes: 38 additions & 0 deletions pkg/junit/convert.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package junit

import (
"bytes"
j "encoding/json"
xj "github.com/basgys/goxml2json"
"os"
)

// ExportJUnitAsJSON attempts to read a JUnit XML file and converts it to a generic JSON map.
func ExportJUnitAsJSON(junitFilename string) (map[string]interface{}, error) {
xmlReader, err := os.Open(junitFilename)
// An error is encountered reading the file.
if err != nil {
return nil, err
}

junitJSONBuffer, err := xj.Convert(xmlReader)
// An error is encountered translating from XML to JSON.
if err != nil {
return nil, err
}

jsonMap, err := convertJSONBytesToMap(junitJSONBuffer)
// An error is encountered unmarshalling the data.
if err != nil {
return nil, err
}

return jsonMap, err
}

// convertJSONBytesToMap is a utility function to convert a bytes.Buffer to a generic JSON map.
func convertJSONBytesToMap(junitJSONBuffer *bytes.Buffer) (map[string]interface{}, error) {
jsonMap := make(map[string]interface{})
err := j.Unmarshal(junitJSONBuffer.Bytes(), &jsonMap)
return jsonMap, err
}
4 changes: 4 additions & 0 deletions pkg/junit/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/*
Package junit provides utility conversion methods for encoding JUnit XML results to generic JSON.
*/
package junit
41 changes: 0 additions & 41 deletions test-network-function/configuration/configuration.go

This file was deleted.

0 comments on commit 8ad1ced

Please sign in to comment.