-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: hwipl <33433250+hwipl@users.noreply.github.com>
- Loading branch information
Showing
7 changed files
with
198 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package vpncscript | ||
|
||
import ( | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/telekom-mms/oc-daemon/internal/api" | ||
"github.com/telekom-mms/oc-daemon/internal/daemon" | ||
) | ||
|
||
// TestRunClient tests runClient. | ||
func TestRunClient(t *testing.T) { | ||
sockfile := filepath.Join(t.TempDir(), "sockfile") | ||
config := api.NewConfig() | ||
config.SocketFile = sockfile | ||
|
||
// without errors | ||
server := api.NewServer(config) | ||
go func() { | ||
for r := range server.Requests() { | ||
r.Close() | ||
} | ||
}() | ||
server.Start() | ||
if err := runClient(sockfile, &daemon.VPNConfigUpdate{}); err != nil { | ||
t.Fatal(err) | ||
} | ||
server.Stop() | ||
|
||
// with error reply | ||
server = api.NewServer(config) | ||
go func() { | ||
for r := range server.Requests() { | ||
r.Error("test error") | ||
r.Close() | ||
} | ||
}() | ||
server.Start() | ||
if err := runClient(sockfile, &daemon.VPNConfigUpdate{}); err != nil { | ||
t.Fatal(err) | ||
} | ||
server.Stop() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package vpncscript | ||
|
||
import ( | ||
"flag" | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
) | ||
|
||
// TestRun tests run. | ||
func TestRun(t *testing.T) { | ||
// test invalid arg | ||
if err := run([]string{"test", "-invalid"}); err == nil || err == flag.ErrHelp { | ||
t.Errorf("invalid argument should return error, got: %v", err) | ||
} | ||
|
||
// test with "-version" | ||
if err := run([]string{"test", "-version"}); err != nil { | ||
t.Errorf("version should not return error, got: %v", err) | ||
} | ||
|
||
// test with "-help" | ||
if err := run([]string{"test", "-help"}); err != flag.ErrHelp { | ||
t.Errorf("help should return ErrHelp, got: %v", err) | ||
} | ||
|
||
// prepare environment with not existing sockfile | ||
os.Clearenv() | ||
sockfile := filepath.Join(t.TempDir(), "sockfile") | ||
if err := os.Setenv("oc_daemon_socket_file", sockfile); err != nil { | ||
t.Fatal(err) | ||
} | ||
if err := os.Setenv("oc_daemon_verbose", "true"); err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
// test with errors | ||
for _, v := range []string{ | ||
"connect", | ||
"disconnect", | ||
"invalid", | ||
} { | ||
if err := os.Setenv("reason", v); err != nil { | ||
t.Fatal(err) | ||
} | ||
if err := run([]string{"test"}); err == nil { | ||
t.Errorf("%s: should return error", v) | ||
} | ||
} | ||
|
||
// test without errors | ||
for _, v := range []string{ | ||
"pre-init", | ||
"attempt-reconnect", | ||
"reconnect", | ||
} { | ||
if err := os.Setenv("reason", v); err != nil { | ||
t.Fatal(err) | ||
} | ||
if err := run([]string{"test"}); err != nil { | ||
t.Errorf("%s: should not return error, got: %v", v, err) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters