MCPcopy
hub / github.com/syncthing/syncthing / TestConfigChanges

Function TestConfigChanges

lib/api/api_test.go:1686–1804  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1684}
1685
1686func TestConfigChanges(t *testing.T) {
1687 t.Parallel()
1688
1689 const testAPIKey = "foobarbaz"
1690 cfg := config.Configuration{
1691 GUI: config.GUIConfiguration{
1692 RawAddress: "127.0.0.1:0",
1693 RawUseTLS: false,
1694 APIKey: testAPIKey,
1695 },
1696 }
1697 tmpFile, err := os.CreateTemp("", "syncthing-testConfig-")
1698 if err != nil {
1699 panic(err)
1700 }
1701 defer os.Remove(tmpFile.Name())
1702 w := config.Wrap(tmpFile.Name(), cfg, protocol.LocalDeviceID, events.NoopLogger)
1703 tmpFile.Close()
1704 cfgCtx, cfgCancel := context.WithCancel(context.Background())
1705 go w.Serve(cfgCtx)
1706 defer cfgCancel()
1707 baseURL := startHTTP(t, w)
1708
1709 cli := &http.Client{
1710 Timeout: time.Minute,
1711 }
1712
1713 do := func(req *http.Request, status int) *http.Response {
1714 t.Helper()
1715 req.Header.Set("X-API-Key", testAPIKey)
1716 resp, err := cli.Do(req)
1717 if err != nil {
1718 t.Fatal(err)
1719 }
1720 if resp.StatusCode != status {
1721 t.Errorf("Expected status %v, got %v", status, resp.StatusCode)
1722 }
1723 return resp
1724 }
1725
1726 mod := func(method, path string, data interface{}) {
1727 t.Helper()
1728 bs, err := json.Marshal(data)
1729 if err != nil {
1730 t.Fatal(err)
1731 }
1732 req, _ := http.NewRequest(method, baseURL+path, bytes.NewReader(bs))
1733 do(req, http.StatusOK).Body.Close()
1734 }
1735
1736 get := func(path string) *http.Response {
1737 t.Helper()
1738 req, _ := http.NewRequest(http.MethodGet, baseURL+path, nil)
1739 return do(req, http.StatusOK)
1740 }
1741
1742 dev1Path := "/rest/config/devices/" + dev1.String()
1743

Callers

nothing calls this directly

Calls 14

WrapFunction · 0.92
startHTTPFunction · 0.85
unmarshalToFunction · 0.85
HelperMethod · 0.80
DoMethod · 0.80
FatalMethod · 0.80
MarshalMethod · 0.80
RemoveMethod · 0.65
NameMethod · 0.65
CloseMethod · 0.65
StringMethod · 0.65
ErrorMethod · 0.65

Tested by

no test coverage detected