Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 100cad5acd |
@@ -1,9 +1,9 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"strings" // Added import
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -17,7 +17,8 @@ func TestRunMissingFlag(t *testing.T) {
|
|||||||
func TestRunNonexistentConfig(t *testing.T) {
|
func TestRunNonexistentConfig(t *testing.T) {
|
||||||
fake := filepath.Join(os.TempDir(), "no-such-file.yaml")
|
fake := filepath.Join(os.TempDir(), "no-such-file.yaml")
|
||||||
err := run(fake)
|
err := run(fake)
|
||||||
if err == nil || !contains(err.Error(), "config load error:") {
|
// Use strings.Contains for standard substring check
|
||||||
|
if err == nil || !strings.Contains(err.Error(), "config load error:") {
|
||||||
t.Fatalf("expected config load error, got %v", err)
|
t.Fatalf("expected config load error, got %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -39,13 +40,11 @@ clients: {}
|
|||||||
defer os.Remove(tmp)
|
defer os.Remove(tmp)
|
||||||
|
|
||||||
err := run(tmp)
|
err := run(tmp)
|
||||||
if err == nil || !contains(err.Error(), "server error: unsupported provider") {
|
// Check for the specific part of the wrapped error message
|
||||||
t.Fatalf("expected unsupported provider error, got %v", err)
|
expectedErrSubstring := "unsupported provider unknown"
|
||||||
|
if err == nil || !strings.Contains(err.Error(), expectedErrSubstring) {
|
||||||
|
t.Fatalf("expected error containing '%s', got %v", expectedErrSubstring, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func contains(s, substr string) bool {
|
// Removed unused contains function
|
||||||
return fmt.Sprintf("%v", s) != "" && (substr == s || len(s) > len(substr) && fmt.Sprint(s) != "" && (func() bool {
|
|
||||||
return len(s) >= len(substr) && s[:len(substr)] == substr
|
|
||||||
})())
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -30,7 +30,8 @@ func TestUpdateRecordFullAPILifecycle(t *testing.T) {
|
|||||||
case r.Method == http.MethodGet && r.URL.Path == "/records":
|
case r.Method == http.MethodGet && r.URL.Path == "/records":
|
||||||
// Query records by zone_id
|
// Query records by zone_id
|
||||||
resp := map[string]interface{}{
|
resp := map[string]interface{}{
|
||||||
"records": []map[string]string{{"id": recID, "name": domain, "value": "0.0.0.0", "type": "A"}},
|
// Return the relative subdomain name ("test") as the API does, not the full domain
|
||||||
|
"records": []map[string]string{{"id": recID, "name": "test", "value": "0.0.0.0", "type": "A"}},
|
||||||
}
|
}
|
||||||
json.NewEncoder(w).Encode(resp)
|
json.NewEncoder(w).Encode(resp)
|
||||||
case r.Method == http.MethodPut && r.URL.Path == "/records/"+recID:
|
case r.Method == http.MethodPut && r.URL.Path == "/records/"+recID:
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import (
|
|||||||
"git.cloonar.com/cloonar/updns/internal/config" // Added for mock provider
|
"git.cloonar.com/cloonar/updns/internal/config" // Added for mock provider
|
||||||
"git.cloonar.com/cloonar/updns/internal/server"
|
"git.cloonar.com/cloonar/updns/internal/server"
|
||||||
"go.uber.org/zap" // Added for logger
|
"go.uber.org/zap" // Added for logger
|
||||||
|
"golang.org/x/crypto/bcrypt"
|
||||||
)
|
)
|
||||||
|
|
||||||
// mockProvider is a simple mock for testing router logic without real provider interaction.
|
// mockProvider is a simple mock for testing router logic without real provider interaction.
|
||||||
@@ -24,10 +25,12 @@ func (m *mockProvider) UpdateRecord(ctx context.Context, host, ip string) error
|
|||||||
}
|
}
|
||||||
|
|
||||||
func newTestConfig(provider string) *config.Config {
|
func newTestConfig(provider string) *config.Config {
|
||||||
// Pre-generate hash for "s3cr3t" (replace with actual hash generation if needed)
|
// Generate hash for "s3cr3t" dynamically for the test
|
||||||
// Example hash generated with bcrypt.GenerateFromPassword([]byte("s3cr3t"), bcrypt.DefaultCost)
|
hashBytes, err := bcrypt.GenerateFromPassword([]byte("s3cr3t"), bcrypt.DefaultCost)
|
||||||
// In a real test setup, you might generate this once or use a helper.
|
if err != nil {
|
||||||
testSecretHash := "$2a$10$abcdefghijklmnopqrstuv" // Placeholder hash
|
panic("bcrypt hash generation failed in test setup: " + err.Error()) // Panic is acceptable in test setup
|
||||||
|
}
|
||||||
|
testSecretHash := string(hashBytes)
|
||||||
|
|
||||||
return &config.Config{
|
return &config.Config{
|
||||||
Server: config.ServerConfig{
|
Server: config.ServerConfig{
|
||||||
|
|||||||
Reference in New Issue
Block a user