Skip to content

Commit

Permalink
update format and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Guillermo Fernández authored and ruiztulio committed Dec 23, 2023
1 parent 6301dfb commit b97259f
Show file tree
Hide file tree
Showing 11 changed files with 30 additions and 14 deletions.
3 changes: 2 additions & 1 deletion cmd/cou.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package cmd

import (
"os"

"entrypoint/pkg/cou"
"entrypoint/utils"
"os"

log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
Expand Down
3 changes: 2 additions & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package cmd

import (
"fmt"
"os"

easy "github.com/ruiztulio/logrus-easy-formatter"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"os"
)

// rootCmd represents the base command when called without any subcommands
Expand Down
3 changes: 2 additions & 1 deletion cmd/run.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package cmd

import (
"entrypoint/utils"
"os"

"entrypoint/utils"

log "github.com/sirupsen/logrus"

"github.com/spf13/cobra"
Expand Down
3 changes: 2 additions & 1 deletion cmd/start.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package cmd

import (
"entrypoint/utils"
"os"

"entrypoint/utils"

log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
Expand Down
3 changes: 2 additions & 1 deletion pkg/cou/cou.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package cou

import (
"os"

"entrypoint/utils"
log "github.com/sirupsen/logrus"
"os"
)

// RunCou will execute click-odoo-update to update the database, if you want to save the logs pass stream=false else the
Expand Down
2 changes: 0 additions & 2 deletions utils/bash.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
// GetUserUIDs returns the user UID and default GID
func GetUserUIDs(username string) (uint32, uint32, error) {
u, err := user.Lookup(username)

if err != nil {
return 0, 0, err
}
Expand Down Expand Up @@ -80,7 +79,6 @@ func RunAndLogCmdAs(cmd string, userName string, env []string) error {
return err
}
return nil

}

// Copy copies a single file from src to dst
Expand Down
2 changes: 1 addition & 1 deletion utils/docker_secrets.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func readDockerSecrets() (map[string]string, error) {
continue
}

filePath := filepath.Join(secretsPath, e.Name())
filePath := filepath.Clean(filepath.Join(secretsPath, e.Name()))

content, err := os.ReadFile(filePath)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion utils/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func appendFiles(odooConfig, filesPath string) error {
}
content := []byte(strings.Join(odooLines, "\n"))
log.Info("Saving Odoo config file content")
if err := os.WriteFile(odooConfig, content, 0644); err != nil {
if err := os.WriteFile(odooConfig, content, 0o600); err != nil {
return err
}
return nil
Expand Down
18 changes: 15 additions & 3 deletions utils/files_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package utils

import (
"github.com/stretchr/testify/assert"
"os"
"testing"

"github.com/stretchr/testify/assert"
)

func TestReadLines(t *testing.T) {
Expand All @@ -14,9 +16,19 @@ func TestReadLines(t *testing.T) {

func TestAppendFiles(t *testing.T) {
expected := []string{"0", "1", "2", "3", "4", "5", "6"}
err := appendFiles("testdata/odoo_cfg", "testdata/odoo.d")
tmpCopy, err := os.CreateTemp("", "odoo_cfg")
assert.NoError(t, err)
defer os.Remove(tmpCopy.Name())

content, err := os.ReadFile("testdata/odoo_cfg")
assert.NoError(t, err)

_, err = tmpCopy.Write(content)
assert.NoError(t, err)

err = appendFiles(tmpCopy.Name(), "testdata/odoo.d")
assert.NoError(t, err)
res, err := readLines("testdata/odoo_cfg")
res, err := readLines(tmpCopy.Name())
assert.NoError(t, err)
assert.Equal(t, expected, res)
}
2 changes: 1 addition & 1 deletion utils/odoo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func TestGetOdooUser(t *testing.T) {

func TestGetConfigFile(t *testing.T) {
res := GetConfigFile()
assert.Equal(t, "/home/odoo/.openerp_serverrc", res)
assert.Equal(t, "/home/odoo/.odoorc", res)
err := os.Setenv("ODOO_CONFIG_FILE", "/etc/odoo.conf")
assert.NoError(t, err)
res = GetConfigFile()
Expand Down
3 changes: 2 additions & 1 deletion utils/randstr_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package utils

import (
"github.com/stretchr/testify/assert"
"testing"

"github.com/stretchr/testify/assert"
)

func TestRandStringRunes(t *testing.T) {
Expand Down

0 comments on commit b97259f

Please sign in to comment.