feat(iaas): set custom user-agent header for STACKIT API calls (#821)

relates to STACKITTPR-184
This commit is contained in:
Ruben Hönle 2025-05-14 16:46:16 +02:00 committed by GitHub
parent 536d824e5d
commit 53ec994a7d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
39 changed files with 575 additions and 740 deletions

View 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))
}

View 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)
}
})
}
}