fix: update test files to work with the new features
This commit is contained in:
@@ -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