func setup(t *testing.T, sockets ...fs.Entry) fs.Entry { mockFS := fs.Dir("", fs.Dir("plugins", sockets...)) fs_hook.Mock( mockFS) stubTransport(func(socket string, timeout time.Duration) (http.RoundTripper, error) { f, err := mockFS.Open(socket) return readWriteCloseRoundTripper{f}, err }) return mockFS }
func TestRegistryLoadsExistingPluginsEvenWhenOneFails(t *testing.T) { setup( t, // TODO: This first one needs to fail fs.Dir("fail", mockPlugin{ t: t, Name: "aFailure", Handler: stringHandler(http.StatusInternalServerError, `Internal Server Error`), }.file(), ), mockPlugin{ t: t, Name: "testPlugin", Handler: stringHandler(http.StatusOK, `{"Plugins":[{"id":"testPlugin","label":"testPlugin","interfaces":["reporter"],"api_version":"1"}]}`), }.file(), ) defer restore(t) root := "/plugins" r, err := NewRegistry(root, "1", nil) if err != nil { t.Fatal(err) } defer r.Close() r.Report() checkLoadedPlugins(t, r.ForEach, []xfer.PluginSpec{ { ID: "aFailure", Label: "aFailure", Status: "error: plugin returned non-200 status code: 500 Internal Server Error", }, { ID: "testPlugin", Label: "testPlugin", Interfaces: []string{"reporter"}, APIVersion: "1", Status: "ok", }, }) }
var mockFS = fs.Dir("", fs.Dir("proc", fs.Dir("1", fs.Dir("fd", fs.File{ FName: "16", FStat: syscall.Stat_t{ Ino: 5107, Mode: syscall.S_IFSOCK, }, }, ), fs.File{ FName: "cmdline", FContents: "foo", }, fs.Dir("ns", fs.File{ FName: "net", FStat: syscall.Stat_t{}, }, ), fs.Dir("net", fs.File{ FName: "tcp", FContents: ` sl local_address rem_address st tx_queue rx_queue tr tm->when retrnsmt uid timeout inode 0: 00000000:A6C0 00000000:0000 01 00000000:00000000 00:00000000 00000000 105 0 5107 1 ffff8800a6aaf040 100 0 0 10 2d `, }, fs.File{ FName: "tcp6", }, ), fs.File{ FName: "stat", FContents: "1 na R 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0", }, fs.File{ FName: "limits", FContents: "", }, ), ), )
var mockFS = fs.Dir("", fs.Dir("proc", fs.Dir("3", fs.File{ FName: "cmdline", FContents: "curl\000google.com", }, fs.File{ FName: "stat", FContents: "3 na R 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 2 2048", }, fs.File{ FName: "limits", FContents: `Max open files 32768 65536 files`, }, fs.Dir("fd", fs.File{FName: "0"}, fs.File{FName: "1"}, fs.File{FName: "2"}), ), fs.Dir("2", fs.File{ FName: "cmdline", FContents: "bash", }, fs.File{ FName: "stat", FContents: "2 na R 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0", }, fs.File{ FName: "limits", FContents: ``, }, fs.Dir("fd", fs.File{FName: "1"}, fs.File{FName: "2"}), ), fs.Dir("4", fs.File{ FName: "cmdline", FContents: "apache", }, fs.File{ FName: "stat", FContents: "4 na R 3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0", }, fs.File{ FName: "limits", FContents: ``, }, fs.Dir("fd", fs.File{FName: "0"}), ), fs.Dir("notapid"), fs.Dir("1", fs.File{ FName: "cmdline", FContents: "init", }, fs.File{ FName: "stat", FContents: "1 na R 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0", }, fs.File{ FName: "limits", FContents: ``, }, fs.Dir("fd"), ), ), )