BREAKING CHANGE: The original Go module name was `github.com/ArtalkJS/Artalk`, which has now been modified to `github.com/artalkjs/artalk/v2` (all lowercase). This change may affect the CI pipeline or other areas if you are compiling the Artalk server and have specified the fixed Go module name. Regarding the original `-ldflags -X github.com/ArtalkJS/Artalk/internal/config.Version` and `CommitHash` definitions, please remove them, as they are now obsolete. The `Version` has been hardcoded into the Go code, and the `CommitHash` is now read from the Go build info via runtime/debug’s vcs.revision value. This change only affects the server developers and does not impact the frontend UI client.
52 lines
1.3 KiB
Go
52 lines
1.3 KiB
Go
package config
|
|
|
|
import (
|
|
"reflect"
|
|
"testing"
|
|
|
|
"github.com/artalkjs/artalk/v2/internal/utils"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func Test_GetHashFuncByFrontendConf(t *testing.T) {
|
|
tests := map[string]struct {
|
|
config *Config
|
|
expected any
|
|
}{
|
|
"nil frontend conf": {
|
|
config: &Config{Frontend: nil},
|
|
expected: utils.GetMD5Hash,
|
|
},
|
|
"empty frontend conf": {
|
|
config: &Config{Frontend: map[string]interface{}{}},
|
|
expected: utils.GetMD5Hash,
|
|
},
|
|
"frontend conf without hash func": {
|
|
config: &Config{Frontend: map[string]interface{}{
|
|
"gravatar": false,
|
|
}},
|
|
expected: utils.GetMD5Hash,
|
|
},
|
|
"frontend conf with gravatar params but without hash func": {
|
|
config: &Config{Frontend: map[string]interface{}{
|
|
"gravatar": map[string]interface{}{"params": "a=1&b=2"},
|
|
}},
|
|
expected: utils.GetMD5Hash,
|
|
},
|
|
"frontend conf with gravatar params containing hash func": {
|
|
config: &Config{Frontend: map[string]interface{}{
|
|
"gravatar": map[string]interface{}{"params": "a=1&sha256=1&b=2"},
|
|
}},
|
|
expected: utils.GetSha256Hash,
|
|
},
|
|
}
|
|
|
|
for name, tc := range tests {
|
|
t.Run(name, func(t *testing.T) {
|
|
expect := reflect.ValueOf(tc.expected).Pointer()
|
|
actual := reflect.ValueOf(GetHashFuncByFrontendConf(tc.config)).Pointer()
|
|
assert.Equal(t, expect, actual)
|
|
})
|
|
}
|
|
}
|