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

mongodb / mongodb-atlas-cli / 16772687316

06 Aug 2025 09:12AM UTC coverage: 64.656% (-3.2%) from 67.902%
16772687316

push

github

web-flow
chore: remove test tags (#4089)

0 of 11 new or added lines in 2 files covered. (0.0%)

1184 existing lines in 46 files now uncovered.

26448 of 40906 relevant lines covered (64.66%)

0.8 hits per line

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

71.97
/tools/shared/api/stability_levels.go
1
// Copyright 2025 MongoDB Inc
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
//     http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14

15
package api
16

17
import (
18
        "errors"
19
        "fmt"
20
        "regexp"
21
        "strconv"
22
        "time"
23
)
24

25
var (
26
        versionRegex = regexp.MustCompile(`^((?P<year>\d{4})-(?P<month>\d{2})-(?P<day>\d{2})(?P<upcoming>\.upcoming)?|(?P<preview>preview))$`)
27
)
28

29
type StabilityLevel string
30

31
const (
32
        StabilityLevelPreview  StabilityLevel = "preview"
33
        StabilityLevelUpcoming StabilityLevel = "upcoming"
34
        StabilityLevelStable   StabilityLevel = "stable"
35
)
36

37
type VersionDate struct {
38
        Year  int
39
        Month time.Month
40
        Day   int
41
}
42

43
// Returns true if v(this) is less than other
44
func (v VersionDate) Less(other *VersionDate) bool {
1✔
45
        switch {
1✔
46
        case v.Year < other.Year:
1✔
47
                return true
1✔
48
        case v.Year == other.Year && v.Month < other.Month:
1✔
49
                return true
1✔
50
        case v.Year == other.Year && v.Month == other.Month && v.Day < other.Day:
1✔
51
                return true
1✔
52
        default:
1✔
53
                return false
1✔
54
        }
55
}
56

57
// Returns true if v(this) is equal to other
58
func (v VersionDate) Equal(other *VersionDate) bool {
2✔
59
        return v.Year == other.Year && v.Month == other.Month && v.Day == other.Day
2✔
60
}
2✔
61

62
// Implement Stringer interface
63
func (v VersionDate) String() string {
1✔
64
        return fmt.Sprintf("%04d-%02d-%02d", v.Year, v.Month, v.Day)
1✔
65
}
1✔
66

67
type Version interface {
68
        StabilityLevel() StabilityLevel
69
        // Returns true if v(this) is less than other
70
        Less(other Version) bool
71
        Equal(other Version) bool
72
        String() string
73
}
74

75
func ParseVersion(version string) (Version, error) {
1✔
76
        matches := versionRegex.FindStringSubmatch(version)
1✔
77
        if len(matches) == 0 {
1✔
78
                return nil, fmt.Errorf("invalid version: %s", version)
×
79
        }
×
80

81
        // Get the named group indexes
82
        yearIndex := versionRegex.SubexpIndex("year")
1✔
83
        monthIndex := versionRegex.SubexpIndex("month")
1✔
84
        dayIndex := versionRegex.SubexpIndex("day")
1✔
85
        upcomingIndex := versionRegex.SubexpIndex("upcoming")
1✔
86
        previewIndex := versionRegex.SubexpIndex("preview")
1✔
87

1✔
88
        // Get the named group values
1✔
89
        year := matches[yearIndex]
1✔
90
        month := matches[monthIndex]
1✔
91
        day := matches[dayIndex]
1✔
92
        upcoming := matches[upcomingIndex]
1✔
93
        preview := matches[previewIndex]
1✔
94

1✔
95
        // If the version is a preview, return a PreviewVersion
1✔
96
        if preview != "" {
1✔
UNCOV
97
                if year != "" || month != "" || day != "" {
×
98
                        return nil, errors.New("preview version cannot have a year, month, or day")
×
99
                }
×
100

UNCOV
101
                return NewPreviewVersion(), nil
×
102
        }
103

104
        // For upcoming and stable versions, year, month, and day are required
105
        if year == "" || month == "" || day == "" {
1✔
106
                return nil, errors.New("upcoming and stable versions must have a year, month, and day")
×
107
        }
×
108

109
        // Convert the year, month, and day to ints
110
        // We know that they're in the correct format (because the regex matched), so we can ignore the error
111
        yearInt, _ := strconv.Atoi(year)
1✔
112
        monthInt, _ := strconv.Atoi(month)
1✔
113
        dayInt, _ := strconv.Atoi(day)
1✔
114

1✔
115
        // If the version is an upcoming version, return an UpcomingVersion
1✔
116
        if upcoming != "" {
1✔
UNCOV
117
                return NewUpcomingVersion(yearInt, time.Month(monthInt), dayInt), nil
×
UNCOV
118
        }
×
119

120
        // If the version is a stable version, return a StableVersion
121
        return NewStableVersion(yearInt, time.Month(monthInt), dayInt), nil
1✔
122
}
123

124
type PreviewVersion struct {
125
}
126

127
func NewPreviewVersion() PreviewVersion {
2✔
128
        return PreviewVersion{}
2✔
129
}
2✔
130

131
func (PreviewVersion) StabilityLevel() StabilityLevel {
×
132
        return StabilityLevelPreview
×
133
}
×
134

135
func (PreviewVersion) Less(_ Version) bool {
1✔
136
        // Preview is always last, so it's never less than anything
1✔
137
        // When comparing two preview versions, they're equal, so less is also false
1✔
138
        return false
1✔
139
}
1✔
140

141
func (PreviewVersion) Equal(other Version) bool {
1✔
142
        // switch cast other Version to preview/upcoming/stable
1✔
143
        switch other.(type) {
1✔
144
        case PreviewVersion:
1✔
145
                // other preview versions are always equal
1✔
146
                return true
1✔
UNCOV
147
        case UpcomingVersion:
×
UNCOV
148
                // upcoming versions are never equal to preview versions
×
UNCOV
149
                return false
×
UNCOV
150
        case StableVersion:
×
UNCOV
151
                // stable versions are never equal to preview versions
×
UNCOV
152
                return false
×
153
        }
154

155
        panic("unreachable")
×
156
}
157

158
func (PreviewVersion) String() string {
1✔
159
        return "preview"
1✔
160
}
1✔
161

162
type UpcomingVersion struct {
163
        Date VersionDate
164
}
165

166
func NewUpcomingVersion(year int, month time.Month, day int) UpcomingVersion {
1✔
167
        return UpcomingVersion{Date: VersionDate{Year: year, Month: month, Day: day}}
1✔
168
}
1✔
169

170
func (UpcomingVersion) StabilityLevel() StabilityLevel {
×
171
        return StabilityLevelUpcoming
×
172
}
×
173

174
func (v UpcomingVersion) Less(other Version) bool {
1✔
175
        // switch cast other Version to preview/upcoming/stable
1✔
176
        switch o := other.(type) {
1✔
177
        case PreviewVersion:
1✔
178
                // preview versions are always newer (greater) than upcoming versions
1✔
179
                return true
1✔
180
        case UpcomingVersion:
1✔
181
                // for other upcoming versions, compare dates
1✔
182
                return v.Date.Less(&o.Date)
1✔
183
        case StableVersion:
1✔
184
                // for stable versions we compare dates
1✔
185
                // if the date is the same, then the stable version is always older (less) than upcoming versions
1✔
186
                if v.Date.Equal(&o.Date) {
2✔
187
                        return false
1✔
188
                }
1✔
189

190
                return v.Date.Less(&o.Date)
1✔
191
        }
192

193
        panic("unreachable")
×
194
}
195

196
func (v UpcomingVersion) Equal(other Version) bool {
1✔
197
        // switch cast other Version to preview/upcoming/stable
1✔
198
        switch o := other.(type) {
1✔
199
        case PreviewVersion:
×
200
                // preview versions are never equal to upcoming versions
×
201
                return false
×
202
        case UpcomingVersion:
1✔
203
                // for other upcoming versions, compare dates
1✔
204
                return v.Date.Equal(&o.Date)
1✔
UNCOV
205
        case StableVersion:
×
UNCOV
206
                // stable versions are never equal to upcoming versions
×
UNCOV
207
                return false
×
208
        }
209

210
        panic("unreachable")
×
211
}
212

UNCOV
213
func (v UpcomingVersion) String() string {
×
UNCOV
214
        return fmt.Sprintf("%s.upcoming", v.Date)
×
UNCOV
215
}
×
216

217
type StableVersion struct {
218
        Date VersionDate
219
}
220

221
func NewStableVersion(year int, month time.Month, day int) StableVersion {
2✔
222
        return StableVersion{Date: VersionDate{Year: year, Month: month, Day: day}}
2✔
223
}
2✔
224

225
func (StableVersion) StabilityLevel() StabilityLevel {
1✔
226
        return StabilityLevelStable
1✔
227
}
1✔
228

229
func (v StableVersion) Less(other Version) bool {
1✔
230
        // switch cast other Version to preview/upcoming/stable
1✔
231
        switch o := other.(type) {
1✔
232
        case PreviewVersion:
1✔
233
                // preview versions are always newer (greater) than stable versions
1✔
234
                return true
1✔
235
        case UpcomingVersion:
1✔
236
                // for upcoming versions we compare dates
1✔
237
                // if the date is the same, then the upcoming version is always older (less) than stable versions
1✔
238
                if v.Date.Equal(&o.Date) {
1✔
239
                        return true
×
240
                }
×
241

242
                return v.Date.Less(&o.Date)
1✔
243
        case StableVersion:
1✔
244
                // for other stable versions, compare dates
1✔
245
                return v.Date.Less(&o.Date)
1✔
246
        }
247

248
        panic("unreachable")
×
249
}
250

251
func (v StableVersion) Equal(other Version) bool {
2✔
252
        // switch cast other Version to preview/upcoming/stable
2✔
253
        switch o := other.(type) {
2✔
UNCOV
254
        case PreviewVersion:
×
UNCOV
255
                // preview versions are never equal to stable versions
×
UNCOV
256
                return false
×
UNCOV
257
        case UpcomingVersion:
×
UNCOV
258
                // upcoming versions are never equal to stable versions
×
UNCOV
259
                return false
×
260
        case StableVersion:
2✔
261
                // for other stable versions, compare dates
2✔
262
                return v.Date.Equal(&o.Date)
2✔
263
        }
264

265
        panic("unreachable")
×
266
}
267

268
func (v StableVersion) String() string {
1✔
269
        return v.Date.String()
1✔
270
}
1✔
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