Skip to content

Commit

Permalink
Merge pull request #1470 from openziti/fix.os.specific.file.not.found…
Browse files Browse the repository at this point in the history
….checks

fixes tests that would check for OS specific error messages
  • Loading branch information
andrewpmartinez authored Oct 30, 2023
2 parents b7c6daa + b2b1295 commit ee4bc22
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 9 deletions.
8 changes: 5 additions & 3 deletions ziti/cmd/create/create_config_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ package create
import (
"fmt"
cmdhelper "github.com/openziti/ziti/ziti/cmd/helpers"
"github.com/pkg/errors"
"github.com/stretchr/testify/assert"
"gopkg.in/yaml.v3"
"os"
"strings"
"syscall"
"testing"
"time"
)
Expand Down Expand Up @@ -111,15 +113,15 @@ func init() {
}

func TestControllerOutputPathDoesNotExist(t *testing.T) {
expectedErrorMsg := "stat /IDoNotExist: no such file or directory"

// Create the options with non-existent path
options := &CreateConfigControllerOptions{}
options.Output = "/IDoNotExist/MyController.yaml"

err := options.run(&ConfigTemplateValues{})

assert.EqualError(t, err, expectedErrorMsg, "Error does not match, expected %s but got %s", expectedErrorMsg, err)
//check wrapped error type and not internal strings as they vary between operating systems
assert.Error(t, err)
assert.Equal(t, errors.Unwrap(err), syscall.ENOENT)
}

func TestCreateConfigControllerTemplateValues(t *testing.T) {
Expand Down
7 changes: 4 additions & 3 deletions ziti/cmd/create/create_config_router_edge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ package create

import (
"github.com/openziti/ziti/ziti/constants"
"github.com/pkg/errors"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"os"
"strconv"
"strings"
"syscall"
"testing"
"time"
)
Expand Down Expand Up @@ -215,8 +217,6 @@ func TestEdgeRouterCannotBeWSSAndPrivate(t *testing.T) {
}

func TestEdgeRouterOutputPathDoesNotExist(t *testing.T) {
expectedErrorMsg := "stat /IDoNotExist: no such file or directory"

// Set the router options
routerOptions := clearEnvAndInitializeTestData()
routerOptions.TunnelerMode = defaultTunnelerMode
Expand All @@ -225,7 +225,8 @@ func TestEdgeRouterOutputPathDoesNotExist(t *testing.T) {

err := routerOptions.runEdgeRouter(&ConfigTemplateValues{})

assert.EqualError(t, err, expectedErrorMsg, "Error does not match, expected %s but got %s", expectedErrorMsg, err)
assert.Error(t, err)
assert.Equal(t, errors.Unwrap(err), syscall.ENOENT)
}

func TestExecuteCreateConfigRouterEdgeHasNonBlankTemplateValues(t *testing.T) {
Expand Down
6 changes: 4 additions & 2 deletions ziti/cmd/create/create_config_router_fabric_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ package create

import (
"github.com/openziti/ziti/ziti/constants"
"github.com/pkg/errors"
"github.com/stretchr/testify/assert"
"os"
"strconv"
"strings"
"syscall"
"testing"
"time"
)
Expand Down Expand Up @@ -94,7 +96,6 @@ func TestBlankFabricRouterNameBecomesHostname(t *testing.T) {

func TestFabricRouterOutputPathDoesNotExist(t *testing.T) {
routerOptions := clearEnvAndInitializeTestData()
expectedErrorMsg := "stat /IDoNotExist: no such file or directory"

// Set the router options
clearEnvAndInitializeTestData()
Expand All @@ -103,7 +104,8 @@ func TestFabricRouterOutputPathDoesNotExist(t *testing.T) {

err := routerOptions.runFabricRouter(&ConfigTemplateValues{})

assert.EqualError(t, err, expectedErrorMsg, "Error does not match, expected %s but got %s", expectedErrorMsg, err)
assert.Error(t, err)
assert.Equal(t, errors.Unwrap(err), syscall.ENOENT)
}

func TestDefaultZitiFabricRouterListenerBindPort(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion ziti/cmd/helpers/env_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (

func HomeDir() string {
if h := os.Getenv("HOME"); h != "" {
return h
return NormalizePath(h)
}
h := os.Getenv("USERPROFILE") // windows
if h == "" {
Expand Down

0 comments on commit ee4bc22

Please sign in to comment.