mirror of
https://github.com/NginxProxyManager/nginx-proxy-manager.git
synced 2025-06-18 18:16:26 +00:00
Add more unit tests
This commit is contained in:
33
backend/internal/dnsproviders/common_test.go
Normal file
33
backend/internal/dnsproviders/common_test.go
Normal 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())
|
||||
}
|
47
backend/internal/dnsproviders/dns_acmedns_test.go
Normal file
47
backend/internal/dnsproviders/dns_acmedns_test.go
Normal 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))
|
||||
}
|
29
backend/internal/dnsproviders/dns_ad_test.go
Normal file
29
backend/internal/dnsproviders/dns_ad_test.go
Normal 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))
|
||||
}
|
37
backend/internal/dnsproviders/dns_ali_test.go
Normal file
37
backend/internal/dnsproviders/dns_ali_test.go
Normal 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))
|
||||
}
|
Reference in New Issue
Block a user