Skip to content

Commit

Permalink
Fix broken code
Browse files Browse the repository at this point in the history
  • Loading branch information
thegridman committed Sep 23, 2024
1 parent 5a5b9c6 commit bdae89c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 39 deletions.
5 changes: 3 additions & 2 deletions pkg/runner/cmd_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/spf13/cobra"
"k8s.io/apimachinery/pkg/api/resource"
"os"
"path/filepath"
"strconv"
"strings"
)
Expand Down Expand Up @@ -44,11 +45,11 @@ func server(details *RunDetails, _ *cobra.Command) {
// otherwise run Coherence DefaultMain.
mc, found := details.lookupEnv(v1.EnvVarAppMainClass)
appDir := details.getenvOrDefault(v1.EnvVarCohAppDir, "/app")
jibMainClassFileName := appDir + "/jib-main-class-file"
jibMainClassFileName := filepath.Join(appDir, "jib-main-class-file")
fi, err := os.Stat(jibMainClassFileName)
mainCls := ""
if err == nil && (fi.Size() != 0) {
mainCls, _ = readFirstLineFromFile(fi.Name())
mainCls, _ = readFirstLineFromFile(jibMainClassFileName)
}
if !found && (len(mainCls) != 0) {
mc = mainCls
Expand Down
8 changes: 5 additions & 3 deletions pkg/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"net/http"
"os"
"os/exec"
"path/filepath"
ctrl "sigs.k8s.io/controller-runtime"
"strconv"
"strings"
Expand Down Expand Up @@ -320,9 +321,10 @@ func createCommand(details *RunDetails) (string, *exec.Cmd, error) {
// are running a Spring Boot application.
if !details.isBuildPacks() && details.AppType != AppTypeSpring && details.isEnvTrueOrBlank(v1.EnvVarJvmClasspathJib) {
appDir := details.getenvOrDefault(v1.EnvVarCohAppDir, "/app")
fi, e := os.Stat(appDir + "/jib-classpath-file")
cpFile := filepath.Join(appDir, "jib-classpath-file")
fi, e := os.Stat(cpFile)
if e == nil && (fi.Size() != 0) {
clsPath, _ := readFirstLineFromFile(fi.Name())
clsPath, _ := readFirstLineFromFile(cpFile)
if len(clsPath) != 0 {
details.addClasspath(clsPath)
}
Expand Down Expand Up @@ -631,7 +633,7 @@ func readFirstLineFromFile(path string) (string, error) {
if st.IsDir() {
return "", fmt.Errorf("%s is a directory", path)
}
file, err := os.Open(st.Name())
file, err := os.Open(path)
if err != nil {
return "", err
}
Expand Down
34 changes: 0 additions & 34 deletions pkg/runner/runner_coherence_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -605,40 +605,6 @@ func TestCoherenceSiteAndRackEnvVarSetFromOtherEnvVarWhenRackIsMissing(t *testin
g.Expect(e.OsCmd.Args).To(ConsistOf(expectedArgs))
}

func TestCoherenceSiteFromFile(t *testing.T) {
g := NewGomegaWithT(t)

d := &coh.Coherence{
ObjectMeta: metav1.ObjectMeta{Name: "test"},
Spec: coh.CoherenceStatefulSetResourceSpec{
CoherenceResourceSpec: coh.CoherenceResourceSpec{
Env: []corev1.EnvVar{
{
Name: coh.EnvVarCohSite,
Value: "test-site.txt",
},
},
},
},
}

args := []string{"server", "--dry-run"}
env := EnvVarsFromDeploymentWithSkipSite(d, false)

expectedCommand := GetJavaCommand()
expectedArgs := append(GetMinimalExpectedArgs(), "-Dcoherence.site=site-from-file")
expectedArgs = append(expectedArgs, "-Dcoherence.rack=site-from-file")

e, err := ExecuteWithArgsAndNewViper(env, args)
g.Expect(err).NotTo(HaveOccurred())
g.Expect(e).NotTo(BeNil())
g.Expect(e.OsCmd).NotTo(BeNil())

g.Expect(e.OsCmd.Dir).To(Equal(TestAppDir))
g.Expect(e.OsCmd.Path).To(Equal(expectedCommand))
g.Expect(e.OsCmd.Args).To(ConsistOf(expectedArgs))
}

func TestCoherenceSiteAndRackFromFile(t *testing.T) {
g := NewGomegaWithT(t)

Expand Down

0 comments on commit bdae89c

Please sign in to comment.