Skip to content

Commit

Permalink
Add test + remove extractors logic
Browse files Browse the repository at this point in the history
  • Loading branch information
omerzi committed Jun 29, 2023
1 parent 8b40559 commit d6afe7c
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 124 deletions.
10 changes: 8 additions & 2 deletions commands/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@ type FrogbotCommand interface {
}

func Exec(command FrogbotCommand, name string) (err error) {
// Get frogbotUtils that contains the config, server and VCS client
// Get frogbotUtils that contains the config, server, and VCS client
log.Info("Frogbot version:", utils.FrogbotVersion)
frogbotUtils, err := utils.GetFrogbotUtils()
if err != nil {
return err
}

// Build the server configuration file
previousJfrogHomeDir, currentJFrogHomeDir, err := utils.BuildServerConfigFile(frogbotUtils.ServerDetails)
if err != nil {
Expand All @@ -32,6 +33,7 @@ func Exec(command FrogbotCommand, name string) (err error) {
defer func() {
err = errors.Join(err, os.Setenv(utils.JfrogHomeDirEnv, previousJfrogHomeDir), fileutils.RemoveTempDir(currentJFrogHomeDir))
}()

// Set releases remote repository env if needed
previousReleasesRepoEnv := os.Getenv(coreutils.ReleasesRemoteEnv)
if frogbotUtils.ReleasesRepo != "" {
Expand All @@ -42,16 +44,20 @@ func Exec(command FrogbotCommand, name string) (err error) {
err = errors.Join(err, os.Setenv(coreutils.ReleasesRemoteEnv, previousReleasesRepoEnv))
}()
}

// Send a usage report
usageReportSent := make(chan error)
go utils.ReportUsage(name, frogbotUtils.ServerDetails, usageReportSent)

// Invoke the command interface
log.Info(fmt.Sprintf("Running Frogbot %q command", name))
err = command.Run(frogbotUtils.Repositories, frogbotUtils.Client)

// Wait for a signal, letting us know that the usage reporting is done.
<-usageReportSent

if err == nil {
log.Info(fmt.Sprintf("Frogbot %q command finished successfully ", name))
log.Info(fmt.Sprintf("Frogbot %q command finished successfully", name))
}
return err
}
Expand Down
77 changes: 0 additions & 77 deletions commands/utils/extractors.go

This file was deleted.

45 changes: 0 additions & 45 deletions commands/utils/extractors_test.go

This file was deleted.

43 changes: 43 additions & 0 deletions commands/utils/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"net/http"
"net/http/httptest"
"os"
"path"
"path/filepath"
"strings"
"testing"
Expand Down Expand Up @@ -296,3 +297,45 @@ func TestValidatedBranchName(t *testing.T) {
})
}
}

func TestBuildServerConfigFile(t *testing.T) {
preTestJFrogHome := os.Getenv(JfrogHomeDirEnv)
defer func() {
assert.NoError(t, os.Setenv(JfrogHomeDirEnv, preTestJFrogHome))
}()
assert.NoError(t, os.Setenv(JfrogHomeDirEnv, "path/to/nowhere"))
server := &config.ServerDetails{
Url: "https://myserver.com",
ArtifactoryUrl: "https://myserver.com/artifactory",
DistributionUrl: "https://myserver.co/distribution",
XrayUrl: "https://myserver.com/xray",
MissionControlUrl: "https://myserver.com/missioncontrol",
PipelinesUrl: "https://myserver.com/pipelines",
AccessUrl: "https://myserver.com/access",
AccessToken: "abcdefg1234",
}
expectedConfigurationFile :=
`{
"servers": [
{
"url": "https://myserver.com/",
"artifactoryUrl": "https://myserver.com/artifactory/",
"distributionUrl": "https://myserver.co/distribution/",
"xrayUrl": "https://myserver.com/xray/",
"missionControlUrl": "https://myserver.com/missioncontrol/",
"pipelinesUrl": "https://myserver.com/pipelines/",
"accessUrl": "https://myserver.com/access",
"accessToken": "abcdefg1234",
"serverId": "frogbot",
"isDefault": true
}
],
"version": "6"
}`
previousJFrogHome, currentJFrogHome, err := BuildServerConfigFile(server)
assert.NoError(t, err)
assert.Equal(t, "path/to/nowhere", previousJFrogHome)
actualConfigurationFile, err := os.ReadFile(path.Join(currentJFrogHome, "jfrog-cli.conf.v6"))
assert.NoError(t, err)
assert.Equal(t, expectedConfigurationFile, string(actualConfigurationFile))
}

0 comments on commit d6afe7c

Please sign in to comment.