github.com/keybase/client/go@v0.0.0-20240309051027-028f7c731f8b/updater/sources/remote_test.go (about)

     1  // Copyright 2016 Keybase, Inc. All rights reserved. Use of
     2  // this source code is governed by the included BSD license.
     3  
     4  package sources
     5  
     6  import (
     7  	"fmt"
     8  	"net/http"
     9  	"net/http/httptest"
    10  	"path/filepath"
    11  	"runtime"
    12  	"testing"
    13  
    14  	"github.com/keybase/client/go/updater"
    15  	"github.com/keybase/client/go/updater/util"
    16  	"github.com/stretchr/testify/assert"
    17  	"github.com/stretchr/testify/require"
    18  )
    19  
    20  func TestRemoteUpdateSource(t *testing.T) {
    21  	_, filename, _, _ := runtime.Caller(0)
    22  	jsonPath := filepath.Join(filepath.Dir(filename), "../test/update.json")
    23  	data, err := util.ReadFile(jsonPath)
    24  	require.NoError(t, err)
    25  
    26  	server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
    27  		w.Header().Set("Content-Type", "application/json")
    28  		fmt.Fprintln(w, string(data))
    29  	}))
    30  
    31  	local := NewRemoteUpdateSource(server.URL, log)
    32  	assert.Equal(t, local.Description(), "Remote")
    33  
    34  	update, err := local.FindUpdate(updater.UpdateOptions{})
    35  	require.NoError(t, err)
    36  	require.NotNil(t, update)
    37  }