File tree Expand file tree Collapse file tree 8 files changed +154
-1
lines changed Expand file tree Collapse file tree 8 files changed +154
-1
lines changed Original file line number Diff line number Diff line change @@ -27,7 +27,7 @@ var generateCmd = &cobra.Command{
27
27
os .Exit (1 )
28
28
}
29
29
30
- fmt . Printf ( "%+v \n " , kubetmuxpCfg )
30
+ kubetmuxpCfg . Process ( )
31
31
},
32
32
}
33
33
Original file line number Diff line number Diff line change @@ -2,11 +2,13 @@ module github.com/arunvelsriram/kube-tmuxp
2
2
3
3
require (
4
4
github.com/BurntSushi/toml v0.3.1 // indirect
5
+ github.com/golang/mock v1.1.1
5
6
github.com/inconshreveable/mousetrap v1.0.0 // indirect
6
7
github.com/mitchellh/go-homedir v1.0.0
7
8
github.com/pmezard/go-difflib v1.0.0 // indirect
8
9
github.com/spf13/cobra v0.0.3
9
10
github.com/spf13/viper v1.2.1
10
11
github.com/stretchr/testify v1.2.2
12
+ golang.org/x/net v0.0.0-20181108082009-03003ca0c849 // indirect
11
13
gopkg.in/yaml.v2 v2.2.1
12
14
)
Original file line number Diff line number Diff line change @@ -4,6 +4,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
4
4
github.com/davecgh/go-spew v1.1.1 /go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38 =
5
5
github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I =
6
6
github.com/fsnotify/fsnotify v1.4.7 /go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo =
7
+ github.com/golang/mock v1.1.1 h1:G5FRp8JnTd7RQH5kemVNlMeyXQAztQ3mOWV95KxsXH8 =
8
+ github.com/golang/mock v1.1.1 /go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A =
7
9
github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4 =
8
10
github.com/hashicorp/hcl v1.0.0 /go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ =
9
11
github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM =
@@ -32,6 +34,8 @@ github.com/spf13/viper v1.2.1 h1:bIcUwXqLseLF3BDAZduuNfekWG87ibtFxi59Bq+oI9M=
32
34
github.com/spf13/viper v1.2.1 /go.mod h1:P4AexN0a+C9tGAnUFNwDMYYZv3pjFuvmeiMyKRaNVlI =
33
35
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w =
34
36
github.com/stretchr/testify v1.2.2 /go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs =
37
+ golang.org/x/net v0.0.0-20181108082009-03003ca0c849 h1:FSqE2GGG7wzsYUsWiQ8MZrvEd1EOyU3NCF0AW3Wtltg =
38
+ golang.org/x/net v0.0.0-20181108082009-03003ca0c849 /go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4 =
35
39
golang.org/x/sys v0.0.0-20180906133057-8cf3aee42992 h1:BH3eQWeGbwRU2+wxxuuPOdFBmaiBH81O8BugSjHeTFg =
36
40
golang.org/x/sys v0.0.0-20180906133057-8cf3aee42992 /go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY =
37
41
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg =
Original file line number Diff line number Diff line change
1
+ package filesystem
2
+
3
+ import "os"
4
+
5
+ // FileSystem abcd
6
+ type FileSystem interface {
7
+ Remove (file string ) error
8
+ }
9
+
10
+ type defaultFS struct {}
11
+
12
+ // Remove abcd
13
+ func (d * defaultFS ) Remove (file string ) error {
14
+ if err := os .Remove (file ); err != nil {
15
+ return err
16
+ }
17
+
18
+ return nil
19
+ }
Original file line number Diff line number Diff line change
1
+ package kubeconfig
2
+
3
+ import (
4
+ "github.com/arunvelsriram/kube-tmuxp/pkg/filesystem"
5
+ )
6
+
7
+ // KubeConfig exposes methods to perform actions on kubeconfig
8
+ type KubeConfig struct {
9
+ filesystem filesystem.FileSystem
10
+ }
11
+
12
+ // Delete deletes the given kubeconfig file
13
+ func (k * KubeConfig ) Delete (file string ) error {
14
+ if err := k .filesystem .Remove (file ); err != nil {
15
+ return err
16
+ }
17
+
18
+ return nil
19
+ }
20
+
21
+ // New returns a new KubeConfig
22
+ func New (fs filesystem.FileSystem ) KubeConfig {
23
+ return KubeConfig {
24
+ filesystem : fs ,
25
+ }
26
+ }
Original file line number Diff line number Diff line change
1
+ package kubeconfig_test
2
+
3
+ import (
4
+ "fmt"
5
+ "testing"
6
+
7
+ "github.com/arunvelsriram/kube-tmuxp/pkg/filesystem"
8
+ "github.com/arunvelsriram/kube-tmuxp/pkg/internal/mock"
9
+ "github.com/arunvelsriram/kube-tmuxp/pkg/kubeconfig"
10
+ "github.com/golang/mock/gomock"
11
+ "github.com/stretchr/testify/assert"
12
+ )
13
+
14
+ func TestNew (t * testing.T ) {
15
+ var fs filesystem.FileSystem
16
+ cfg := kubeconfig .New (fs )
17
+
18
+ assert .NotNil (t , cfg )
19
+ }
20
+
21
+ func TestDelete (t * testing.T ) {
22
+ t .Run ("should delete given kubeconfig file from filesystem" , func (t * testing.T ) {
23
+ ctrl := gomock .NewController (t )
24
+ defer ctrl .Finish ()
25
+ mockFS := mock .NewFileSystem (ctrl )
26
+ mockFS .EXPECT ().Remove ("kubeconfig.yaml" ).Return (nil )
27
+
28
+ cfg := kubeconfig .New (mockFS )
29
+ err := cfg .Delete ("kubeconfig.yaml" )
30
+
31
+ assert .Nil (t , err )
32
+ })
33
+
34
+ t .Run ("should return error if kubeconfig file cannot be deleted" , func (t * testing.T ) {
35
+ ctrl := gomock .NewController (t )
36
+ defer ctrl .Finish ()
37
+ mockFS := mock .NewFileSystem (ctrl )
38
+ mockFS .EXPECT ().Remove ("kubeconfig.yaml" ).Return (fmt .Errorf ("some error" ))
39
+
40
+ cfg := kubeconfig .New (mockFS )
41
+ err := cfg .Delete ("kubeconfig.yaml" )
42
+
43
+ assert .EqualError (t , err , "some error" )
44
+ })
45
+ }
Original file line number Diff line number Diff line change 1
1
package kubetmuxp
2
2
3
3
import (
4
+ "fmt"
4
5
"io"
5
6
"io/ioutil"
6
7
@@ -52,6 +53,17 @@ func (c *Config) Load() error {
52
53
return nil
53
54
}
54
55
56
+ // Process processes kube-tmuxp configs
57
+ func (c * Config ) Process () error {
58
+ for _ , project := range c .Projects {
59
+ for _ , cluster := range project .Clusters {
60
+ fmt .Println (cluster )
61
+ }
62
+ }
63
+
64
+ return nil
65
+ }
66
+
55
67
// NewConfig creates a new Config
56
68
func NewConfig (reader io.Reader ) Config {
57
69
return Config {
You can’t perform that action at this time.
0 commit comments