MCPcopy Create free account
hub / github.com/TheThingsNetwork/lorawan-stack / TestCheckUpdate

Function TestCheckUpdate

pkg/version/remote_test.go:32–77  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

30)
31
32func TestCheckUpdate(t *testing.T) {
33 _, ctx := test.New(t)
34 const timeout = time.Second
35
36 srv := httptest.NewServer(http.FileServer(http.Dir("testdata")))
37 defer srv.Close()
38 sourceOpt := version.WithURLs(fmt.Sprintf("%s/tts.json", srv.URL), "https://example.com")
39
40 for _, tc := range []struct {
41 Reference semver.Version
42 Minor, Patch bool
43 }{
44 {
45 Reference: semver.MustParse("3.14.0"), // Unreleased version
46 },
47 {
48 Reference: semver.MustParse("3.13.2"), // Latest version
49 },
50 {
51 Reference: semver.MustParse("3.13.1"), // Previous patch
52 Patch: true,
53 },
54 {
55 Reference: semver.MustParse("3.12.3"), // Previous patch
56 Minor: true,
57 },
58 } {
59 t.Run(tc.Reference.String(), func(t *testing.T) {
60 a := assertions.New(t)
61
62 ctx, cancel := context.WithTimeout(ctx, timeout)
63 defer cancel()
64 version.ClearRecentCheckCache()
65 update, err := version.CheckUpdate(ctx, sourceOpt, version.WithReference(tc.Reference))
66 a.So(err, should.BeNil)
67
68 if !tc.Minor && !tc.Patch {
69 a.So(update, should.BeNil)
70 } else {
71 a.So(update, should.NotBeNil)
72 a.So(update.Minor, should.Equal, tc.Minor)
73 a.So(update.Patch, should.Equal, tc.Patch)
74 }
75 })
76 }
77}

Callers

nothing calls this directly

Calls 10

NewFunction · 0.92
WithURLsFunction · 0.92
ClearRecentCheckCacheFunction · 0.92
CheckUpdateFunction · 0.92
WithReferenceFunction · 0.92
DirMethod · 0.80
CloseMethod · 0.65
RunMethod · 0.65
StringMethod · 0.65
NewMethod · 0.65

Tested by

no test coverage detected