Add more unit tests

This commit is contained in:
Jamie Curnow 2023-07-31 15:31:38 +10:00
parent db95a465c8
commit 155e09407f
No known key found for this signature in database
GPG Key ID: FFBB624C43388E9E
5 changed files with 152 additions and 5 deletions

View File

@ -1,11 +1,12 @@
package config
import (
"npm/internal/logger"
"os"
"strings"
"testing"
"npm/internal/logger"
"github.com/stretchr/testify/assert"
)
@ -22,7 +23,7 @@ func TestInit(t *testing.T) {
t.Setenv("NPM_DISABLE_IPV6", "true")
version := "999.999.999"
commit := "abcd123"
commit := "abcd124"
Init(&version, &commit)
err := InitIPRanges(&version, &commit)
assert.Nil(t, err)
@ -98,8 +99,8 @@ func TestConnectURLs(t *testing.T) {
},
}
version := "999.999.999"
commit := "abcd123"
version := "888.888.888"
commit := "abcd125"
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
@ -119,7 +120,7 @@ func TestConnectURLs(t *testing.T) {
func TestCreateDataFolders(t *testing.T) {
t.Setenv("NPM_DATA_FOLDER", "/tmp/npmtest")
version := "999.999.999"
version := "777.777.777"
commit := "abcd123"
Init(&version, &commit)
CreateDataFolders()

View File

@ -0,0 +1,33 @@
package dnsproviders
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestGetAll(t *testing.T) {
providers := GetAll()
// This number will have to (annoyingly) be updated
// when adding new dns providers to the list
assert.Equal(t, 45, len(providers))
_, dynuExists := providers["dns_dynu"]
assert.Equal(t, true, dynuExists)
_, duckDNSExists := providers["dns_duckdns"]
assert.Equal(t, true, duckDNSExists)
_, cfExists := providers["dns_cf"]
assert.Equal(t, true, cfExists)
_, randomExists := providers["dns_shouldnotexist"]
assert.Equal(t, false, randomExists)
}
func TestGet(t *testing.T) {
provider, err := Get("dns_duckdns")
assert.Nil(t, err)
assert.Equal(t, "dns_duckdns", provider.Title)
provider, err = Get("dns_shouldnotexist")
assert.NotNil(t, err)
assert.Equal(t, "provider_not_found", err.Error())
}

View File

@ -0,0 +1,47 @@
package dnsproviders
import (
"npm/internal/util"
"testing"
"github.com/stretchr/testify/assert"
)
func TestAcmeDNSProvider(t *testing.T) {
provider := getDNSAcmeDNS()
json, err := provider.GetJsonSchema()
assert.Nil(t, err)
assert.Equal(t, `{
"title": "dns_acmedns",
"type": "object",
"additionalProperties": false,
"required": [
"ACMEDNS_BASE_URL",
"ACMEDNS_SUBDOMAIN",
"ACMEDNS_USERNAME",
"ACMEDNS_PASSWORD"
],
"properties": {
"ACMEDNS_BASE_URL": {
"title": "base-url",
"type": "string",
"additionalProperties": false
},
"ACMEDNS_PASSWORD": {
"title": "password",
"type": "string",
"additionalProperties": false
},
"ACMEDNS_SUBDOMAIN": {
"title": "subdomain",
"type": "string",
"additionalProperties": false
},
"ACMEDNS_USERNAME": {
"title": "username",
"type": "string",
"additionalProperties": false
}
}
}`, util.PrettyPrintJSON(json))
}

View File

@ -0,0 +1,29 @@
package dnsproviders
import (
"npm/internal/util"
"testing"
"github.com/stretchr/testify/assert"
)
func TestAdProvider(t *testing.T) {
provider := getDNSAd()
provider.ConvertToUpdatable()
json, err := provider.GetJsonSchema()
assert.Nil(t, err)
assert.Equal(t, `{
"title": "dns_ad",
"type": "object",
"additionalProperties": false,
"minProperties": 1,
"properties": {
"AD_API_KEY": {
"title": "api-key",
"type": "string",
"additionalProperties": false,
"minLength": 1
}
}
}`, util.PrettyPrintJSON(json))
}

View File

@ -0,0 +1,37 @@
package dnsproviders
import (
"npm/internal/util"
"testing"
"github.com/stretchr/testify/assert"
)
func TestAliProvider(t *testing.T) {
provider := getDNSAli()
json, err := provider.GetJsonSchema()
assert.Nil(t, err)
assert.Equal(t, `{
"title": "dns_ali",
"type": "object",
"additionalProperties": false,
"required": [
"Ali_Key",
"Ali_Secret"
],
"properties": {
"Ali_Key": {
"title": "api-key",
"type": "string",
"additionalProperties": false,
"minLength": 1
},
"Ali_Secret": {
"title": "secret",
"type": "string",
"additionalProperties": false,
"minLength": 1
}
}
}`, util.PrettyPrintJSON(json))
}