Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ayakovlenko committed Jun 13, 2024
1 parent 332b06a commit dbc88ea
Showing 1 changed file with 81 additions and 0 deletions.
81 changes: 81 additions & 0 deletions internal/identity/identity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,36 @@ func TestFindBestMatch(t *testing.T) {

func TestSetIdentity(t *testing.T) {

t.Run("set credentials", func(t *testing.T) {
// given
dryRun := false

gitClient := git.NewMockGitClient()

cred := config.User{
Name: "John Doe",
Email: "john.doe@gmail.com",
}

gitClient.AddCommand(
[]string{"config", "--local", "user.name", "John Doe"}, "", nil,
)

gitClient.AddCommand(
[]string{"config", "--local", "user.email", "john.doe@gmail.com"}, "", nil,
)

// when

err := setIdentity(gitClient, cred, dryRun)

// then

assert.NoError(t, err)
})

t.Run("set credentials and signing key", func(t *testing.T) {
// given
dryRun := false

gitClient := git.NewMockGitClient()
Expand All @@ -200,8 +229,60 @@ func TestSetIdentity(t *testing.T) {
},
}

gitClient.AddCommand(
[]string{"config", "--local", "user.name", "John Doe"}, "", nil,
)

gitClient.AddCommand(
[]string{"config", "--local", "user.email", "john.doe@gmail.com"}, "", nil,
)

gitClient.AddCommand(
[]string{"config", "--local", "commit.gpgsign", "true"}, "", nil,
)

gitClient.AddCommand(
[]string{"config", "--local", "tag.gpgsign", "true"}, "", nil,
)

gitClient.AddCommand(
[]string{"config", "--local", "user.signingKey", "~/.ssh/key"}, "", nil,
)

gitClient.AddCommand(
[]string{"config", "--local", "gpg.format", "ssh"}, "", nil,
)

// when

err := setIdentity(gitClient, cred, dryRun)

// then

assert.NoError(t, err)
})

t.Run("set credentials and signing key -- dry run", func(t *testing.T) {
// given
dryRun := true

gitClient := git.NewMockGitClient()

cred := config.User{
Name: "John Doe",
Email: "john.doe@gmail.com",
Signing: &config.Signing{
Key: "~/.ssh/key",
Format: "ssh",
},
}

// when

err := setIdentity(gitClient, cred, dryRun)

// then

assert.NoError(t, err)
})
}

0 comments on commit dbc88ea

Please sign in to comment.