Switch to semver, basic test.

This commit is contained in:
2021-06-17 18:47:59 +09:30
parent c47660addf
commit 1812486b19
6 changed files with 54 additions and 3 deletions

View File

@@ -10,6 +10,7 @@ import (
daulog "github.com/tardisx/discord-auto-upload/log"
"github.com/mitchellh/go-homedir"
"golang.org/x/mod/semver"
)
// Config for the application
@@ -22,7 +23,7 @@ var Config struct {
Exclude string
}
const CurrentVersion string = "0.10"
const CurrentVersion string = "v1.0.0"
// Load the current config or initialise with defaults
func LoadOrInit() {
@@ -76,3 +77,22 @@ func configPath() string {
homeDir := homeDir()
return homeDir + string(os.PathSeparator) + ".dau.json"
}
func NewVersionAvailable(v string) bool {
if !semver.IsValid(CurrentVersion) {
panic(fmt.Sprintf("my current version '%s' is not valid", CurrentVersion))
}
if !semver.IsValid(v) {
// maybe this should just be a warning
log.Printf("passed in version '%s' is not valid - assuming no new version", v)
return false
}
comp := semver.Compare(v, CurrentVersion)
if comp == 0 {
return false
}
if comp == -1 {
return true
}
return false // they are using a newer one than exists?
}

13
config/config_test.go Normal file
View File

@@ -0,0 +1,13 @@
package config_test
import (
"testing"
"github.com/tardisx/discord-auto-upload/config"
)
func TestVersioning(t *testing.T) {
if !config.NewVersionAvailable("v0.1.0") {
t.Error("should be a version newer than v0.1.0")
}
}