Skip to content

Commit 5b0e049

Browse files
authored
Merge pull request #93 from davidk/poeCycleFix
Populate model after detection for cycle and set
2 parents 5ff4b22 + 6016727 commit 5b0e049

File tree

4 files changed

+31
-2
lines changed

4 files changed

+31
-2
lines changed

poe_cycle.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ func (poe *PoeCyclePowerCommand) Run(args *GlobalOptions) error {
2222
if err != nil {
2323
return err
2424
}
25+
args.model = model
26+
2527
}
2628
if isModel30x(model) {
2729
return poe.cyclePowerGs30xEPx(args)

port_set.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ func (portSet *PortSetCommand) Run(args *GlobalOptions) error {
5050
if err != nil {
5151
return err
5252
}
53+
args.model = model
54+
5355
}
5456
if isModel30x(model) {
5557
return portSet.runPortSetGs30xEPx(args)

token.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,11 @@ func tokenFilename(configDir string, host string) string {
3232
}
3333

3434
func readTokenAndModel2GlobalOptions(args *GlobalOptions, host string) (NetgearModel, string, error) {
35-
if len(args.model) > 0 {
35+
36+
if len(args.model) > 0 && len(args.token) > 0 {
3637
return args.model, args.token, nil
3738
}
39+
3840
if args.Verbose {
3941
fmt.Println("reading token from: " + tokenFilename(args.TokenDir, host))
4042
}

token_test.go

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
package main
22

33
import (
4+
"testing"
5+
46
"github.com/corbym/gocrest/is"
57
"github.com/corbym/gocrest/then"
6-
"testing"
78
)
89

910
func Test_storing_and_loading_a_token_also_preserves_the_model(t *testing.T) {
@@ -28,3 +29,25 @@ func Test_storing_and_loading_a_token_also_preserves_the_model(t *testing.T) {
2829
then.AssertThat(t, args.token, is.EqualTo("1234567890"))
2930
then.AssertThat(t, args.model, is.EqualTo(GS30xEPx))
3031
}
32+
33+
func Test_loading_a_token_with_model(t *testing.T) {
34+
// setup
35+
args := GlobalOptions{
36+
Verbose: false,
37+
model: GS30xEPx,
38+
}
39+
const host = "ntgrrc-test-case-host"
40+
// given
41+
err := storeToken(&args, host, "1234567890")
42+
then.AssertThat(t, err, is.Nil())
43+
44+
// when
45+
model, token, err := readTokenAndModel2GlobalOptions(&args, host)
46+
47+
// then
48+
then.AssertThat(t, err, is.Nil())
49+
then.AssertThat(t, token, is.EqualTo("1234567890"))
50+
then.AssertThat(t, model, is.EqualTo(GS30xEPx))
51+
then.AssertThat(t, args.token, is.EqualTo("1234567890"))
52+
then.AssertThat(t, args.model, is.EqualTo(GS30xEPx))
53+
}

0 commit comments

Comments
 (0)