Skip to content

Commit

Permalink
claim file: move data structs and handlers to the CNF repo (#1603)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmontesi authored Nov 10, 2023
1 parent 4429fa1 commit 78628ae
Show file tree
Hide file tree
Showing 29 changed files with 3,077 additions and 81 deletions.
2 changes: 1 addition & 1 deletion cmd/tnf/claim/add/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (

log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/test-network-function/cnf-certification-test/pkg/claim"
"github.com/test-network-function/cnf-certification-test/pkg/junit"
"github.com/test-network-function/test-network-function-claim/pkg/claim"
)

var (
Expand Down
7 changes: 3 additions & 4 deletions cmd/tnf/claim/add/add_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/test-network-function/test-network-function-claim/pkg/claim"
"github.com/test-network-function/cnf-certification-test/pkg/claim"
)

func TestReadClaim(t *testing.T) {
Expand All @@ -17,9 +17,8 @@ func TestReadClaim(t *testing.T) {
expectedClaimRoot: &claim.Root{
Claim: &claim.Claim{
Versions: &claim.Versions{
K8s: "1.23.1",
Tnf: "0.3.1",
ClaimFormat: "v0.0.1",
K8s: "1.23.1",
Tnf: "0.3.1",
},
Metadata: &claim.Metadata{
EndTime: "1:33:00",
Expand Down
2 changes: 1 addition & 1 deletion cmd/tnf/claim/compare/versions/versions.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"log"

"github.com/test-network-function/cnf-certification-test/cmd/tnf/claim/compare/diff"
officialClaimScheme "github.com/test-network-function/test-network-function-claim/pkg/claim"
officialClaimScheme "github.com/test-network-function/cnf-certification-test/pkg/claim"
)

type DiffReport struct {
Expand Down
8 changes: 1 addition & 7 deletions cmd/tnf/claim/compare/versions/versions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (

"github.com/stretchr/testify/assert"
"github.com/test-network-function/cnf-certification-test/cmd/tnf/claim/compare/diff"
officialClaimScheme "github.com/test-network-function/test-network-function-claim/pkg/claim"
officialClaimScheme "github.com/test-network-function/cnf-certification-test/pkg/claim"
)

func TestCompare(t *testing.T) {
Expand All @@ -30,15 +30,13 @@ func TestCompare(t *testing.T) {
name: "matching versions",
args: args{
claim1Versions: &officialClaimScheme.Versions{
ClaimFormat: "1",
K8s: "22",
OcClient: "333",
Ocp: "4444",
Tnf: "55555",
TnfGitCommit: "666666",
},
claim2Versions: &officialClaimScheme.Versions{
ClaimFormat: "1",
K8s: "22",
OcClient: "333",
Ocp: "4444",
Expand All @@ -52,15 +50,13 @@ func TestCompare(t *testing.T) {
name: "non matching versions 1",
args: args{
claim1Versions: &officialClaimScheme.Versions{
ClaimFormat: "1",
K8s: "22AAA",
OcClient: "333",
Ocp: "4444",
Tnf: "55555",
TnfGitCommit: "666666",
},
claim2Versions: &officialClaimScheme.Versions{
ClaimFormat: "1",
K8s: "22",
OcClient: "333",
Ocp: "4444",
Expand All @@ -83,15 +79,13 @@ func TestCompare(t *testing.T) {
name: "non matching versions 2",
args: args{
claim1Versions: &officialClaimScheme.Versions{
ClaimFormat: "1",
K8s: "22AAA",
OcClient: "333",
Ocp: "4444",
Tnf: "55555",
TnfGitCommit: "666666",
},
claim2Versions: &officialClaimScheme.Versions{
ClaimFormat: "1",
K8s: "22",
OcClient: "333",
Ocp: "4444",
Expand Down
8 changes: 1 addition & 7 deletions cmd/tnf/claim/show/csv/csv.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/spf13/cobra"
"github.com/test-network-function/cnf-certification-test/cmd/tnf/pkg/claim"
"github.com/test-network-function/cnf-certification-test/cnf-certification-test/identifiers"
claimschema "github.com/test-network-function/test-network-function-claim/pkg/claim"
claimschema "github.com/test-network-function/cnf-certification-test/pkg/claim"
)

var (
Expand Down Expand Up @@ -92,12 +92,6 @@ func dumpCsv(_ *cobra.Command, _ []string) error {
return fmt.Errorf("failed to parse claim file %s: %v", claimFilePathFlag, err)
}

// Check claim format version
err = claim.CheckVersion(claimScheme.Claim.Versions.ClaimFormat)
if err != nil {
return err
}

// loads the mapping between CNF name and type
CNFTypeMap, err := loadCNFTypeMap(CNFListFilePathFlag)
if err != nil {
Expand Down
6 changes: 0 additions & 6 deletions cmd/tnf/claim/show/failures/failures.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,12 +290,6 @@ func showFailures(_ *cobra.Command, _ []string) error {
return fmt.Errorf("failed to parse claim file %s: %v", claimFilePathFlag, err)
}

// Check claim format version
err = claim.CheckVersion(claimScheme.Claim.Versions.ClaimFormat)
if err != nil {
return err
}

// Order test case results by test suite, using a helper map.
resultsByTestSuite := map[string][]*claim.TestCaseResult{}
for id := range claimScheme.Claim.Results {
Expand Down
2 changes: 1 addition & 1 deletion cmd/tnf/generate/catalog/catalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
"github.com/sirupsen/logrus"
"github.com/test-network-function/cnf-certification-test/cnf-certification-test/identifiers"
"github.com/test-network-function/cnf-certification-test/pkg/arrayhelper"
"github.com/test-network-function/test-network-function-claim/pkg/claim"
"github.com/test-network-function/cnf-certification-test/pkg/claim"

"github.com/spf13/cobra"
)
Expand Down
2 changes: 1 addition & 1 deletion cmd/tnf/generate/catalog/catalog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (

"github.com/stretchr/testify/assert"
"github.com/test-network-function/cnf-certification-test/pkg/arrayhelper"
"github.com/test-network-function/test-network-function-claim/pkg/claim"
"github.com/test-network-function/cnf-certification-test/pkg/claim"
)

func TestNewCommand(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion cmd/tnf/generate/qe_coverage/qe_coverage.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

"github.com/spf13/cobra"
"github.com/test-network-function/cnf-certification-test/cnf-certification-test/identifiers"
"github.com/test-network-function/test-network-function-claim/pkg/claim"
"github.com/test-network-function/cnf-certification-test/pkg/claim"
)

type TestCoverageSummaryReport struct {
Expand Down
2 changes: 1 addition & 1 deletion cmd/tnf/generate/qe_coverage/qe_coverage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/test-network-function/test-network-function-claim/pkg/claim"
"github.com/test-network-function/cnf-certification-test/pkg/claim"
)

type catalogEntry struct {
Expand Down
2 changes: 1 addition & 1 deletion cmd/tnf/pkg/claim/claim.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"os"

"github.com/Masterminds/semver/v3"
officialClaimScheme "github.com/test-network-function/test-network-function-claim/pkg/claim"
officialClaimScheme "github.com/test-network-function/cnf-certification-test/pkg/claim"
)

const (
Expand Down
2 changes: 1 addition & 1 deletion cnf-certification-test/identifiers/identifiers.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"strings"

"github.com/test-network-function/cnf-certification-test/cnf-certification-test/common"
"github.com/test-network-function/test-network-function-claim/pkg/claim"
"github.com/test-network-function/cnf-certification-test/pkg/claim"
)

// shared description text
Expand Down
2 changes: 1 addition & 1 deletion cnf-certification-test/identifiers/identifiers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/test-network-function/cnf-certification-test/pkg/claim"
"github.com/test-network-function/cnf-certification-test/pkg/stringhelper"
"github.com/test-network-function/test-network-function-claim/pkg/claim"
)

func TestGetGinkgoTestIDAndLabels(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion cnf-certification-test/results/results.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"github.com/test-network-function/cnf-certification-test/cnf-certification-test/identifiers"
"github.com/test-network-function/cnf-certification-test/pkg/testhelper"

"github.com/test-network-function/test-network-function-claim/pkg/claim"
"github.com/test-network-function/cnf-certification-test/pkg/claim"
)

const (
Expand Down
52 changes: 7 additions & 45 deletions cnf-certification-test/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ import (
"github.com/onsi/ginkgo/v2"
log "github.com/sirupsen/logrus"
"github.com/test-network-function/cnf-certification-test/cnf-certification-test/results"
"github.com/test-network-function/cnf-certification-test/pkg/claim"
"github.com/test-network-function/cnf-certification-test/pkg/claimhelper"
"github.com/test-network-function/cnf-certification-test/pkg/collector"
"github.com/test-network-function/cnf-certification-test/pkg/loghelper"
"github.com/test-network-function/cnf-certification-test/pkg/provider"
"github.com/test-network-function/cnf-certification-test/pkg/testhelper"
"github.com/test-network-function/test-network-function-claim/pkg/claim"

_ "github.com/test-network-function/cnf-certification-test/cnf-certification-test/accesscontrol"
_ "github.com/test-network-function/cnf-certification-test/cnf-certification-test/certification"
Expand All @@ -54,8 +54,8 @@ import (
_ "github.com/test-network-function/cnf-certification-test/cnf-certification-test/preflight"
"github.com/test-network-function/cnf-certification-test/cnf-certification-test/webserver"
"github.com/test-network-function/cnf-certification-test/internal/clientsholder"
"github.com/test-network-function/cnf-certification-test/internal/version"
"github.com/test-network-function/cnf-certification-test/pkg/configuration"
"github.com/test-network-function/cnf-certification-test/pkg/diagnostics"
)

const (
Expand All @@ -71,23 +71,9 @@ const (
)

var (
claimPath *string
junitPath *string
// GitCommit is the latest commit in the current git branch
GitCommit string
// GitRelease is the list of tags (if any) applied to the latest commit
// in the current branch
GitRelease string
// GitPreviousRelease is the last release at the date of the latest commit
// in the current branch
GitPreviousRelease string
// gitDisplayRelease is a string used to hold the text to display
// the version on screen and in the claim file
gitDisplayRelease string
// ClaimFormat is the current version for the claim file format to be produced by the TNF test suite.
// A client decoding this claim file must support decoding its specific version.
ClaimFormatVersion string
serverMode *bool
claimPath *string
junitPath *string
serverMode *bool
)

func init() {
Expand Down Expand Up @@ -126,18 +112,6 @@ func getK8sClientsConfigFileNames() []string {
return fileNames
}

// getGitVersion returns the git display version: the latest previously released
// build in case this build is not released. Otherwise display the build version
func getGitVersion() string {
if GitRelease == "" {
gitDisplayRelease = "Unreleased build post " + GitPreviousRelease
} else {
gitDisplayRelease = GitRelease
}

return gitDisplayRelease + " ( " + GitCommit + " )"
}

func PreRun(t *testing.T) (claimData *claim.Claim, claimRoot *claim.Root) {
// When running unit tests, skip the suite
if os.Getenv("UNIT_TEST") != "" {
Expand All @@ -154,8 +128,7 @@ func PreRun(t *testing.T) (claimData *claim.Claim, claimRoot *claim.Root) {
setLogLevel()

ginkgoConfig, _ := ginkgo.GinkgoConfiguration()
log.Infof("TNF Version : %v", getGitVersion())
log.Infof("Claim Format Version: %s", ClaimFormatVersion)
log.Infof("TNF Version : %v", version.GetGitVersion())
log.Infof("Ginkgo Version : %v", ginkgo.GINKGO_VERSION)
log.Infof("Labels filter : %v", ginkgoConfig.LabelFilter)
log.Infof("run test with webserver : %v", *serverMode)
Expand All @@ -167,7 +140,7 @@ func PreRun(t *testing.T) (claimData *claim.Claim, claimRoot *claim.Root) {
claimData = claimRoot.Claim
claimData.Configurations = make(map[string]interface{})
claimData.Nodes = make(map[string]interface{})
incorporateVersions(claimData)
claimhelper.IncorporateVersions(claimData)

configurations, err := claimhelper.MarshalConfigurations()
if err != nil {
Expand Down Expand Up @@ -278,17 +251,6 @@ func ContinueRun(diagnosticMode bool, env *provider.TestEnvironment, claimData *
}
}

// incorporateTNFVersion adds the TNF version to the claim.
func incorporateVersions(claimData *claim.Claim) {
claimData.Versions = &claim.Versions{
Tnf: gitDisplayRelease,
TnfGitCommit: GitCommit,
OcClient: diagnostics.GetVersionOcClient(),
Ocp: diagnostics.GetVersionOcp(),
K8s: diagnostics.GetVersionK8s(),
ClaimFormat: ClaimFormatVersion,
}
}
func StartServer() {
server := &http.Server{
Addr: ":8084", // Server address
Expand Down
43 changes: 43 additions & 0 deletions internal/version/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Copyright (C) 2020-2023 Red Hat, Inc.
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this program; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

package version

var (
// GitCommit is the latest commit in the current git branch
GitCommit string
// GitRelease is the list of tags (if any) applied to the latest commit
// in the current branch
GitRelease string
// GitPreviousRelease is the last release at the date of the latest commit
// in the current branch
GitPreviousRelease string
)

// GetGitVersion returns the git display version: the latest previously released
// build in case this build is not released. Otherwise display the build version
func GetGitVersion() string {
// gitDisplayRelease is a string used to hold the text to display
// the version on screen and in the claim file
var gitDisplayRelease string
if GitRelease == "" {
gitDisplayRelease = "Unreleased build post " + GitPreviousRelease
} else {
gitDisplayRelease = GitRelease
}

return gitDisplayRelease + " ( " + GitCommit + " )"
}
Loading

0 comments on commit 78628ae

Please sign in to comment.