Skip to content

Commit 172fe02

Browse files
authored
fix remark for version mismatch (#234)
* fix remark for version mismatch * fix linting issue
1 parent d99e764 commit 172fe02

File tree

5 files changed

+68
-33
lines changed

5 files changed

+68
-33
lines changed

pkg/global/nucleusconstants.go

Lines changed: 32 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -10,34 +10,35 @@ var TestServer string
1010

1111
// All constant related to nucleus
1212
const (
13-
CoverageManifestFileName = "manifest.json"
14-
HomeDir = "/home/nucleus"
15-
WorkspaceCacheDir = "/workspace-cache"
16-
RepoDir = HomeDir + "/repo"
17-
CodeCoverageDir = RepoDir + "/coverage"
18-
RepoCacheDir = RepoDir + "/__tas"
19-
DefaultAPITimeout = 45 * time.Second
20-
DefaultGitCloneTimeout = 30 * time.Minute
21-
SamplingTime = 5 * time.Millisecond
22-
RepoSecretPath = "/vault/secrets/reposecrets"
23-
OauthSecretPath = "/vault/secrets/oauth"
24-
NeuronRemoteHost = "http://neuron-service.phoenix.svc.cluster.local"
25-
BlockTestFileLocation = "/tmp/blocktests.json"
26-
SecretRegex = `\${{\s*secrets\.(.*?)\s*}}`
27-
ExecutionResultChunkSize = 50
28-
TestLocatorsDelimiter = "#TAS#"
29-
ExpiryDelta = 15 * time.Minute
30-
NewTASVersion = 2
31-
ModulePath = "MODULE_PATH"
32-
PackageJSON = "package.json"
33-
SubModuleName = "SUBMODULE_NAME"
34-
ArgPattern = "--pattern"
35-
ArgConfig = "--config"
36-
ArgDiff = "--diff"
37-
ArgCommand = "--command"
38-
ArgLocator = "--locator-file"
39-
ArgFrameworVersion = "--frameworkVersion"
40-
DefaultTASVersion = "1.0.0"
13+
CoverageManifestFileName = "manifest.json"
14+
HomeDir = "/home/nucleus"
15+
WorkspaceCacheDir = "/workspace-cache"
16+
RepoDir = HomeDir + "/repo"
17+
CodeCoverageDir = RepoDir + "/coverage"
18+
RepoCacheDir = RepoDir + "/__tas"
19+
DefaultAPITimeout = 45 * time.Second
20+
DefaultGitCloneTimeout = 30 * time.Minute
21+
SamplingTime = 5 * time.Millisecond
22+
RepoSecretPath = "/vault/secrets/reposecrets"
23+
OauthSecretPath = "/vault/secrets/oauth"
24+
NeuronRemoteHost = "http://neuron-service.phoenix.svc.cluster.local"
25+
BlockTestFileLocation = "/tmp/blocktests.json"
26+
SecretRegex = `\${{\s*secrets\.(.*?)\s*}}` // nolint: gosec
27+
ExecutionResultChunkSize = 50
28+
TestLocatorsDelimiter = "#TAS#"
29+
ExpiryDelta = 15 * time.Minute
30+
NewTASVersion = 2
31+
ModulePath = "MODULE_PATH"
32+
PackageJSON = "package.json"
33+
SubModuleName = "SUBMODULE_NAME"
34+
ArgPattern = "--pattern"
35+
ArgConfig = "--config"
36+
ArgDiff = "--diff"
37+
ArgCommand = "--command"
38+
ArgLocator = "--locator-file"
39+
ArgFrameworVersion = "--frameworkVersion"
40+
DefaultTASVersion = "1.0.0"
41+
TASYmlConfigurationDocLink = "https://www.lambdatest.com/support/docs/tas-configuring-tas-yml"
4142
)
4243

4344
// FrameworkRunnerMap is map of framework with there respective runner location
@@ -74,3 +75,6 @@ var FrameworkLanguageMap = map[string]string{
7475
"golang": "golang",
7576
"junit": "java",
7677
}
78+
79+
// ValidYMLVersions defines all valid yml version
80+
var ValidYMLVersions = []int{1, 2}

pkg/tasconfigdownloader/setup.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,19 @@ package tasconfigdownloader
22

33
import (
44
"context"
5+
"errors"
6+
"fmt"
57
"os"
68

79
"github.com/LambdaTest/test-at-scale/pkg/core"
810
"github.com/LambdaTest/test-at-scale/pkg/gitmanager"
11+
"github.com/LambdaTest/test-at-scale/pkg/global"
912
"github.com/LambdaTest/test-at-scale/pkg/lumber"
1013
"github.com/LambdaTest/test-at-scale/pkg/tasconfigmanager"
1114
)
1215

16+
const ymlVersionMismtachRemarks = "the yml structure is invalid, please check the TAS yml documentation : %s"
17+
1318
type TASConfigDownloader struct {
1419
logger lumber.Logger
1520
gitmanager core.GitManager
@@ -40,6 +45,12 @@ func (t *TASConfigDownloader) GetTASConfig(ctx context.Context, gitProvider, com
4045

4146
tasConfig, err := t.tasconfigmanager.LoadAndValidate(ctx, version, ymlPath, eventType, licenseTier, filePath)
4247
if err != nil {
48+
if supportedVersion := t.checkYmlValidityForOtherVersion(ctx, version, ymlPath, eventType,
49+
licenseTier, filePath); supportedVersion != -1 {
50+
errMsg := fmt.Sprintf(ymlVersionMismtachRemarks, global.TASYmlConfigurationDocLink)
51+
t.logger.Errorf("error while parsing yml for commitID %s, error: %s", commitID, errMsg)
52+
return nil, errors.New(errMsg)
53+
}
4354
t.logger.Errorf("error while parsing yml for commitID %s error %v", commitID, err)
4455
return nil, err
4556
}
@@ -49,3 +60,19 @@ func (t *TASConfigDownloader) GetTASConfig(ctx context.Context, gitProvider, com
4960
}
5061
return &core.TASConfigDownloaderOutput{Version: version, TASConfig: tasConfig}, nil
5162
}
63+
64+
func (t *TASConfigDownloader) checkYmlValidityForOtherVersion(ctx context.Context,
65+
version int,
66+
ymlPath string,
67+
eventType core.EventType,
68+
licenseTier core.Tier, filePath string) int {
69+
for _, supportedVersion := range global.ValidYMLVersions {
70+
if version == supportedVersion {
71+
continue
72+
}
73+
if _, err := t.tasconfigmanager.LoadAndValidate(ctx, supportedVersion, ymlPath, eventType, licenseTier, filePath); err == nil {
74+
return supportedVersion
75+
}
76+
}
77+
return -1
78+
}

pkg/tasconfigmanager/setup.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,8 @@ func (tc *tasConfigManager) GetVersion(path string) (int, error) {
160160
}
161161
versionYml, err := utils.GetVersion(yamlFile)
162162
if err != nil {
163-
tc.logger.Errorf("Error while reading tas yml version error %v", err)
164-
return 0, errs.New("Error while reading tas yml version")
163+
tc.logger.Errorf("error while reading tas yml version : %v", err)
164+
return 0, err
165165
}
166166
return versionYml, nil
167167
}

pkg/utils/utils.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,11 @@ func GetVersion(ymlContent []byte) (int, error) {
166166
}
167167
majorVersion := strings.Split(tasVersion.Version, ".")[0]
168168

169-
return strconv.Atoi(majorVersion)
169+
version, err := strconv.Atoi(majorVersion)
170+
if err != nil {
171+
return version, errs.New("error while parsing version for tas yml")
172+
}
173+
return version, err
170174
}
171175

172176
// ValidateStructTASYmlV2 validates tas configuration file
@@ -306,6 +310,6 @@ func ValidateStructTASYml(ctx context.Context, ymlContent []byte, ymlFilename st
306310
case v2:
307311
return ValidateStructTASYmlV2(ctx, ymlContent, ymlFilename)
308312
default:
309-
return nil, fmt.Errorf("")
313+
return nil, fmt.Errorf("version %d is not supported ", version)
310314
}
311315
}

pkg/utils/utils_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ func TestGetVersion(t *testing.T) {
322322
{
323323
"Test with invalid version type",
324324
"testutils/testdata/tasyml/invalidVersion.yml",
325-
fmt.Errorf("strconv.Atoi: parsing \"a\": invalid syntax"),
325+
fmt.Errorf("error while parsing version for tas yml"),
326326
0,
327327
},
328328
{

0 commit comments

Comments
 (0)