Skip to content

Commit

Permalink
fix remark for version mismatch (#234)
Browse files Browse the repository at this point in the history
* fix remark for version mismatch

* fix linting issue
  • Loading branch information
VikrantKS authored Aug 5, 2022
1 parent d99e764 commit 172fe02
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 33 deletions.
60 changes: 32 additions & 28 deletions pkg/global/nucleusconstants.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,34 +10,35 @@ var TestServer string

// All constant related to nucleus
const (
CoverageManifestFileName = "manifest.json"
HomeDir = "/home/nucleus"
WorkspaceCacheDir = "/workspace-cache"
RepoDir = HomeDir + "/repo"
CodeCoverageDir = RepoDir + "/coverage"
RepoCacheDir = RepoDir + "/__tas"
DefaultAPITimeout = 45 * time.Second
DefaultGitCloneTimeout = 30 * time.Minute
SamplingTime = 5 * time.Millisecond
RepoSecretPath = "/vault/secrets/reposecrets"
OauthSecretPath = "/vault/secrets/oauth"
NeuronRemoteHost = "http://neuron-service.phoenix.svc.cluster.local"
BlockTestFileLocation = "/tmp/blocktests.json"
SecretRegex = `\${{\s*secrets\.(.*?)\s*}}`
ExecutionResultChunkSize = 50
TestLocatorsDelimiter = "#TAS#"
ExpiryDelta = 15 * time.Minute
NewTASVersion = 2
ModulePath = "MODULE_PATH"
PackageJSON = "package.json"
SubModuleName = "SUBMODULE_NAME"
ArgPattern = "--pattern"
ArgConfig = "--config"
ArgDiff = "--diff"
ArgCommand = "--command"
ArgLocator = "--locator-file"
ArgFrameworVersion = "--frameworkVersion"
DefaultTASVersion = "1.0.0"
CoverageManifestFileName = "manifest.json"
HomeDir = "/home/nucleus"
WorkspaceCacheDir = "/workspace-cache"
RepoDir = HomeDir + "/repo"
CodeCoverageDir = RepoDir + "/coverage"
RepoCacheDir = RepoDir + "/__tas"
DefaultAPITimeout = 45 * time.Second
DefaultGitCloneTimeout = 30 * time.Minute
SamplingTime = 5 * time.Millisecond
RepoSecretPath = "/vault/secrets/reposecrets"
OauthSecretPath = "/vault/secrets/oauth"
NeuronRemoteHost = "http://neuron-service.phoenix.svc.cluster.local"
BlockTestFileLocation = "/tmp/blocktests.json"
SecretRegex = `\${{\s*secrets\.(.*?)\s*}}` // nolint: gosec
ExecutionResultChunkSize = 50
TestLocatorsDelimiter = "#TAS#"
ExpiryDelta = 15 * time.Minute
NewTASVersion = 2
ModulePath = "MODULE_PATH"
PackageJSON = "package.json"
SubModuleName = "SUBMODULE_NAME"
ArgPattern = "--pattern"
ArgConfig = "--config"
ArgDiff = "--diff"
ArgCommand = "--command"
ArgLocator = "--locator-file"
ArgFrameworVersion = "--frameworkVersion"
DefaultTASVersion = "1.0.0"
TASYmlConfigurationDocLink = "https://www.lambdatest.com/support/docs/tas-configuring-tas-yml"
)

// FrameworkRunnerMap is map of framework with there respective runner location
Expand Down Expand Up @@ -74,3 +75,6 @@ var FrameworkLanguageMap = map[string]string{
"golang": "golang",
"junit": "java",
}

// ValidYMLVersions defines all valid yml version
var ValidYMLVersions = []int{1, 2}
27 changes: 27 additions & 0 deletions pkg/tasconfigdownloader/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,19 @@ package tasconfigdownloader

import (
"context"
"errors"
"fmt"
"os"

"github.com/LambdaTest/test-at-scale/pkg/core"
"github.com/LambdaTest/test-at-scale/pkg/gitmanager"
"github.com/LambdaTest/test-at-scale/pkg/global"
"github.com/LambdaTest/test-at-scale/pkg/lumber"
"github.com/LambdaTest/test-at-scale/pkg/tasconfigmanager"
)

const ymlVersionMismtachRemarks = "the yml structure is invalid, please check the TAS yml documentation : %s"

type TASConfigDownloader struct {
logger lumber.Logger
gitmanager core.GitManager
Expand Down Expand Up @@ -40,6 +45,12 @@ func (t *TASConfigDownloader) GetTASConfig(ctx context.Context, gitProvider, com

tasConfig, err := t.tasconfigmanager.LoadAndValidate(ctx, version, ymlPath, eventType, licenseTier, filePath)
if err != nil {
if supportedVersion := t.checkYmlValidityForOtherVersion(ctx, version, ymlPath, eventType,
licenseTier, filePath); supportedVersion != -1 {
errMsg := fmt.Sprintf(ymlVersionMismtachRemarks, global.TASYmlConfigurationDocLink)
t.logger.Errorf("error while parsing yml for commitID %s, error: %s", commitID, errMsg)
return nil, errors.New(errMsg)
}
t.logger.Errorf("error while parsing yml for commitID %s error %v", commitID, err)
return nil, err
}
Expand All @@ -49,3 +60,19 @@ func (t *TASConfigDownloader) GetTASConfig(ctx context.Context, gitProvider, com
}
return &core.TASConfigDownloaderOutput{Version: version, TASConfig: tasConfig}, nil
}

func (t *TASConfigDownloader) checkYmlValidityForOtherVersion(ctx context.Context,
version int,
ymlPath string,
eventType core.EventType,
licenseTier core.Tier, filePath string) int {
for _, supportedVersion := range global.ValidYMLVersions {
if version == supportedVersion {
continue
}
if _, err := t.tasconfigmanager.LoadAndValidate(ctx, supportedVersion, ymlPath, eventType, licenseTier, filePath); err == nil {
return supportedVersion
}
}
return -1
}
4 changes: 2 additions & 2 deletions pkg/tasconfigmanager/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,8 @@ func (tc *tasConfigManager) GetVersion(path string) (int, error) {
}
versionYml, err := utils.GetVersion(yamlFile)
if err != nil {
tc.logger.Errorf("Error while reading tas yml version error %v", err)
return 0, errs.New("Error while reading tas yml version")
tc.logger.Errorf("error while reading tas yml version : %v", err)
return 0, err
}
return versionYml, nil
}
Expand Down
8 changes: 6 additions & 2 deletions pkg/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,11 @@ func GetVersion(ymlContent []byte) (int, error) {
}
majorVersion := strings.Split(tasVersion.Version, ".")[0]

return strconv.Atoi(majorVersion)
version, err := strconv.Atoi(majorVersion)
if err != nil {
return version, errs.New("error while parsing version for tas yml")
}
return version, err
}

// ValidateStructTASYmlV2 validates tas configuration file
Expand Down Expand Up @@ -306,6 +310,6 @@ func ValidateStructTASYml(ctx context.Context, ymlContent []byte, ymlFilename st
case v2:
return ValidateStructTASYmlV2(ctx, ymlContent, ymlFilename)
default:
return nil, fmt.Errorf("")
return nil, fmt.Errorf("version %d is not supported ", version)
}
}
2 changes: 1 addition & 1 deletion pkg/utils/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ func TestGetVersion(t *testing.T) {
{
"Test with invalid version type",
"testutils/testdata/tasyml/invalidVersion.yml",
fmt.Errorf("strconv.Atoi: parsing \"a\": invalid syntax"),
fmt.Errorf("error while parsing version for tas yml"),
0,
},
{
Expand Down

0 comments on commit 172fe02

Please sign in to comment.