Skip to content

Commit

Permalink
saving current progress
Browse files Browse the repository at this point in the history
Signed-off-by: k4yt3x <i@k4yt3x.com>
  • Loading branch information
k4yt3x committed Aug 30, 2024
1 parent 8f99d16 commit caaa545
Show file tree
Hide file tree
Showing 7 changed files with 157 additions and 134 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ Exceptions are acceptable depending on the circumstances (critical bug fixes tha

- removed redundant release pipeline

### Fixed

- fixed a typo in authentication method selection

## [2.14.0] - 2024-03-01

### Added
Expand Down
12 changes: 7 additions & 5 deletions cmd/autobump/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,19 @@ package main
import (
"errors"
"testing"

"github.com/go-faker/faker/v4"
)

func TestValidateGlobalConfig_Success(t *testing.T) {
// Arrange
globalConfig := GlobalConfig{

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
Projects: []ProjectConfig{
{Path: "/home/user/test", ProjectAccessToken: "glpat-ABCDEFGHIJKLMNOPQRST"},
{Path: "/home/user/test", ProjectAccessToken: faker.Password()},
},
LanguagesConfig: map[string]LanguageConfig{"Go": {}},

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
GpgKeyPath: "/home/user/.gnupg/autobump.asc",
GitLabAccessToken: "glpat-ABCDEFGHIJKLMNOPQRST",
GitLabAccessToken: faker.Password(),
}

// Act
Expand Down Expand Up @@ -43,7 +45,7 @@ func TestValidateGlobalConfig_MissingProjectPath(t *testing.T) {
// Arrange
globalConfig := GlobalConfig{
Projects: []ProjectConfig{
{Path: "", ProjectAccessToken: "token1"},
{Path: "", ProjectAccessToken: faker.Password()},
},
LanguagesConfig: map[string]LanguageConfig{"Go": {}},
}
Expand All @@ -61,7 +63,7 @@ func TestValidateGlobalConfig_MissingProjectAccessTokenInBatchMode(t *testing.T)
// Arrange
globalConfig := GlobalConfig{
Projects: []ProjectConfig{
{Path: "some/path", ProjectAccessToken: ""},
{Path: faker.Word(), ProjectAccessToken: ""},
},
LanguagesConfig: map[string]LanguageConfig{"Go": {}},
GitLabAccessToken: "",
Expand All @@ -80,7 +82,7 @@ func TestValidateGlobalConfig_MissingLanguagesConfig(t *testing.T) {
// Arrange
globalConfig := GlobalConfig{
Projects: []ProjectConfig{
{Path: "some/path", ProjectAccessToken: "token1"},
{Path: faker.Word(), ProjectAccessToken: faker.Password()},
},
LanguagesConfig: nil,
}
Expand Down
36 changes: 23 additions & 13 deletions cmd/autobump/git_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ package main

import (
"errors"
"fmt"
"math/rand"
"testing"

"github.com/go-faker/faker/v4"
"github.com/go-git/go-billy/v5/memfs"
"github.com/go-git/go-git/v5"
"github.com/go-git/go-git/v5/config"
Expand All @@ -13,15 +16,17 @@ import (

func TestGetAuthMethods_Success(t *testing.T) {

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
// Arrange
gitlabAccessToken := faker.Password()
projectAccessToken := faker.Password()

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
globalConfig := GlobalConfig{
GitLabAccessToken: "glpat-ABCDEFGHIJKLMNOPQRST",
GitLabAccessToken: gitlabAccessToken,
}
projectConfig := ProjectConfig{
ProjectAccessToken: "glpat-ABCDEFGHIJKLMNOPQRST",
ProjectAccessToken: projectAccessToken,
}

// Act
authMethods, err := getAuthMethods(GITLAB, "user", &globalConfig, &projectConfig)
authMethods, err := getAuthMethods(GITLAB, faker.Username(), &globalConfig, &projectConfig)
// Assert
if err != nil {
t.Errorf("expected no error, got %v", err)
Expand All @@ -32,8 +37,9 @@ func TestGetAuthMethods_Success(t *testing.T) {
basicAuthFound := false
for _, authMethod := range authMethods {
if auth, ok := authMethod.(*http.BasicAuth); ok {
if auth.Password != "glpat-ABCDEFGHIJKLMNOPQRST" {
t.Errorf("expected password to be 'glpat-ABCDEFGHIJKLMNOPQRST', got %v", auth.Password)
if auth.Password != gitlabAccessToken && auth.Password != projectAccessToken {
t.Errorf("expected password to be either gitlabAccessToken or projectAccessToken, got %v",
auth.Password)
}
basicAuthFound = true
}
Expand All @@ -49,7 +55,7 @@ func TestGetAuthMethods_NoAuthMethodFound(t *testing.T) {
projectConfig := ProjectConfig{}

// Act
authMethods, err := getAuthMethods(GITLAB, "user", &globalConfig, &projectConfig)
authMethods, err := getAuthMethods(GITLAB, faker.Username(), &globalConfig, &projectConfig)
// Assert
if !errors.Is(err, ErrNoAuthMethodFound) {
t.Errorf("expected error to be ErrNoAuthMethod, got %v", err)
Expand All @@ -65,7 +71,7 @@ func TestGetAuthMethods_AuthNotImplemented(t *testing.T) {
projectConfig := ProjectConfig{}

// Act
authMethods, err := getAuthMethods(UNKNOWN, "user", &globalConfig, &projectConfig)
authMethods, err := getAuthMethods(UNKNOWN, faker.Username(), &globalConfig, &projectConfig)
// Assert
if !errors.Is(err, ErrAuthNotImplemented) {
t.Errorf("expected error to be ErrAuthNotImplemented, got %v", err)
Expand Down Expand Up @@ -110,7 +116,7 @@ func TestGetRemoteServiceType_UnknownService(t *testing.T) {

_, err = repo.CreateRemote(&config.RemoteConfig{
Name: "origin",
URLs: []string{"https://example.com/user/repo.git"},
URLs: []string{faker.URL()},
})
if err != nil {
t.Errorf("expected no error, got %v", err)
Expand Down Expand Up @@ -146,7 +152,7 @@ func TestGetLatestTag_Success(t *testing.T) {
if err != nil {
t.Errorf("expected no error, got %v", err)
}
_, err = file.Write([]byte("hello world"))
_, err = file.Write([]byte(faker.Sentence()))
if err != nil {
t.Errorf("expected no error, got %v", err)
}
Expand All @@ -159,7 +165,7 @@ func TestGetLatestTag_Success(t *testing.T) {
}

// Commit the changes
_, err = wt.Commit("initial commit", &git.CommitOptions{
_, err = wt.Commit(faker.Sentence(), &git.CommitOptions{
All: true,
})
if err != nil {
Expand All @@ -173,7 +179,8 @@ func TestGetLatestTag_Success(t *testing.T) {
}

// Create a tag on the commit
_, err = repo.CreateTag("1.0.0", head.Hash(), nil)
testTag := fmt.Sprintf("%d.%d.%d", rand.Intn(10), rand.Intn(10), rand.Intn(10))
_, err = repo.CreateTag(testTag, head.Hash(), nil)
if err != nil {
t.Errorf("expected no error, got %v", err)
}
Expand All @@ -184,8 +191,11 @@ func TestGetLatestTag_Success(t *testing.T) {
if err != nil {
t.Errorf("expected no error, got %v", err)
}
if tag.Tag.String() != "1.0.0" {
t.Errorf("expected tag to be '1.0.0', got %v", tag.Tag.String())
if tag.Tag == nil {
t.Errorf("expected tag to be non-nil, got nil")
}
if tag.Tag.String() != testTag {
t.Errorf("expected tag to be '%s', got %v", testTag, tag.Tag.String())
}
}

Expand Down
Loading

0 comments on commit caaa545

Please sign in to comment.