Files
zeekay 8feb24ea1f One name for this fork, and it is ours
The server module named github.com/hanzoai/team/server/v8 — a path that
resolves to the retired workspace's repository, not this one — while
server/public still published github.com/mattermost/mattermost/server/public.
Both are github.com/hanzoteam/server/... now, which is where this code
actually lives.

That second half is what made the binary unbootable. Upstream's public path
stayed claimed by upstream, mattermost-plugin-ai imported it, and the build
linked public/model twice; public/plugin's gob.Register then ran twice under
one name and panicked at init, before main. Reverting the rename traded the
brand for a working binary. Rebranding the plugin alongside it needs no such
trade: the agents fork is github.com/hanzoteam/agents/v2 against our public
module, so no module named mattermost/mattermost is in the graph at all.

Measured: `go list -deps ./cmd/mattermost` names exactly one public/model, and
it is ours.
2026-08-28 23:35:36 -07:00

97 lines
2.8 KiB
Go

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package app
import (
"encoding/json"
"net/http"
"net/http/httptest"
"testing"
"github.com/stretchr/testify/require"
"github.com/hanzoteam/server/server/public/model"
)
func TestGetLatestVersion(t *testing.T) {
mainHelper.Parallel(t)
th := Setup(t).InitBasic(t)
version := &model.GithubReleaseInfo{
Id: 57117096,
TagName: "v6.3.0",
Name: "v6.3.0",
CreatedAt: "2022-01-13T14:19:44Z",
PublishedAt: "2022-01-14T13:45:09Z",
Body: "Hanzo Team Platform Release v6.3.0",
Url: "https://github.com/mattermost/mattermost-server/releases/tag/v6.3.0",
}
validJSON, jsonErr := json.Marshal(version)
require.NoError(t, jsonErr)
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
_, err := w.Write(validJSON)
require.NoError(t, err)
}))
defer ts.Close()
t.Run("get latest mm version happy path", func(t *testing.T) {
_, err := th.App.GetLatestVersion(th.Context, ts.URL)
require.Nil(t, err)
})
t.Run("get latest mm version from cache", func(t *testing.T) {
err := th.App.clearLatestVersionCache()
require.NoError(t, err)
originalResult, appErr := th.App.GetLatestVersion(th.Context, ts.URL)
require.Nil(t, appErr)
// Call same function but mock the GET request to return a different result.
// We are hoping the function will use the cache instead of making the GET request
v := &model.GithubReleaseInfo{
Id: 57117096,
TagName: "v6.3.1",
Name: "v6.3.1",
CreatedAt: "2022-01-13T14:19:44Z",
PublishedAt: "2022-01-14T13:45:09Z",
Body: "Hanzo Team Platform Release v6.3.0",
Url: "https://github.com/mattermost/mattermost-server/releases/tag/v6.3.0",
}
updatedJSON, jsonErr := json.Marshal(v)
require.NoError(t, jsonErr)
updatedServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
_, err := w.Write(updatedJSON)
require.NoError(t, err)
}))
defer updatedServer.Close()
cachedResult, appErr := th.App.GetLatestVersion(th.Context, updatedServer.URL)
require.Nil(t, appErr)
require.Equal(t, originalResult.TagName, cachedResult.TagName, "did not get cached result")
})
t.Run("get latest mm version error from external", func(t *testing.T) {
err := th.App.clearLatestVersionCache()
require.NoError(t, err)
errorServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusInternalServerError)
_, err := w.Write([]byte(`
{
"message": "internal server error"
}
`))
require.NoError(t, err)
}))
defer errorServer.Close()
_, appErr := th.App.GetLatestVersion(th.Context, errorServer.URL)
require.NotNil(t, appErr)
})
}