Skip to content

Commit

Permalink
config: platform dependent error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
magiconair committed Nov 15, 2022
1 parent bc8fc63 commit 33edbcc
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import (
"crypto/rsa"
"crypto/tls"
"encoding/pem"
"errors"
"fmt"
"io/ioutil"
"net"
"os"
"path/filepath"
"runtime"
"testing"
"time"

Expand Down Expand Up @@ -142,6 +143,16 @@ func TestOptions(t *testing.T) {
keyPEMFile = filepath.Join(d, "key.pem")
)

// the error message for "file not found" is platform dependent.
notFoundError := func(msg, name string) error {
switch runtime.GOOS {
case "windows":
return fmt.Errorf("opcua: Failed to load %s: open %s: The system cannot find the file specified.", msg, name)
default:
return fmt.Errorf("opcua: Failed to load %s: open %s: no such file or directory", msg, name)
}
}

if err := ioutil.WriteFile(certDERFile, certDER, 0644); err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -288,7 +299,7 @@ func TestOptions(t *testing.T) {
name: `CertificateFile() error`,
opt: CertificateFile("x"),
cfg: &Config{
err: errors.New("opcua: Failed to load certificate: open x: no such file or directory"),
err: notFoundError("certificate", "x"),
},
},
{
Expand Down Expand Up @@ -350,7 +361,7 @@ func TestOptions(t *testing.T) {
name: `PrivateKeyFile() error`,
opt: PrivateKeyFile("x"),
cfg: &Config{
err: errors.New("opcua: Failed to load private key: open x: no such file or directory"),
err: notFoundError("private key", "x"),
},
},
{
Expand Down Expand Up @@ -423,7 +434,7 @@ func TestOptions(t *testing.T) {
name: `RemoteCertificateFile() error`,
opt: RemoteCertificateFile("x"),
cfg: &Config{
err: errors.New("opcua: Failed to load certificate: open x: no such file or directory"),
err: notFoundError("certificate", "x"),
},
},
{
Expand Down

0 comments on commit 33edbcc

Please sign in to comment.