• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

supabase / pg_replicate / 13136601502

04 Feb 2025 01:29PM UTC coverage: 36.506% (-0.7%) from 37.25%
13136601502

Pull #88

github

imor
wrap publications api response in an object
Pull Request #88: API responses now always return objects and never arrays

14 of 25 new or added lines in 7 files covered. (56.0%)

11 existing lines in 5 files now uncovered.

2010 of 5506 relevant lines covered (36.51%)

15.85 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

68.32
/api/src/replicator_config.rs
1
use std::fmt::Debug;
2

3
#[derive(serde::Serialize, serde::Deserialize, PartialEq, Eq)]
4
pub enum SourceConfig {
5
    Postgres {
6
        /// Host on which Postgres is running
7
        host: String,
8

9
        /// Port on which Postgres is running
10
        port: u16,
11

12
        /// Postgres database name
13
        name: String,
14

15
        /// Postgres database user name
16
        username: String,
17

18
        /// Postgres slot name
19
        slot_name: String,
20

21
        /// Postgres publication name
22
        publication: String,
23
    },
24
}
25

26
impl Debug for SourceConfig {
UNCOV
27
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
×
28
        match self {
×
29
            Self::Postgres {
×
30
                host,
×
31
                port,
×
32
                name,
×
33
                username,
×
34
                slot_name,
×
35
                publication,
×
36
            } => f
×
37
                .debug_struct("Postgres")
×
38
                .field("host", host)
×
39
                .field("port", port)
×
40
                .field("name", name)
×
41
                .field("username", username)
×
42
                .field("slot_name", slot_name)
×
43
                .field("publication", publication)
×
44
                .finish(),
×
45
        }
×
46
    }
×
47
}
48

49
#[derive(serde::Serialize, serde::Deserialize, PartialEq, Eq)]
50
pub enum SinkConfig {
51
    BigQuery {
52
        /// BigQuery project id
53
        project_id: String,
54

55
        /// BigQuery dataset id
56
        dataset_id: String,
57
    },
58
}
59

60
impl Debug for SinkConfig {
UNCOV
61
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
×
UNCOV
62
        match self {
×
63
            Self::BigQuery {
×
64
                project_id,
×
65
                dataset_id,
×
66
            } => f
×
67
                .debug_struct("BigQuery")
×
68
                .field("project_id", project_id)
×
69
                .field("dataset_id", dataset_id)
×
70
                .finish(),
×
71
        }
×
72
    }
×
73
}
74

75
#[derive(Debug, serde::Serialize, serde::Deserialize, PartialEq, Eq)]
76
pub struct BatchConfig {
77
    /// maximum batch size in number of events
78
    pub max_size: usize,
79

80
    /// maximum duration, in seconds, to wait for a batch to fill
81
    pub max_fill_secs: u64,
82
}
83

84
#[derive(Debug, serde::Serialize, serde::Deserialize, PartialEq, Eq)]
85
pub struct Config {
86
    pub source: SourceConfig,
87
    pub sink: SinkConfig,
88
    pub batch: BatchConfig,
89
}
90

91
#[cfg(test)]
92
mod tests {
93
    use crate::replicator_config::{BatchConfig, Config, SinkConfig, SourceConfig};
94

95
    #[test]
96
    pub fn deserialize_settings_test() {
1✔
97
        let settings = r#"{
1✔
98
            "source": {
1✔
99
                "Postgres": {
1✔
100
                    "host": "localhost",
1✔
101
                    "port": 5432,
1✔
102
                    "name": "postgres",
1✔
103
                    "username": "postgres",
1✔
104
                    "slot_name": "replicator_slot",
1✔
105
                    "publication": "replicator_publication"
1✔
106
                }
1✔
107
            },
1✔
108
            "sink": {
1✔
109
                "BigQuery": {
1✔
110
                    "project_id": "project-id",
1✔
111
                    "dataset_id": "dataset-id"
1✔
112
                }
1✔
113
            },
1✔
114
            "batch": {
1✔
115
                "max_size": 1000,
1✔
116
                "max_fill_secs": 10
1✔
117
            }
1✔
118
        }"#;
1✔
119
        let actual = serde_json::from_str::<Config>(settings);
1✔
120
        let expected = Config {
1✔
121
            source: SourceConfig::Postgres {
1✔
122
                host: "localhost".to_string(),
1✔
123
                port: 5432,
1✔
124
                name: "postgres".to_string(),
1✔
125
                username: "postgres".to_string(),
1✔
126
                slot_name: "replicator_slot".to_string(),
1✔
127
                publication: "replicator_publication".to_string(),
1✔
128
            },
1✔
129
            sink: SinkConfig::BigQuery {
1✔
130
                project_id: "project-id".to_string(),
1✔
131
                dataset_id: "dataset-id".to_string(),
1✔
132
            },
1✔
133
            batch: BatchConfig {
1✔
134
                max_size: 1000,
1✔
135
                max_fill_secs: 10,
1✔
136
            },
1✔
137
        };
1✔
138
        assert!(actual.is_ok());
1✔
139
        assert_eq!(expected, actual.unwrap());
1✔
140
    }
1✔
141

142
    #[test]
143
    pub fn serialize_settings_test() {
1✔
144
        let actual = Config {
1✔
145
            source: SourceConfig::Postgres {
1✔
146
                host: "localhost".to_string(),
1✔
147
                port: 5432,
1✔
148
                name: "postgres".to_string(),
1✔
149
                username: "postgres".to_string(),
1✔
150
                slot_name: "replicator_slot".to_string(),
1✔
151
                publication: "replicator_publication".to_string(),
1✔
152
            },
1✔
153
            sink: SinkConfig::BigQuery {
1✔
154
                project_id: "project-id".to_string(),
1✔
155
                dataset_id: "dataset-id".to_string(),
1✔
156
            },
1✔
157
            batch: BatchConfig {
1✔
158
                max_size: 1000,
1✔
159
                max_fill_secs: 10,
1✔
160
            },
1✔
161
        };
1✔
162
        let expected = r#"{"source":{"Postgres":{"host":"localhost","port":5432,"name":"postgres","username":"postgres","slot_name":"replicator_slot","publication":"replicator_publication"}},"sink":{"BigQuery":{"project_id":"project-id","dataset_id":"dataset-id"}},"batch":{"max_size":1000,"max_fill_secs":10}}"#;
1✔
163
        let actual = serde_json::to_string(&actual);
1✔
164
        assert!(actual.is_ok());
1✔
165
        assert_eq!(expected, actual.unwrap());
1✔
166
    }
1✔
167
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc