Skip to content

Commit 2df87b4

Browse files
committed
refactor: use testify suite
1 parent f3f1c0b commit 2df87b4

1 file changed

Lines changed: 25 additions & 36 deletions

File tree

pkg/gitsshsigning/helper_test.go

Lines changed: 25 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -3,67 +3,56 @@ package gitsshsigning
33
import (
44
"strings"
55
"testing"
6+
7+
"github.com/stretchr/testify/assert"
8+
"github.com/stretchr/testify/suite"
69
)
710

8-
func TestRemoveSignatureHelper_PreservesUnrelatedGpgConfig(t *testing.T) {
11+
type HelperTestSuite struct {
12+
suite.Suite
13+
}
14+
15+
func TestHelperSuite(t *testing.T) {
16+
suite.Run(t, new(HelperTestSuite))
17+
}
18+
19+
func (s *HelperTestSuite) TestRemoveSignatureHelper_PreservesUnrelatedGpgConfig() {
920
input := strings.Join([]string{
1021
"[user]", "\tname = Test User", "\temail = test@example.com",
11-
"[gpg \"ssh\"]", "\tprogram = devpod-ssh-signature",
22+
`[gpg "ssh"]`, "\tprogram = devpod-ssh-signature",
1223
"[gpg]", "\tformat = ssh", "\tprogram = /usr/bin/gpg2",
1324
"[commit]", "\tgpgsign = true",
1425
"[user]", "\tsigningkey = /path/to/key",
1526
}, "\n")
1627

1728
result := removeSignatureHelper(input)
1829

19-
if strings.Contains(result, "devpod-ssh-signature") {
20-
t.Errorf("expected devpod-ssh-signature to be removed, got:\n%s", result)
21-
}
22-
if !strings.Contains(result, "[user]") {
23-
t.Errorf("expected [user] section to be preserved, got:\n%s", result)
24-
}
25-
if !strings.Contains(result, "[commit]") {
26-
t.Errorf("expected [commit] section to be preserved, got:\n%s", result)
27-
}
28-
if !strings.Contains(result, "program = /usr/bin/gpg2") {
29-
t.Errorf("expected unrelated gpg program to be preserved, got:\n%s", result)
30-
}
31-
if strings.Contains(result, "format = ssh") {
32-
t.Errorf("expected 'format = ssh' to be removed, got:\n%s", result)
33-
}
30+
assert.NotContains(s.T(), result, "devpod-ssh-signature")
31+
assert.Contains(s.T(), result, "[user]")
32+
assert.Contains(s.T(), result, "[commit]")
33+
assert.Contains(s.T(), result, "program = /usr/bin/gpg2")
34+
assert.NotContains(s.T(), result, "format = ssh")
3435
}
3536

36-
func TestRemoveSignatureHelper_RemovesDevpodSections(t *testing.T) {
37+
func (s *HelperTestSuite) TestRemoveSignatureHelper_RemovesDevpodSections() {
3738
input := strings.Join([]string{
3839
"[user]", "\tname = Test User",
39-
"[gpg \"ssh\"]", "\tprogram = devpod-ssh-signature",
40+
`[gpg "ssh"]`, "\tprogram = devpod-ssh-signature",
4041
"[gpg]", "\tformat = ssh",
4142
"[user]", "\tsigningkey = /path/to/key",
4243
}, "\n")
4344

4445
result := removeSignatureHelper(input)
4546

46-
if strings.Contains(result, "devpod-ssh-signature") {
47-
t.Errorf("expected devpod-ssh-signature to be removed, got:\n%s", result)
48-
}
49-
if strings.Contains(result, "format = ssh") {
50-
t.Errorf("expected 'format = ssh' under [gpg] to be removed, got:\n%s", result)
51-
}
52-
if !strings.Contains(result, "Test User") {
53-
t.Errorf("expected user name to be preserved, got:\n%s", result)
54-
}
47+
assert.NotContains(s.T(), result, "devpod-ssh-signature")
48+
assert.NotContains(s.T(), result, "format = ssh")
49+
assert.Contains(s.T(), result, "Test User")
5550
}
5651

57-
func TestRemoveSignatureHelper_NoGpgSections(t *testing.T) {
52+
func (s *HelperTestSuite) TestRemoveSignatureHelper_NoGpgSections() {
5853
input := "[user]\n\tname = Test User\n\temail = test@example.com"
5954

6055
result := removeSignatureHelper(input)
6156

62-
if result != input {
63-
t.Errorf(
64-
"expected input to be unchanged when no gpg sections exist.\nExpected:\n%s\nGot:\n%s",
65-
input,
66-
result,
67-
)
68-
}
57+
assert.Equal(s.T(), input, result)
6958
}

0 commit comments

Comments
 (0)