(t *testing.T)
| 18 | } |
| 19 | |
| 20 | func TestVersionUpdateCheck(t *testing.T) { |
| 21 | fakeEndpoint := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 22 | fmt.Fprintln(w, `{"tag_name": "v2.0.0"}`) |
| 23 | }) |
| 24 | ts := httptest.NewServer(fakeEndpoint) |
| 25 | defer ts.Close() |
| 26 | cli.ReleaseURL = ts.URL |
| 27 | |
| 28 | testCases := []struct { |
| 29 | desc string |
| 30 | version string |
| 31 | expected string |
| 32 | }{ |
| 33 | { |
| 34 | desc: "It returns new version available for versions older than latest.", |
| 35 | version: "1.0.0", |
| 36 | expected: "A new CLI version is available. Run `exercism upgrade` to update to 2.0.0", |
| 37 | }, |
| 38 | { |
| 39 | desc: "It returns up to date for versions matching latest.", |
| 40 | version: "2.0.0", |
| 41 | expected: "Your CLI version is up to date.", |
| 42 | }, |
| 43 | { |
| 44 | desc: "It returns up to date for versions newer than latest.", |
| 45 | version: "2.0.1", |
| 46 | expected: "Your CLI version is up to date.", |
| 47 | }, |
| 48 | } |
| 49 | |
| 50 | for _, tc := range testCases { |
| 51 | t.Run(tc.desc, func(t *testing.T) { |
| 52 | c := &cli.CLI{ |
| 53 | Version: tc.version, |
| 54 | } |
| 55 | |
| 56 | actual, err := checkForUpdate(c) |
| 57 | |
| 58 | assert.NoError(t, err) |
| 59 | assert.NotEmpty(t, actual) |
| 60 | assert.Equal(t, tc.expected, actual) |
| 61 | }) |
| 62 | } |
| 63 | } |
nothing calls this directly
no test coverage detected