Skip to content

Commit

Permalink
fix: broken tests and potential memory leaks
Browse files Browse the repository at this point in the history
  • Loading branch information
fschade committed Feb 26, 2024
1 parent 7738f24 commit dbdef9a
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 13 deletions.
23 changes: 11 additions & 12 deletions ocis-pkg/log/log_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"os/exec"
"testing"

"github.com/tidwall/gjson"
"github.com/onsi/gomega"

"github.com/owncloud/ocis/v2/ocis-pkg/log"
)
Expand All @@ -16,26 +16,27 @@ func TestDefault(t *testing.T) {
return
}

g := gomega.NewWithT(t)

tests := []struct {
name string
args []string
validate func(result string) bool
validate func(result string)
}{
{
name: "default",
args: []string{"OCIS_LOG_PRETTY=false", "OCIS_LOG_COLOR=false"},
validate: func(result string) bool {
json := gjson.Parse(result)
return json.Get("level").String() == "info" &&
json.Get("message").String() == "this is a test"
validate: func(result string) {
g.Expect(result).To(gomega.ContainSubstring("info"))
g.Expect(result).To(gomega.ContainSubstring("this is a test"))
},
},
{
name: "default",
args: []string{"OCIS_LOG_PRETTY=false", "OCIS_LOG_COLOR=false", "OCIS_LOG_LEVEL=error"},
validate: func(result string) bool {
json := gjson.Parse(result)
return json.String() == "" && result == "PASS\n"
validate: func(result string) {
g.Expect(result).ToNot(gomega.ContainSubstring("info"))
g.Expect(result).ToNot(gomega.ContainSubstring("this is a test"))
},
},
}
Expand All @@ -55,9 +56,7 @@ func TestDefault(t *testing.T) {
t.Fatal(err)
}

if valid := tt.validate(string(out)); !valid {
t.Fatalf("test %v failed", tt.name)
}
tt.validate(string(out))
})
}
}
8 changes: 8 additions & 0 deletions ocis-pkg/x/io/fsx/fallback_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,15 @@ func TestFallbackFS_Open(t *testing.T) {
defer cleanup()

foo, _ := fsys.Open(m["foo.txt"])
defer foo.Close()
testFallbackFSContent(t, foo, "foo - fs")

bar, _ := fsys.Open(m["bar.txt"])
defer bar.Close()
testFallbackFSContent(t, bar, "bar - fs")

baz, _ := fsys.Open(m["baz.txt"])
defer baz.Close()
testFallbackFSContent(t, baz, "baz - embedded")
}

Expand All @@ -99,12 +102,15 @@ func TestFallbackFS_OpenEmbedded(t *testing.T) {
defer cleanup()

foo, _ := fsys.OpenEmbedded(m["foo.txt"])
defer foo.Close()
testFallbackFSContent(t, foo, "foo - embedded")

bar, _ := fsys.OpenEmbedded(m["bar.txt"])
defer bar.Close()
testFallbackFSContent(t, bar, "bar - embedded")

baz, _ := fsys.OpenEmbedded(m["baz.txt"])
defer baz.Close()
testFallbackFSContent(t, baz, "baz - embedded")
}

Expand All @@ -117,6 +123,7 @@ func TestFallbackFS_Create(t *testing.T) {

baz, _ := fsys.Open("baz.txt")
testFallbackFSContent(t, baz, "baz - embedded")
_ = baz.Close()

// parent directory access is here to test the jail join
f, err := fsys.Create("../././././././baz.txt")
Expand All @@ -133,4 +140,5 @@ func TestFallbackFS_Create(t *testing.T) {

baz, _ = fsys.Open("baz.txt")
testFallbackFSContent(t, baz, "baz - fs")
_ = baz.Close()
}
1 change: 1 addition & 0 deletions services/search/pkg/engine/bleve.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"github.com/cs3org/reva/v2/pkg/utils"

libregraph "github.com/owncloud/libre-graph-api-go"

searchMessage "github.com/owncloud/ocis/v2/protogen/gen/ocis/messages/search/v0"
searchService "github.com/owncloud/ocis/v2/protogen/gen/ocis/services/search/v0"
"github.com/owncloud/ocis/v2/services/search/pkg/content"
Expand Down
1 change: 1 addition & 0 deletions services/web/pkg/apps/apps.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ func Build(fSystem fs.FS, name string, conf map[string]any) (Application, error)
// manifest.json is required
return Application{}, errors.Join(err, ErrMissingManifest)
}
defer reader.Close()

var application Application
if json.NewDecoder(reader).Decode(&application) != nil {
Expand Down
4 changes: 3 additions & 1 deletion services/web/pkg/assets/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,12 @@ func (f *fileServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {

// not every fs contains a file named index.html,
// therefore, we need to check if the file exists and stop the recursion if it doesn't
if _, err := f.fsys.Open(r.URL.Path); err != nil {
file, err := f.fsys.Open(r.URL.Path)
if err != nil {
http.NotFound(w, r)
return
}
defer file.Close()

f.ServeHTTP(w, r)
}
Expand Down
1 change: 1 addition & 0 deletions services/web/pkg/service/v0/branding.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ func (p Web) updateLogoThemeConfig(logoPath string) error {
if err != nil {
return err
}
defer dst.Close()

return json.NewEncoder(dst).Encode(m)
}
Expand Down

0 comments on commit dbdef9a

Please sign in to comment.