File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -25,12 +25,10 @@ func newListCmd(opts *Options) *cobra.Command {
2525 return activeErr
2626 }
2727 if ns == "" {
28- if cfg , path , err := config . Load (opts . ConfigPath ); err == nil && cfg .Spec .Namespace != "" {
28+ if cfg , err := loadOptionalConfigForList (opts , announceConfigPath ); err == nil && cfg .Spec .Namespace != "" {
2929 ns = cfg .Spec .Namespace
30- announceConfigPath (path )
3130 applyConfigKubeContext (opts , cfg )
3231 } else if err == nil {
33- announceConfigPath (path )
3432 applyConfigKubeContext (opts , cfg )
3533 }
3634 }
@@ -109,3 +107,17 @@ func sessionNameFromPodSummary(p kube.PodSummary) string {
109107 }
110108 return name
111109}
110+
111+ func loadOptionalConfigForList (opts * Options , announce func (string ) func (bool )) (* config.DevEnvironment , error ) {
112+ path , err := config .ResolvePath (opts .ConfigPath )
113+ if err != nil {
114+ return nil , err
115+ }
116+ done := announce (path )
117+ cfg , _ , err := config .Load (path )
118+ done (err == nil )
119+ if err != nil {
120+ return nil , err
121+ }
122+ return cfg , nil
123+ }
Original file line number Diff line number Diff line change 1+ package cli
2+
3+ import (
4+ "os"
5+ "path/filepath"
6+ "testing"
7+
8+ "github.com/acmore/okdev/internal/config"
9+ )
10+
11+ func TestLoadOptionalConfigForListAnnouncesAndStops (t * testing.T ) {
12+ dir := t .TempDir ()
13+ cfgPath := filepath .Join (dir , config .DefaultFile )
14+ if err := os .WriteFile (cfgPath , []byte (`
15+ apiVersion: okdev.io/v1alpha1
16+ kind: DevEnvironment
17+ metadata:
18+ name: test
19+ spec:
20+ namespace: team-a
21+ sidecar:
22+ image: ghcr.io/acmore/okdev:edge
23+ ` ), 0o644 ); err != nil {
24+ t .Fatalf ("write config: %v" , err )
25+ }
26+
27+ var announcedPath string
28+ var doneCalled bool
29+ var doneSuccess bool
30+ cfg , err := loadOptionalConfigForList (& Options {ConfigPath : cfgPath }, func (path string ) func (bool ) {
31+ announcedPath = path
32+ return func (success bool ) {
33+ doneCalled = true
34+ doneSuccess = success
35+ }
36+ })
37+ if err != nil {
38+ t .Fatalf ("loadOptionalConfigForList returned error: %v" , err )
39+ }
40+ if cfg == nil {
41+ t .Fatal ("expected config" )
42+ }
43+ if cfg .Spec .Namespace != "team-a" {
44+ t .Fatalf ("expected namespace team-a, got %q" , cfg .Spec .Namespace )
45+ }
46+ if announcedPath != cfgPath {
47+ t .Fatalf ("expected announced path %q, got %q" , cfgPath , announcedPath )
48+ }
49+ if ! doneCalled {
50+ t .Fatal ("expected announce completion callback to be called" )
51+ }
52+ if ! doneSuccess {
53+ t .Fatal ("expected announce completion callback to report success" )
54+ }
55+ }
You can’t perform that action at this time.
0 commit comments