-
Notifications
You must be signed in to change notification settings - Fork 280
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added homedir resolve process for license paths (#182)
* added homedir resolve process for license paths * added homedir module * remove excessive comments * improved license init logic * moved path resolving logic to a separate path * added tests
- Loading branch information
Showing
8 changed files
with
134 additions
and
23 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,60 @@ | ||
package clab | ||
|
||
import ( | ||
"path/filepath" | ||
"strings" | ||
"testing" | ||
) | ||
|
||
func TestLicenseInit(t *testing.T) { | ||
tests := map[string]struct { | ||
got string | ||
want string | ||
}{ | ||
"node_license": { | ||
got: "test_data/topo1.yml", | ||
want: "node1.lic", | ||
}, | ||
"kind_license": { | ||
got: "test_data/topo2.yml", | ||
want: "kind.lic", | ||
}, | ||
"default_license": { | ||
got: "test_data/topo3.yml", | ||
want: "default.lic", | ||
}, | ||
"kind_overwrite": { | ||
got: "test_data/topo4.yml", | ||
want: "node1.lic", | ||
}, | ||
} | ||
|
||
for name, tc := range tests { | ||
t.Run(name, func(t *testing.T) { | ||
opts := []ClabOption{ | ||
WithTopoFile(tc.got), | ||
} | ||
c := NewContainerLab(opts...) | ||
if err := c.ParseTopology(); err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
nodeCfg := c.Config.Topology.Nodes["node1"] | ||
node := Node{} | ||
node.Kind = strings.ToLower(c.kindInitialization(&nodeCfg)) | ||
|
||
lic, err := c.licenseInit(&nodeCfg, &node) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
if lic != tc.want { | ||
t.Fatalf("wanted '%s' got '%s'", tc.want, lic) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func abspath(s string) string { | ||
p, _ := filepath.Abs(s) | ||
return p | ||
} |
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,7 @@ | ||
name: topo1 | ||
topology: | ||
nodes: | ||
node1: | ||
kind: srl | ||
type: ixr6 | ||
license: node1.lic |
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,9 @@ | ||
name: topo2 | ||
topology: | ||
kinds: | ||
srl: | ||
license: kind.lic | ||
nodes: | ||
node1: | ||
kind: srl | ||
type: ixr6 |
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,8 @@ | ||
name: topo3 | ||
topology: | ||
defaults: | ||
license: default.lic | ||
nodes: | ||
node1: | ||
kind: srl | ||
type: ixr6 |
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,12 @@ | ||
name: topo3 | ||
topology: | ||
defaults: | ||
license: default.lic | ||
kinds: | ||
srl: | ||
license: kind.lic | ||
nodes: | ||
node1: | ||
kind: srl | ||
type: ixr6 | ||
license: node1.lic |
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