Skip to content

Commit

Permalink
improve coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
Dean Oren committed Mar 25, 2023
1 parent 82d22c6 commit a9b04a0
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
4 changes: 2 additions & 2 deletions pkg/clients/token_flow.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ type TokenFlowConfig struct {

// GetEnvironment returns the defined API environment
func (c *TokenFlow) GetEnvironment() env.Environment {
return c.config.Environment
return c.GetConfig().Environment
}

// GetServiceAccountEmail returns the service account email
func (c *TokenFlow) GetServiceAccountEmail() string {
return c.config.ServiceAccountEmail
return c.GetConfig().ServiceAccountEmail
}

// GetConfig returns the flow configuration
Expand Down
32 changes: 31 additions & 1 deletion pkg/clients/token_flow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,44 @@ func TestTokenFlow_Init(t *testing.T) {
args args
wantErr bool
}{
// TODO: Add test cases.
{"ok", args{context.Background(), []TokenFlowConfig{
{
ServiceAccountEmail: "abc",
ServiceAccountToken: "efg",
},
}}, false},
{"error 1", args{context.Background(), []TokenFlowConfig{
{
ServiceAccountEmail: "",
ServiceAccountToken: "",
},
}}, true},
{"error 2", args{context.Background(), []TokenFlowConfig{
{
ServiceAccountEmail: "",
ServiceAccountToken: "efg",
},
}}, true},
}
a := os.Getenv(ServiceAccountEmail)
b := os.Getenv(ServiceAccountToken)
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
c := &TokenFlow{}
assert.EqualValues(t, "", c.GetEnvironment())

os.Setenv(ServiceAccountEmail, "")
os.Setenv(ServiceAccountToken, "")
if err := c.Init(tt.args.ctx, tt.args.cfg...); (err != nil) != tt.wantErr {
t.Errorf("TokenFlow.Init() error = %v, wantErr %v", err, tt.wantErr)
}
os.Setenv(ServiceAccountEmail, a)
os.Setenv(ServiceAccountToken, b)
if c.config == nil {
t.Error("config is nil")
}
assert.EqualValues(t, "prod", c.GetEnvironment())
assert.EqualValues(t, c.config.ServiceAccountEmail, c.GetServiceAccountEmail())
})
}
}

0 comments on commit a9b04a0

Please sign in to comment.