This repository has been archived by the owner on Aug 26, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
1 parent
560cfdf
commit 8ad1ced
Showing
24 changed files
with
667 additions
and
111 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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
claim.json | ||
.idea | ||
vendor | ||
*.test | ||
|
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
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
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,4 @@ | ||
/* | ||
Package config provides a config pool. Configurations registered with the pool are automatically included in the claim. | ||
*/ | ||
package config |
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 @@ | ||
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 | ||
} |
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,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{})) | ||
} |
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,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 | ||
} |
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,4 @@ | ||
/* | ||
Package junit provides utility conversion methods for encoding JUnit XML results to generic JSON. | ||
*/ | ||
package junit |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.