-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: k4yt3x <[email protected]>
- Loading branch information
Showing
10 changed files
with
549 additions
and
173 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
package main | ||
|
||
import ( | ||
"errors" | ||
"testing" | ||
) | ||
|
||
func TestValidateGlobalConfig_Success(t *testing.T) { | ||
// Arrange | ||
globalConfig := GlobalConfig{ | ||
Projects: []ProjectConfig{ | ||
{Path: "/home/user/test", ProjectAccessToken: "glpat-ABCDEFGHIJKLMNOPQRST"}, | ||
Check failure Code scanning / SonarCloud GitLab tokens should not be disclosed High test
Make sure this GitLab token gets revoked, changed, and removed from the code. See more on SonarCloud
|
||
}, | ||
LanguagesConfig: map[string]LanguageConfig{"Go": {}}, | ||
GpgKeyPath: "/home/user/.gnupg/autobump.asc", | ||
GitLabAccessToken: "glpat-ABCDEFGHIJKLMNOPQRST", | ||
Check failure Code scanning / SonarCloud GitLab tokens should not be disclosed High test
Make sure this GitLab token gets revoked, changed, and removed from the code. See more on SonarCloud
|
||
} | ||
|
||
// Act | ||
err := validateGlobalConfig(&globalConfig, false) | ||
// Assert | ||
if err != nil { | ||
t.Errorf("expected no error, got %v", err) | ||
} | ||
} | ||
|
||
func TestValidateGlobalConfig_MissingProjectsInBatchMode(t *testing.T) { | ||
// Arrange | ||
globalConfig := GlobalConfig{ | ||
LanguagesConfig: map[string]LanguageConfig{"Go": {}}, | ||
} | ||
|
||
// Act | ||
err := validateGlobalConfig(&globalConfig, true) | ||
|
||
// Assert | ||
if !errors.Is(err, ErrConfigKeyMissingError) { | ||
t.Errorf("expected error %v, got %v", ErrConfigKeyMissingError, err) | ||
} | ||
} | ||
|
||
func TestValidateGlobalConfig_MissingProjectPath(t *testing.T) { | ||
// Arrange | ||
globalConfig := GlobalConfig{ | ||
Projects: []ProjectConfig{ | ||
{Path: "", ProjectAccessToken: "token1"}, | ||
}, | ||
LanguagesConfig: map[string]LanguageConfig{"Go": {}}, | ||
} | ||
|
||
// Act | ||
err := validateGlobalConfig(&globalConfig, false) | ||
|
||
// Assert | ||
if !errors.Is(err, ErrConfigKeyMissingError) { | ||
t.Errorf("expected error %v, got %v", ErrConfigKeyMissingError, err) | ||
} | ||
} | ||
|
||
func TestValidateGlobalConfig_MissingProjectAccessTokenInBatchMode(t *testing.T) { | ||
// Arrange | ||
globalConfig := GlobalConfig{ | ||
Projects: []ProjectConfig{ | ||
{Path: "some/path", ProjectAccessToken: ""}, | ||
}, | ||
LanguagesConfig: map[string]LanguageConfig{"Go": {}}, | ||
GitLabAccessToken: "", | ||
} | ||
|
||
// Act | ||
err := validateGlobalConfig(&globalConfig, true) | ||
|
||
// Assert | ||
if !errors.Is(err, ErrConfigKeyMissingError) { | ||
t.Errorf("expected error %v, got %v", ErrConfigKeyMissingError, err) | ||
} | ||
} | ||
|
||
func TestValidateGlobalConfig_MissingLanguagesConfig(t *testing.T) { | ||
// Arrange | ||
globalConfig := GlobalConfig{ | ||
Projects: []ProjectConfig{ | ||
{Path: "some/path", ProjectAccessToken: "token1"}, | ||
}, | ||
LanguagesConfig: nil, | ||
} | ||
|
||
// Act | ||
err := validateGlobalConfig(&globalConfig, false) | ||
|
||
// Assert | ||
if !errors.Is(err, ErrLanguagesKeyMissingError) { | ||
t.Errorf("expected error %v, got %v", ErrLanguagesKeyMissingError, err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.