MCPcopy Index your code
hub / github.com/coder/coder / TestChecker_Latest

Function TestChecker_Latest

coderd/updatecheck/updatecheck_test.go:79–152  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

77}
78
79func TestChecker_Latest(t *testing.T) {
80 t.Parallel()
81
82 rr := github.RepositoryRelease{
83 TagName: github.String("v1.2.3"),
84 HTMLURL: github.String("https://someurl.com"),
85 }
86
87 tests := []struct {
88 name string
89 release github.RepositoryRelease
90 wantR updatecheck.Result
91 wantErr bool
92 }{
93 {
94 name: "check latest",
95 release: rr,
96 wantR: updatecheck.Result{
97 Version: "v1.2.3",
98 URL: "https://someurl.com",
99 },
100 wantErr: false,
101 },
102 {
103 name: "missing release data",
104 release: github.RepositoryRelease{},
105 wantErr: true,
106 },
107 {
108 name: "error",
109 release: rr,
110 wantErr: true,
111 },
112 }
113 for _, tt := range tests {
114 t.Run(tt.name, func(t *testing.T) {
115 t.Parallel()
116
117 srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
118 if tt.wantErr {
119 w.WriteHeader(http.StatusInternalServerError)
120 return
121 }
122
123 rrJSON, err := json.Marshal(rr)
124 assert.NoError(t, err)
125
126 w.Header().Set("Content-Type", "application/json")
127 w.WriteHeader(http.StatusOK)
128 w.Write(rrJSON)
129 }))
130 defer srv.Close()
131
132 db, _ := dbtestutil.NewDB(t)
133 logger := slogtest.Make(t, &slogtest.Options{IgnoreErrors: true}).Named(t.Name())
134 c := updatecheck.New(db, logger, updatecheck.Options{
135 URL: srv.URL,
136 })

Callers

nothing calls this directly

Calls 15

CloseMethod · 0.95
NewDBFunction · 0.92
NewFunction · 0.92
ContextFunction · 0.92
NamedMethod · 0.80
LatestMethod · 0.80
RunMethod · 0.65
SetMethod · 0.65
WriteMethod · 0.65
NameMethod · 0.65
CloseMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected