Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 100cad5acd |
@@ -1,9 +1,9 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings" // Added import
|
||||
"testing"
|
||||
)
|
||||
|
||||
@@ -17,7 +17,8 @@ func TestRunMissingFlag(t *testing.T) {
|
||||
func TestRunNonexistentConfig(t *testing.T) {
|
||||
fake := filepath.Join(os.TempDir(), "no-such-file.yaml")
|
||||
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)
|
||||
}
|
||||
}
|
||||
@@ -39,13 +40,11 @@ clients: {}
|
||||
defer os.Remove(tmp)
|
||||
|
||||
err := run(tmp)
|
||||
if err == nil || !contains(err.Error(), "server error: unsupported provider") {
|
||||
t.Fatalf("expected unsupported provider error, got %v", err)
|
||||
// Check for the specific part of the wrapped error message
|
||||
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 {
|
||||
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
|
||||
})())
|
||||
}
|
||||
// Removed unused contains function
|
||||
|
||||
@@ -30,7 +30,8 @@ func TestUpdateRecordFullAPILifecycle(t *testing.T) {
|
||||
case r.Method == http.MethodGet && r.URL.Path == "/records":
|
||||
// Query records by zone_id
|
||||
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)
|
||||
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/server"
|
||||
"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.
|
||||
@@ -24,10 +25,12 @@ func (m *mockProvider) UpdateRecord(ctx context.Context, host, ip string) error
|
||||
}
|
||||
|
||||
func newTestConfig(provider string) *config.Config {
|
||||
// Pre-generate hash for "s3cr3t" (replace with actual hash generation if needed)
|
||||
// Example hash generated with bcrypt.GenerateFromPassword([]byte("s3cr3t"), bcrypt.DefaultCost)
|
||||
// In a real test setup, you might generate this once or use a helper.
|
||||
testSecretHash := "$2a$10$abcdefghijklmnopqrstuv" // Placeholder hash
|
||||
// Generate hash for "s3cr3t" dynamically for the test
|
||||
hashBytes, err := bcrypt.GenerateFromPassword([]byte("s3cr3t"), bcrypt.DefaultCost)
|
||||
if err != nil {
|
||||
panic("bcrypt hash generation failed in test setup: " + err.Error()) // Panic is acceptable in test setup
|
||||
}
|
||||
testSecretHash := string(hashBytes)
|
||||
|
||||
return &config.Config{
|
||||
Server: config.ServerConfig{
|
||||
|
||||
Reference in New Issue
Block a user