feat(iaas): set custom user-agent header for STACKIT API calls (#821)
relates to STACKITTPR-184
This commit is contained in:
parent
536d824e5d
commit
53ec994a7d
39 changed files with 575 additions and 740 deletions
11
stackit/internal/utils/headers.go
Normal file
11
stackit/internal/utils/headers.go
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
package utils
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/stackitcloud/stackit-sdk-go/core/config"
|
||||
)
|
||||
|
||||
func UserAgentConfigOption(providerVersion string) config.ConfigurationOption {
|
||||
return config.WithUserAgent(fmt.Sprintf("stackit-terraform-provider/%s", providerVersion))
|
||||
}
|
||||
46
stackit/internal/utils/headers_test.go
Normal file
46
stackit/internal/utils/headers_test.go
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
package utils
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/stackitcloud/stackit-sdk-go/core/config"
|
||||
)
|
||||
|
||||
func TestUserAgentConfigOption(t *testing.T) {
|
||||
type args struct {
|
||||
providerVersion string
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
want config.ConfigurationOption
|
||||
}{
|
||||
{
|
||||
name: "TestUserAgentConfigOption",
|
||||
args: args{
|
||||
providerVersion: "1.0.0",
|
||||
},
|
||||
want: config.WithUserAgent("stackit-terraform-provider/1.0.0"),
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
clientConfigActual := config.Configuration{}
|
||||
err := tt.want(&clientConfigActual)
|
||||
if err != nil {
|
||||
t.Errorf("error applying configuration: %v", err)
|
||||
}
|
||||
|
||||
clientConfigExpected := config.Configuration{}
|
||||
err = UserAgentConfigOption(tt.args.providerVersion)(&clientConfigExpected)
|
||||
if err != nil {
|
||||
t.Errorf("error applying configuration: %v", err)
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(clientConfigActual, clientConfigExpected) {
|
||||
t.Errorf("UserAgentConfigOption() = %v, want %v", clientConfigActual, clientConfigExpected)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue