(t *testing.T)
| 11 | ) |
| 12 | |
| 13 | func TestSetRefreshInterval(t *testing.T) { |
| 14 | is := is.New(t) |
| 15 | baseTestPath := filepath.Join("testdata", "set-refresh-interval-test") |
| 16 | t.Run("single-file plugin", func(t *testing.T) { |
| 17 | var ( |
| 18 | testpath = filepath.Join(baseTestPath, "single-file-plugin") |
| 19 | oldPluginName = "set-refresh-interval.1m.sh" |
| 20 | oldPluginPath = filepath.Join(testpath, oldPluginName) |
| 21 | newPluginName = "set-refresh-interval.1d.sh" |
| 22 | newPluginPath = filepath.Join(testpath, newPluginName) |
| 23 | ) |
| 24 | err := os.MkdirAll(testpath, 0777) |
| 25 | is.NoErr(err) |
| 26 | t.Cleanup(func() { |
| 27 | os.RemoveAll(testpath) |
| 28 | }) |
| 29 | _, err = os.Create(oldPluginPath) |
| 30 | is.NoErr(err) |
| 31 | renamedPlugin, refreshInterval, err := SetRefreshInterval(testpath, oldPluginName, RefreshInterval{N: 1, Unit: "days"}) |
| 32 | is.NoErr(err) |
| 33 | is.Equal(renamedPlugin, newPluginName) |
| 34 | is.Equal(refreshInterval, RefreshInterval{N: 1, Unit: "days"}) |
| 35 | _, err = os.Stat(newPluginPath) |
| 36 | is.NoErr(err) |
| 37 | }) |
| 38 | t.Run("update vars json file too", func(t *testing.T) { |
| 39 | var ( |
| 40 | testpath = filepath.Join(baseTestPath, "single-file-plugin") |
| 41 | oldPluginName = "set-refresh-interval.1m.sh" |
| 42 | oldPluginPath = filepath.Join(testpath, oldPluginName) |
| 43 | oldPluginVarsName = "set-refresh-interval.1m.sh" + variableJSONFileExt |
| 44 | oldPluginVarsPath = filepath.Join(testpath, oldPluginVarsName) |
| 45 | newPluginName = "set-refresh-interval.1d.sh" |
| 46 | newPluginPath = filepath.Join(testpath, newPluginName) |
| 47 | newPluginVarsName = "set-refresh-interval.1d.sh" + variableJSONFileExt |
| 48 | newPluginVarsPath = filepath.Join(testpath, newPluginVarsName) |
| 49 | ) |
| 50 | err := os.MkdirAll(testpath, 0777) |
| 51 | is.NoErr(err) |
| 52 | t.Cleanup(func() { |
| 53 | os.RemoveAll(testpath) |
| 54 | }) |
| 55 | _, err = os.Create(oldPluginPath) |
| 56 | is.NoErr(err) |
| 57 | _, err = os.Create(oldPluginVarsPath) |
| 58 | is.NoErr(err) |
| 59 | renamedPlugin, refreshInterval, err := SetRefreshInterval(testpath, oldPluginName, RefreshInterval{N: 1, Unit: "days"}) |
| 60 | is.NoErr(err) |
| 61 | is.Equal(renamedPlugin, newPluginName) |
| 62 | is.Equal(refreshInterval, RefreshInterval{N: 1, Unit: "days"}) |
| 63 | _, err = os.Stat(newPluginPath) |
| 64 | is.NoErr(err) |
| 65 | _, err = os.Stat(newPluginVarsPath) |
| 66 | is.NoErr(err) |
| 67 | }) |
| 68 | t.Run("disabled plugin", func(t *testing.T) { |
| 69 | var ( |
| 70 | testpath = filepath.Join(baseTestPath, "single-file-plugin") |
nothing calls this directly
no test coverage detected