@@ -14,14 +14,28 @@ const testServiceAccountToken = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJlbWFpbC
1414
1515func TestSTACKITCLIFlow_Init (t * testing.T ) {
1616 type args struct {
17- cfg * STACKITCLIFlowConfig
17+ cfg * STACKITCLIFlowConfig
18+ confFn func (t * testing.T )
1819 }
1920 tests := []struct {
2021 name string
2122 args args
2223 wantErr bool
2324 }{
24- {"ok" , args {& STACKITCLIFlowConfig {}}, false },
25+ {"ok" , args {
26+ cfg : & STACKITCLIFlowConfig {},
27+ confFn : func (t * testing.T ) {
28+ _ , err := runSTACKITCLICommand (context .TODO (), "stackit auth activate-service-account --service-account-token=" + testServiceAccountToken )
29+ if err != nil {
30+ t .Errorf ("runSTACKITCLICommand() error = %v" , err )
31+ return
32+ }
33+ },
34+ }, false },
35+ {"no token" , args {
36+ cfg : & STACKITCLIFlowConfig {},
37+ confFn : func (t * testing.T ) {},
38+ }, true },
2539 }
2640 for _ , tt := range tests {
2741 t .Run (tt .name , func (t * testing.T ) {
@@ -36,19 +50,20 @@ func TestSTACKITCLIFlow_Init(t *testing.T) {
3650 return
3751 }
3852
39- _ , err = runSTACKITCLICommand (ctx , "stackit auth activate-service-account --service-account-token=" + testServiceAccountToken )
40- if err != nil {
41- t .Errorf ("runSTACKITCLICommand() error = %v" , err )
42- return
43- }
53+ tt .args .confFn (t )
4454
4555 defer func () {
4656 _ , _ = runSTACKITCLICommand (ctx , "stackit config profile delete test-stackit-cli-flow-init -y" )
4757 }()
4858
49- if err := c .Init (tt .args .cfg ); (err != nil ) != tt .wantErr {
50- t .Errorf ("TokenFlow.Init() error = %v, wantErr %v" , err , tt .wantErr )
59+ if err := c .Init (tt .args .cfg ); err != nil {
60+ if (err != nil ) != tt .wantErr {
61+ t .Errorf ("TokenFlow.Init() error = %v, wantErr %v" , err , tt .wantErr )
62+ }
63+
64+ return
5165 }
66+
5267 if c .config == nil {
5368 t .Error ("config is nil" )
5469 }
0 commit comments