Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Introduce new npmExecuteTests step #5124

Open
wants to merge 43 commits into
base: master
Choose a base branch
from

Conversation

phgermanov
Copy link
Contributor

Changes

  • Tests
  • Documentation
    ADR

@phgermanov phgermanov requested a review from a team as a code owner October 1, 2024 13:05
- PARAMETERS
- STAGES
- STEPS
default: "npm install"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use npm clean-install

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

- STAGES
- STEPS
mandatory: true
default: "wdi5"
Copy link
Member

@CCFenner CCFenner Oct 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Above we expose the tool npm, here we don't. We should be consistent. default: "npm run wdi5"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

type: e2e
containers:
- name: node
image: node:lts-buster
Copy link
Member

@CCFenner CCFenner Oct 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

buster is a pretty old image. use a more recent one.

https://hub.docker.com/_/node

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines 30 to 36
if (config.credentialsId) {
if (config.wdi5) {
credentials.add([type: 'usernamePassword', id: config.credentialsId, env: ['wdi5_username', 'wdi5_password']])
} else {
credentials.add([type: 'usernamePassword', id: config.credentialsId, env: ['e2e_username', 'e2e_password']])
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should avoid doing such special handling in the groovy. That way we will have no support for it in GHA / ADO.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So should we store those in Vault as well?

Copy link
Contributor Author

@phgermanov phgermanov Oct 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something like:

{
  "appSecrets": {
  	"urls": [
      {
      	"url": "loocalhost:8080",
        "username": "some-username1",
        "password": "some-password1"
      },
      {
      	"url": "loocalhost:8080",
        "username": "some-username2",
        "password": "some-password2"
      }
    ],
    "username": "base-url-username",
    "password": "base-url-password"
  }
}

Comment on lines +141 to +143
if configOptions.OpenFile == nil {
return stepConfig, errors.New("config: open file function not set")
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks unrelated

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is, but it's been missed in some old PR and it's a hard bug to catch, might add it as a new PR

params:
- name: installCommand
type: string
description: Command to be executed for installation. Defaults to `npm ci`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the "defaults to" can be omitted as defaults are printed in the docs.

Comment on lines 52 to 68
- name: onlyRunInProductiveBranch
type: bool
default: false
description: Boolean to indicate whether the step should only be executed in the productive branch or not.
scope:
- PARAMETERS
- STAGES
- STEPS
- name: productiveBranch
type: string
default: "main"
description: The branch used as productive branch.
scope:
- GENERAL
- PARAMETERS
- STAGES
- STEPS
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is that really needed? I would not make a simple step aware of where it's running. This should be part of the pipeline I would say.

resources/metadata/npmExecuteTests.yaml Show resolved Hide resolved
- name: reports
type: reports
params:
- filePattern: "**/e2e-results.xml"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a typical file pattern for WDI5?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think you can provide report with wdi5

resources/metadata/npmExecuteTests.yaml Outdated Show resolved Hide resolved
- STEPS
mandatory: true
default: "npm run wdi5"
- name: appSecrets
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Name is misleading as it also contains the URLs

resources/metadata/npmExecuteTests.yaml Show resolved Hide resolved
Comment on lines 93 to 96
prefix := "e2e"
if wdi5 {
prefix = "wdi5"
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about leaving this to the user by exposing a credentialEnvVarPrefix parameter?

log.Entry().Infof("Running end to end tests for URL: %s", url)

// Execute the npm script
options := "--baseUrl=" + url
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this is tool specific and should be configurable or maybe expose as an env var as well?


username := config.AppSecrets["username"].(string)
password := config.AppSecrets["password"].(string)
credentialsToEnv(username, password, isWdi5)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are empty credentials working here..?

Comment on lines 34 to 44
if ok {
for _, urlRaw := range urlsRaw {
urlMap := urlRaw.(map[string]interface{})
url := urlMap["url"].(string)
appURLs[url] = AppURL{
URL: url,
Username: urlMap["username"].(string),
Password: urlMap["password"].(string),
}
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can handle the single url case with the collection as well.

Suggested change
if ok {
for _, urlRaw := range urlsRaw {
urlMap := urlRaw.(map[string]interface{})
url := urlMap["url"].(string)
appURLs[url] = AppURL{
URL: url,
Username: urlMap["username"].(string),
Password: urlMap["password"].(string),
}
}
}
if ok {
for _, urlRaw := range urlsRaw {
urlMap := urlRaw.(map[string]interface{})
url := urlMap["url"].(string)
appURLs[url] = AppURL{
URL: url,
Username: urlMap["username"].(string),
Password: urlMap["password"].(string),
}
}
} else {
appURLs[url] = AppURL{
URL: config.BaseURL,
}
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this complicates it a bit

for _, urlRaw := range urlsRaw {
urlMap := urlRaw.(map[string]interface{})
url := urlMap["url"].(string)
appURLs[url] = AppURL{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The key is not used at all, so this could also be a list of AppUrL.

}

func runNpmExecuteTests(config *npmExecuteTestsOptions, c command.ExecRunner) error {
type AppURL struct {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
type AppURL struct {
type AppUnderTest struct {

Copy link

sonarcloud bot commented Oct 23, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants