-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(webconnectivitylte): wire-in SummaryKeys (#1493)
Closes ooni/probe#2667. While there, repair flaky unit test and explain why it was flaky.
- Loading branch information
1 parent
0f5529f
commit b89a15f
Showing
5 changed files
with
117 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package webconnectivitylte | ||
|
||
import "github.com/ooni/probe-cli/v3/internal/model" | ||
|
||
var _ model.MeasurementSummaryKeysProvider = &TestKeys{} | ||
|
||
// SummaryKeys contains summary keys for this experiment. | ||
type SummaryKeys struct { | ||
Accessible bool `json:"accessible"` | ||
Blocking string `json:"blocking"` | ||
IsAnomaly bool `json:"-"` | ||
} | ||
|
||
// MeasurementSummaryKeys implements model.MeasurementSummaryKeysProvider. | ||
func (tk *TestKeys) MeasurementSummaryKeys() model.MeasurementSummaryKeys { | ||
// TODO(https://github.com/ooni/probe/issues/1684) | ||
sk := &SummaryKeys{} | ||
switch v := tk.Blocking.(type) { | ||
case string: | ||
sk.IsAnomaly = true | ||
sk.Blocking = v | ||
default: | ||
// nothing | ||
} | ||
sk.Accessible = tk.Accessible.UnwrapOr(false) | ||
return sk | ||
} | ||
|
||
// Anomaly implements model.MeasurementSummaryKeys. | ||
func (sk *SummaryKeys) Anomaly() bool { | ||
return sk.IsAnomaly | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package webconnectivitylte | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/ooni/probe-cli/v3/internal/optional" | ||
) | ||
|
||
func TestSummaryKeys(t *testing.T) { | ||
type testcase struct { | ||
name string | ||
accessible optional.Value[bool] | ||
blocking any | ||
expectAccessible bool | ||
expectBlocking string | ||
expectIsAnomaly bool | ||
} | ||
|
||
cases := []testcase{{ | ||
name: "with all nil", | ||
accessible: optional.None[bool](), | ||
blocking: nil, | ||
expectAccessible: false, | ||
expectBlocking: "", | ||
expectIsAnomaly: false, | ||
}, { | ||
name: "with success", | ||
accessible: optional.Some(true), | ||
blocking: false, | ||
expectAccessible: true, | ||
expectBlocking: "", | ||
expectIsAnomaly: false, | ||
}, { | ||
name: "with website down", | ||
accessible: optional.Some(false), | ||
blocking: false, | ||
expectAccessible: false, | ||
expectBlocking: "", | ||
expectIsAnomaly: false, | ||
}, { | ||
name: "with anomaly", | ||
accessible: optional.Some(false), | ||
blocking: "http-failure", | ||
expectAccessible: false, | ||
expectBlocking: "http-failure", | ||
expectIsAnomaly: true, | ||
}} | ||
|
||
for _, tc := range cases { | ||
t.Run(tc.name, func(t *testing.T) { | ||
tk := &TestKeys{ | ||
Accessible: tc.accessible, | ||
Blocking: tc.blocking, | ||
} | ||
sk := tk.MeasurementSummaryKeys().(*SummaryKeys) | ||
if sk.Accessible != tc.expectAccessible { | ||
t.Fatal("expected", tc.expectAccessible, "got", sk.Accessible) | ||
} | ||
if sk.Blocking != tc.expectBlocking { | ||
t.Fatal("expected", tc.expectBlocking, "got", sk.Blocking) | ||
} | ||
if sk.IsAnomaly != tc.expectIsAnomaly { | ||
t.Fatal("expected", tc.expectIsAnomaly, "got", sk.IsAnomaly) | ||
} | ||
if sk.Anomaly() != sk.IsAnomaly { | ||
t.Fatal("expected Anomaly() to equal IsAnomaly") | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters