mirror of
https://github.com/jc21/nginx-proxy-manager.git
synced 2024-08-30 18:22:48 +00:00
Add more unit tests
This commit is contained in:
parent
db95a465c8
commit
155e09407f
@ -1,11 +1,12 @@
|
|||||||
package config
|
package config
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"npm/internal/logger"
|
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"npm/internal/logger"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -22,7 +23,7 @@ func TestInit(t *testing.T) {
|
|||||||
t.Setenv("NPM_DISABLE_IPV6", "true")
|
t.Setenv("NPM_DISABLE_IPV6", "true")
|
||||||
|
|
||||||
version := "999.999.999"
|
version := "999.999.999"
|
||||||
commit := "abcd123"
|
commit := "abcd124"
|
||||||
Init(&version, &commit)
|
Init(&version, &commit)
|
||||||
err := InitIPRanges(&version, &commit)
|
err := InitIPRanges(&version, &commit)
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
@ -98,8 +99,8 @@ func TestConnectURLs(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
version := "999.999.999"
|
version := "888.888.888"
|
||||||
commit := "abcd123"
|
commit := "abcd125"
|
||||||
|
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
@ -119,7 +120,7 @@ func TestConnectURLs(t *testing.T) {
|
|||||||
func TestCreateDataFolders(t *testing.T) {
|
func TestCreateDataFolders(t *testing.T) {
|
||||||
t.Setenv("NPM_DATA_FOLDER", "/tmp/npmtest")
|
t.Setenv("NPM_DATA_FOLDER", "/tmp/npmtest")
|
||||||
|
|
||||||
version := "999.999.999"
|
version := "777.777.777"
|
||||||
commit := "abcd123"
|
commit := "abcd123"
|
||||||
Init(&version, &commit)
|
Init(&version, &commit)
|
||||||
CreateDataFolders()
|
CreateDataFolders()
|
||||||
|
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))
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user