aboutsummaryrefslogtreecommitdiff
path: root/internal/db
diff options
context:
space:
mode:
authorᴜɴᴋɴᴡᴏɴ <u@gogs.io>2020-04-19 04:24:08 +0800
committerGitHub <noreply@github.com>2020-04-19 04:24:08 +0800
commitc0fd6042fd56646f24275785faf5cd40ed8ab2c2 (patch)
tree6e448c85aefed0edeacf396608b7667c43e14d63 /internal/db
parentfc57c921b1716f0f84b5b2d4d5693091c48a4b2d (diff)
test: remove the use of goconvey (#6123)
Diffstat (limited to 'internal/db')
-rw-r--r--internal/db/repo_editor_test.go39
-rw-r--r--internal/db/repo_test.go92
-rw-r--r--internal/db/ssh_key_test.go91
3 files changed, 116 insertions, 106 deletions
diff --git a/internal/db/repo_editor_test.go b/internal/db/repo_editor_test.go
index 18e844d0..1b7d2265 100644
--- a/internal/db/repo_editor_test.go
+++ b/internal/db/repo_editor_test.go
@@ -5,30 +5,29 @@
package db
import (
- "os"
+ "path/filepath"
"testing"
- . "github.com/smartystreets/goconvey/convey"
+ "github.com/stretchr/testify/assert"
)
func Test_isRepositoryGitPath(t *testing.T) {
- Convey("Check if path is or resides inside '.git'", t, func() {
- sep := string(os.PathSeparator)
- testCases := []struct {
- path string
- expect bool
- }{
- {"." + sep + ".git", true},
- {"." + sep + ".git" + sep + "", true},
- {"." + sep + ".git" + sep + "hooks" + sep + "pre-commit", true},
- {".git" + sep + "hooks", true},
- {"dir" + sep + ".git", true},
+ tests := []struct {
+ path string
+ expVal bool
+ }{
+ {path: filepath.Join(".", ".git"), expVal: true},
+ {path: filepath.Join(".", ".git", ""), expVal: true},
+ {path: filepath.Join(".", ".git", "hooks", "pre-commit"), expVal: true},
+ {path: filepath.Join(".git", "hooks"), expVal: true},
+ {path: filepath.Join("dir", ".git"), expVal: true},
- {".gitignore", false},
- {"dir" + sep + ".gitkeep", false},
- }
- for _, tc := range testCases {
- So(isRepositoryGitPath(tc.path), ShouldEqual, tc.expect)
- }
- })
+ {path: filepath.Join(".gitignore"), expVal: false},
+ {path: filepath.Join("dir", ".gitkeep"), expVal: false},
+ }
+ for _, test := range tests {
+ t.Run("", func(t *testing.T) {
+ assert.Equal(t, test.expVal, isRepositoryGitPath(test.path))
+ })
+ }
}
diff --git a/internal/db/repo_test.go b/internal/db/repo_test.go
index c239e74d..f689f05d 100644
--- a/internal/db/repo_test.go
+++ b/internal/db/repo_test.go
@@ -1,63 +1,49 @@
-package db_test
+package db
import (
"testing"
- . "github.com/smartystreets/goconvey/convey"
+ "github.com/stretchr/testify/assert"
- "gogs.io/gogs/internal/db"
"gogs.io/gogs/internal/markup"
)
-func TestRepo(t *testing.T) {
- Convey("The metas map", t, func() {
- var repo = new(db.Repository)
- repo.Name = "testrepo"
- repo.Owner = new(db.User)
- repo.Owner.Name = "testuser"
- repo.ExternalTrackerFormat = "https://someurl.com/{user}/{repo}/{issue}"
-
- Convey("When no external tracker is configured", func() {
- Convey("It should be nil", func() {
- repo.EnableExternalTracker = false
- So(repo.ComposeMetas(), ShouldEqual, map[string]string(nil))
- })
- Convey("It should be nil even if other settings are present", func() {
- repo.EnableExternalTracker = false
- repo.ExternalTrackerFormat = "http://someurl.com/{user}/{repo}/{issue}"
- repo.ExternalTrackerStyle = markup.ISSUE_NAME_STYLE_NUMERIC
- So(repo.ComposeMetas(), ShouldEqual, map[string]string(nil))
- })
- })
-
- Convey("When an external issue tracker is configured", func() {
- repo.EnableExternalTracker = true
- Convey("It should default to numeric issue style", func() {
- metas := repo.ComposeMetas()
- So(metas["style"], ShouldEqual, markup.ISSUE_NAME_STYLE_NUMERIC)
- })
- Convey("It should pass through numeric issue style setting", func() {
- repo.ExternalTrackerStyle = markup.ISSUE_NAME_STYLE_NUMERIC
- metas := repo.ComposeMetas()
- So(metas["style"], ShouldEqual, markup.ISSUE_NAME_STYLE_NUMERIC)
- })
- Convey("It should pass through alphanumeric issue style setting", func() {
- repo.ExternalTrackerStyle = markup.ISSUE_NAME_STYLE_ALPHANUMERIC
- metas := repo.ComposeMetas()
- So(metas["style"], ShouldEqual, markup.ISSUE_NAME_STYLE_ALPHANUMERIC)
- })
- Convey("It should contain the user name", func() {
- metas := repo.ComposeMetas()
- So(metas["user"], ShouldEqual, "testuser")
- })
- Convey("It should contain the repo name", func() {
- metas := repo.ComposeMetas()
- So(metas["repo"], ShouldEqual, "testrepo")
- })
- Convey("It should contain the URL format", func() {
- metas := repo.ComposeMetas()
- So(metas["format"], ShouldEqual, "https://someurl.com/{user}/{repo}/{issue}")
- })
- })
+func TestRepository_ComposeMetas(t *testing.T) {
+ repo := &Repository{
+ Name: "testrepo",
+ Owner: &User{
+ Name: "testuser",
+ },
+ ExternalTrackerFormat: "https://someurl.com/{user}/{repo}/{issue}",
+ }
+
+ t.Run("no external tracker is configured", func(t *testing.T) {
+ repo.EnableExternalTracker = false
+ assert.Equal(t, map[string]string(nil), repo.ComposeMetas())
+
+ // Should be nil even if other settings are present
+ repo.ExternalTrackerStyle = markup.ISSUE_NAME_STYLE_NUMERIC
+ assert.Equal(t, map[string]string(nil), repo.ComposeMetas())
+ })
+
+ t.Run("an external issue tracker is configured", func(t *testing.T) {
+ repo.EnableExternalTracker = true
+
+ // Default to numeric issue style
+ assert.Equal(t, markup.ISSUE_NAME_STYLE_NUMERIC, repo.ComposeMetas()["style"])
+ repo.ExternalMetas = nil
+
+ repo.ExternalTrackerStyle = markup.ISSUE_NAME_STYLE_NUMERIC
+ assert.Equal(t, markup.ISSUE_NAME_STYLE_NUMERIC, repo.ComposeMetas()["style"])
+ repo.ExternalMetas = nil
+
+ repo.ExternalTrackerStyle = markup.ISSUE_NAME_STYLE_ALPHANUMERIC
+ assert.Equal(t, markup.ISSUE_NAME_STYLE_ALPHANUMERIC, repo.ComposeMetas()["style"])
+ repo.ExternalMetas = nil
+
+ metas := repo.ComposeMetas()
+ assert.Equal(t, "testuser", metas["user"])
+ assert.Equal(t, "testrepo", metas["repo"])
+ assert.Equal(t, "https://someurl.com/{user}/{repo}/{issue}", metas["format"])
})
}
diff --git a/internal/db/ssh_key_test.go b/internal/db/ssh_key_test.go
index dfd945b6..ceaf48c2 100644
--- a/internal/db/ssh_key_test.go
+++ b/internal/db/ssh_key_test.go
@@ -5,49 +5,74 @@
package db
import (
- "fmt"
- "strings"
"testing"
- . "github.com/smartystreets/goconvey/convey"
+ "github.com/stretchr/testify/assert"
"gogs.io/gogs/internal/conf"
)
func Test_SSHParsePublicKey(t *testing.T) {
+ // TODO: Refactor SSHKeyGenParsePublicKey to accept a tempPath and remove this init.
conf.MustInit("")
- testKeys := map[string]struct {
- typeName string
- length int
- content string
+ tests := []struct {
+ name string
+ content string
+ expType string
+ expLength int
}{
- "dsa-1024": {"dsa", 1024, "ssh-dss AAAAB3NzaC1kc3MAAACBAOChCC7lf6Uo9n7BmZ6M8St19PZf4Tn59NriyboW2x/DZuYAz3ibZ2OkQ3S0SqDIa0HXSEJ1zaExQdmbO+Ux/wsytWZmCczWOVsaszBZSl90q8UnWlSH6P+/YA+RWJm5SFtuV9PtGIhyZgoNuz5kBQ7K139wuQsecdKktISwTakzAAAAFQCzKsO2JhNKlL+wwwLGOcLffoAmkwAAAIBpK7/3xvduajLBD/9vASqBQIHrgK2J+wiQnIb/Wzy0UsVmvfn8A+udRbBo+csM8xrSnlnlJnjkJS3qiM5g+eTwsLIV1IdKPEwmwB+VcP53Cw6lSyWyJcvhFb0N6s08NZysLzvj0N+ZC/FnhKTLzIyMtkHf/IrPCwlM+pV/M/96YgAAAIEAqQcGn9CKgzgPaguIZooTAOQdvBLMI5y0bQjOW6734XOpqQGf/Kra90wpoasLKZjSYKNPjE+FRUOrStLrxcNs4BeVKhy2PYTRnybfYVk1/dmKgH6P1YSRONsGKvTsH6c5IyCRG0ncCgYeF8tXppyd642982daopE7zQ/NPAnJfag= nocomment"},
- "rsa-1024": {"rsa", 1024, "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQDAu7tvIvX6ZHrRXuZNfkR3XLHSsuCK9Zn3X58lxBcQzuo5xZgB6vRwwm/QtJuF+zZPtY5hsQILBLmF+BZ5WpKZp1jBeSjH2G7lxet9kbcH+kIVj0tPFEoyKI9wvWqIwC4prx/WVk2wLTJjzBAhyNxfEq7C9CeiX9pQEbEqJfkKCQ== nocomment\n"},
- "rsa-2048": {"rsa", 2048, "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDMZXh+1OBUwSH9D45wTaxErQIN9IoC9xl7MKJkqvTvv6O5RR9YW/IK9FbfjXgXsppYGhsCZo1hFOOsXHMnfOORqu/xMDx4yPuyvKpw4LePEcg4TDipaDFuxbWOqc/BUZRZcXu41QAWfDLrInwsltWZHSeG7hjhpacl4FrVv9V1pS6Oc5Q1NxxEzTzuNLS/8diZrTm/YAQQ/+B+mzWI3zEtF4miZjjAljWd1LTBPvU23d29DcBmmFahcZ441XZsTeAwGxG/Q6j8NgNXj9WxMeWwxXV2jeAX/EBSpZrCVlCQ1yJswT6xCp8TuBnTiGWYMBNTbOZvPC4e0WI2/yZW/s5F nocomment"},
- "ecdsa-256": {"ecdsa", 256, "ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBFQacN3PrOll7PXmN5B/ZNVahiUIqI05nbBlZk1KXsO3d06ktAWqbNflv2vEmA38bTFTfJ2sbn2B5ksT52cDDbA= nocomment"},
- "ecdsa-384": {"ecdsa", 384, "ecdsa-sha2-nistp384 AAAAE2VjZHNhLXNoYTItbmlzdHAzODQAAAAIbmlzdHAzODQAAABhBINmioV+XRX1Fm9Qk2ehHXJ2tfVxW30ypUWZw670Zyq5GQfBAH6xjygRsJ5wWsHXBsGYgFUXIHvMKVAG1tpw7s6ax9oA+dJOJ7tj+vhn8joFqT+sg3LYHgZkHrfqryRasQ== nocomment"},
- // "ecdsa-521": {"ecdsa", 521, "ecdsa-sha2-nistp521 AAAAE2VjZHNhLXNoYTItbmlzdHA1MjEAAAAIbmlzdHA1MjEAAACFBACGt3UG3EzRwNOI17QR84l6PgiAcvCE7v6aXPj/SC6UWKg4EL8vW9ZBcdYL9wzs4FZXh4MOV8jAzu3KRWNTwb4k2wFNUpGOt7l28MztFFEtH5BDDrtAJSPENPy8pvPLMfnPg5NhvWycqIBzNcHipem5wSJFN5PdpNOC2xMrPWKNqj+ZjQ== nocomment"},
+ {
+ name: "dsa-1024",
+ content: "ssh-dss AAAAB3NzaC1kc3MAAACBAOChCC7lf6Uo9n7BmZ6M8St19PZf4Tn59NriyboW2x/DZuYAz3ibZ2OkQ3S0SqDIa0HXSEJ1zaExQdmbO+Ux/wsytWZmCczWOVsaszBZSl90q8UnWlSH6P+/YA+RWJm5SFtuV9PtGIhyZgoNuz5kBQ7K139wuQsecdKktISwTakzAAAAFQCzKsO2JhNKlL+wwwLGOcLffoAmkwAAAIBpK7/3xvduajLBD/9vASqBQIHrgK2J+wiQnIb/Wzy0UsVmvfn8A+udRbBo+csM8xrSnlnlJnjkJS3qiM5g+eTwsLIV1IdKPEwmwB+VcP53Cw6lSyWyJcvhFb0N6s08NZysLzvj0N+ZC/FnhKTLzIyMtkHf/IrPCwlM+pV/M/96YgAAAIEAqQcGn9CKgzgPaguIZooTAOQdvBLMI5y0bQjOW6734XOpqQGf/Kra90wpoasLKZjSYKNPjE+FRUOrStLrxcNs4BeVKhy2PYTRnybfYVk1/dmKgH6P1YSRONsGKvTsH6c5IyCRG0ncCgYeF8tXppyd642982daopE7zQ/NPAnJfag= nocomment",
+ expType: "dsa",
+ expLength: 1024,
+ },
+ {
+ name: "rsa-1024",
+ content: "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQDAu7tvIvX6ZHrRXuZNfkR3XLHSsuCK9Zn3X58lxBcQzuo5xZgB6vRwwm/QtJuF+zZPtY5hsQILBLmF+BZ5WpKZp1jBeSjH2G7lxet9kbcH+kIVj0tPFEoyKI9wvWqIwC4prx/WVk2wLTJjzBAhyNxfEq7C9CeiX9pQEbEqJfkKCQ== nocomment",
+ expType: "rsa",
+ expLength: 1024,
+ },
+ {
+ name: "rsa-2048",
+ content: "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDMZXh+1OBUwSH9D45wTaxErQIN9IoC9xl7MKJkqvTvv6O5RR9YW/IK9FbfjXgXsppYGhsCZo1hFOOsXHMnfOORqu/xMDx4yPuyvKpw4LePEcg4TDipaDFuxbWOqc/BUZRZcXu41QAWfDLrInwsltWZHSeG7hjhpacl4FrVv9V1pS6Oc5Q1NxxEzTzuNLS/8diZrTm/YAQQ/+B+mzWI3zEtF4miZjjAljWd1LTBPvU23d29DcBmmFahcZ441XZsTeAwGxG/Q6j8NgNXj9WxMeWwxXV2jeAX/EBSpZrCVlCQ1yJswT6xCp8TuBnTiGWYMBNTbOZvPC4e0WI2/yZW/s5F nocomment",
+ expType: "rsa",
+ expLength: 2048,
+ },
+ {
+ name: "ecdsa-256",
+ content: "ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBFQacN3PrOll7PXmN5B/ZNVahiUIqI05nbBlZk1KXsO3d06ktAWqbNflv2vEmA38bTFTfJ2sbn2B5ksT52cDDbA= nocomment",
+ expType: "ecdsa",
+ expLength: 256,
+ },
+ {
+ name: "ecdsa-384",
+ content: "ecdsa-sha2-nistp384 AAAAE2VjZHNhLXNoYTItbmlzdHAzODQAAAAIbmlzdHAzODQAAABhBINmioV+XRX1Fm9Qk2ehHXJ2tfVxW30ypUWZw670Zyq5GQfBAH6xjygRsJ5wWsHXBsGYgFUXIHvMKVAG1tpw7s6ax9oA+dJOJ7tj+vhn8joFqT+sg3LYHgZkHrfqryRasQ== nocomment",
+ expType: "ecdsa",
+ expLength: 384,
+ },
+ {
+ name: "ecdsa-521",
+ content: "ecdsa-sha2-nistp521 AAAAE2VjZHNhLXNoYTItbmlzdHA1MjEAAAAIbmlzdHA1MjEAAACFBACGt3UG3EzRwNOI17QR84l6PgiAcvCE7v6aXPj/SC6UWKg4EL8vW9ZBcdYL9wzs4FZXh4MOV8jAzu3KRWNTwb4k2wFNUpGOt7l28MztFFEtH5BDDrtAJSPENPy8pvPLMfnPg5NhvWycqIBzNcHipem5wSJFN5PdpNOC2xMrPWKNqj+ZjQ== nocomment",
+ expType: "ecdsa",
+ expLength: 521,
+ },
}
+ for _, test := range tests {
+ t.Run(test.name, func(t *testing.T) {
+ typ, length, err := SSHNativeParsePublicKey(test.content)
+ if err != nil {
+ t.Fatal(err)
+ }
+ assert.Equal(t, test.expType, typ)
+ assert.Equal(t, test.expLength, length)
- Convey("Parse public keys in both native and ssh-keygen", t, func() {
- for name, key := range testKeys {
- fmt.Println("\nTesting key:", name)
-
- keyTypeN, lengthN, errN := SSHNativeParsePublicKey(key.content)
- So(errN, ShouldBeNil)
- So(keyTypeN, ShouldEqual, key.typeName)
- So(lengthN, ShouldEqual, key.length)
-
- keyTypeK, lengthK, errK := SSHKeyGenParsePublicKey(key.content)
- if errK != nil {
- // Some server just does not support ecdsa format.
- if strings.Contains(errK.Error(), "line 1 too long:") {
- continue
- }
- So(errK, ShouldBeNil)
+ typ, length, err = SSHKeyGenParsePublicKey(test.content)
+ if err != nil {
+ t.Fatal(err)
}
- So(keyTypeK, ShouldEqual, key.typeName)
- So(lengthK, ShouldEqual, key.length)
- }
- })
+ assert.Equal(t, test.expType, typ)
+ assert.Equal(t, test.expLength, length)
+ })
+ }
}